gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.lib / org.gvsig.scripting.lib.impl / src / main / resources / org / gvsig / scripting / langs / python / init.txt @ 468
History | View | Annotate | Download (1.63 KB)
1 |
|
---|---|
2 |
|
3 |
__file__ = script.getFile().getAbsolutePath() |
4 |
|
5 |
|
6 |
def __init_python_path(): |
7 |
import sys |
8 |
|
9 |
# Add folder of script |
10 |
path = script.getFile().getParentFile().getCanonicalPath() |
11 |
if not path in sys.path: |
12 |
sys.path.append(path) |
13 |
|
14 |
# Add folder of root user scripts |
15 |
path = script.getManager().getUserFolder().getFile().getCanonicalPath() |
16 |
if not path in sys.path: |
17 |
sys.path.append(path) |
18 |
|
19 |
# Add folders of libs |
20 |
folders = script.getManager().getLibFolders() |
21 |
if folders != None: |
22 |
for folder in folders: |
23 |
path = folder.getCanonicalPath() |
24 |
if not path in sys.path: |
25 |
sys.path.append(path) |
26 |
|
27 |
# Add the scripts folder of system folders |
28 |
folders = script.getManager().getSystemFolder() |
29 |
if folders != None: |
30 |
for folder in folders.getUnits(): |
31 |
path = folder.getFile().getCanonicalPath() |
32 |
if not path in sys.path: |
33 |
sys.path.append(path) |
34 |
|
35 |
|
36 |
def use_plugin(pluginName): |
37 |
from org.gvsig.andami import PluginsLocator |
38 |
|
39 |
pluginsManager = PluginsLocator.getManager() |
40 |
other = pluginsManager.getPlugin(pluginName) |
41 |
scripting = pluginsManager.getPlugin("org.gvsig.scripting.app.extension") |
42 |
scripting.addDependencyWithPlugin(other) |
43 |
|
44 |
def use_jar(fname, root=__file__): |
45 |
from java.io import File |
46 |
import sys |
47 |
import os |
48 |
|
49 |
if isinstance(fname,File): |
50 |
f = fname |
51 |
fname = f.getPath() |
52 |
else: |
53 |
f = File(fname) |
54 |
if not f.isAbsolute() : |
55 |
rf = File(root) |
56 |
if rf.isFile() : |
57 |
rf = rf.getParentFile() |
58 |
f = File( rf,fname) |
59 |
|
60 |
fname = f.getCanonicalPath() |
61 |
if not fname in sys.path: |
62 |
sys.path.append(fname) |
63 |
|
64 |
|
65 |
__init_python_path() |
66 |
|
67 |
|
68 |
|