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 @ 724
History | View | Annotate | Download (1.58 KB)
1 |
|
---|---|
2 |
|
3 |
__file__ = script.getResource(script.getId()+".py").getAbsolutePath() |
4 |
|
5 |
def __init_python_path(): |
6 |
import sys |
7 |
from org.gvsig.scripting import ScriptingLocator |
8 |
|
9 |
new_path = list() |
10 |
new_path.append(sys.path[0]) |
11 |
|
12 |
# Add folder of script |
13 |
path = script.getFile().getParentFile().getCanonicalPath() |
14 |
if not path in new_path: |
15 |
new_path.append(path) |
16 |
|
17 |
# Add folder of root user scripts |
18 |
path = script.getManager().getUserFolder().getFile().getCanonicalPath() |
19 |
if not path in new_path: |
20 |
new_path.append(path) |
21 |
|
22 |
# Add folders of libs |
23 |
folders = script.getLibFolders() |
24 |
|
25 |
if folders != None: |
26 |
for folder in folders: |
27 |
path = folder.getCanonicalPath() |
28 |
if not path in new_path: |
29 |
new_path.append(path) |
30 |
|
31 |
# Add the scripts folder of system folders |
32 |
folders = script.getManager().getSystemFolder() |
33 |
if folders != None: |
34 |
for folder in folders.getUnits(): |
35 |
path = folder.getFile().getCanonicalPath() |
36 |
if not path in new_path: |
37 |
new_path.append(path) |
38 |
|
39 |
new_path.append("__classpath__") |
40 |
new_path.append("__pyclasspath__/") |
41 |
|
42 |
# Add global libs from uselib module |
43 |
# Deben ir a final para reproducir el mismo entorno que tenia el script cuando |
44 |
# se ejecuto e hizo el use_xxx. |
45 |
manager = ScriptingLocator.getManager() |
46 |
global_path = manager.getProperty("jython.global.path") |
47 |
if global_path != None: |
48 |
new_path.extend(global_path) |
49 |
|
50 |
del sys.path[:] |
51 |
for path in new_path: |
52 |
sys.path.append(path) |
53 |
|
54 |
|
55 |
__init_python_path() |
56 |
|
57 |
del __init_python_path |
58 |
|
59 |
|