Revision 103
org.gvsig.batovi/trunk/org.gvsig.batovi/resources/fix_gdal_links.sh | ||
---|---|---|
1 |
#!/bin/sh |
|
2 |
|
|
3 |
# Fixes symbolic link of GDAL library (if any) |
|
4 |
|
|
5 |
if [ -f "$GVSIG_HOME/native/libgdal.so"] ; then |
|
6 |
rm "$GVSIG_HOME/native/libgdal.so" |
|
7 |
fi; |
|
8 |
if [ -f "$GVSIG_HOME/libgdal.so.1"] ; then |
|
9 |
rm "$GVSIG_HOME/native/libgdal.so.1" |
|
10 |
fi; |
|
11 |
GDAL_LIB=`ls $GVSIG_HOME/native/libgdal.so.1.*` |
|
12 |
if [ -f "$GDAL_LIB" ] ; then |
|
13 |
ln -s "$GDAL_LIB" "$GVSIG_HOME/native/libgdal.so" |
|
14 |
ln -s "$GDAL_LIB" "$GVSIG_HOME/native/libgdal.so.1" |
|
15 |
fi |
org.gvsig.batovi/trunk/org.gvsig.batovi/resources/customize-gvSIG.sh | ||
---|---|---|
6 | 6 |
echo "" |
7 | 7 |
echo "Usage:" |
8 | 8 |
echo "" |
9 |
echo " $0 -g {path-to-gvsig-tocustomize} -r {path-to-resources-folder}" |
|
9 |
echo " $0 -g {path-to-gvsig-tocustomize} -r {path-to-resources-folder} -w {path-to-work-folder} -a {path-to-activity-folder}"
|
|
10 | 10 |
echo "" |
11 | 11 |
echo "Options:" |
12 | 12 |
echo "" |
13 | 13 |
echo "-g {path-to-gvsig-tocustomize}: path where gvSIG v2.0 is to customize" |
14 | 14 |
echo "-r {path-to-resources-folder}: path to resources folder" |
15 |
echo "-w {path-to-work-folder}: path to work folder" |
|
16 |
echo "-a {path-to-activity-folder}: path to work activity folder" |
|
15 | 17 |
} |
16 | 18 |
|
19 |
|
|
17 | 20 |
## Replace a regular expression in a file by a string |
18 | 21 |
# |
19 | 22 |
# Params: |
... | ... | |
28 | 31 |
FINAL_STRING="$3" |
29 | 32 |
|
30 | 33 |
cp "$FILE_TO_REPLACE" "$BACKUP_FILE" |
31 |
sed "$RE_FOR_SED" "$BACKUP_FILE" > "$FILE_TO_REPLACE"
|
|
34 |
sed "s/$RE_FOR_SED/$FINAL_STRING/" "$BACKUP_FILE" > "$FILE_TO_REPLACE"
|
|
32 | 35 |
rm "$BACKUP_FILE" |
33 | 36 |
} |
34 | 37 |
|
35 | 38 |
#set -x |
36 | 39 |
|
37 |
while getopts "g:r:" OPT |
|
40 |
while getopts "g:r:w:a:" OPT
|
|
38 | 41 |
do case "$OPT" in |
39 |
g) TARGET_GVSIG_FOLDER="$OPTARG";; |
|
40 |
r) RESOURCE_FOLDER="$OPTARG";; |
|
42 |
g) export TARGET_GVSIG_FOLDER="$OPTARG";; |
|
43 |
r) export RESOURCE_FOLDER="$OPTARG";; |
|
44 |
w) export WORK_FOLDER="$OPTARG";; |
|
45 |
a) export ACTIVITY_FOLDER="$OPTARG";; |
|
41 | 46 |
[?]) usage; |
42 | 47 |
exit 1;; |
43 | 48 |
esac |
... | ... | |
94 | 99 |
exit 1; |
95 | 100 |
fi; |
96 | 101 |
|
102 |
if [ "x$WORK_FOLDER" == "x" ] ; then |
|
103 |
usage |
|
104 |
echo "" |
|
105 |
echo "ERROR: Missing -w option" |
|
106 |
exit 1; |
|
107 |
fi; |
|
108 |
|
|
109 |
if [ ! -d "$WORK_FOLDER" ] ; then |
|
110 |
usage |
|
111 |
echo "" |
|
112 |
echo "ERROR: $WORK_FOLDER is not a folder" |
|
113 |
exit 1; |
|
114 |
fi; |
|
115 |
|
|
116 |
if [ "x$ACTIVITY_FOLDER" == "x" ] ; then |
|
117 |
usage |
|
118 |
echo "" |
|
119 |
echo "ERROR: Missing -a option" |
|
120 |
exit 1; |
|
121 |
fi; |
|
122 |
|
|
123 |
if [ ! -d "$ACTIVITY_FOLDER" ] ; then |
|
124 |
usage |
|
125 |
echo "" |
|
126 |
echo "ERROR: $ACTIVITY_FOLDER is not a folder" |
|
127 |
exit 1; |
|
128 |
fi; |
|
129 |
|
|
130 |
|
|
97 | 131 |
echo "Removing unused files..." |
98 | 132 |
rm "$TARGET_GVSIG_FOLDER/uninstall" |
99 | 133 |
rm "$TARGET_GVSIG_FOLDER/README.txt" |
100 | 134 |
rm "$TARGET_GVSIG_FOLDER/LEEME.txt" |
101 |
if [ ! -e `ls "$TARGET_GVSIG_FOLDER/install/"` ] ; then
|
|
135 |
if [ ! -n `ls "$TARGET_GVSIG_FOLDER/install/"` ] ; then
|
|
102 | 136 |
rm $TARGET_GVSIG_FOLDER/install/* |
103 | 137 |
fi |
104 | 138 |
|
139 |
echo "Fixing gvSIG theme files..." |
|
140 |
cp "$RESOURCE_FOLDER/one_pixel.png" "$TARGET_GVSIG_FOLDER/gvSIG/extensiones/org.gvsig.app/theme/gvsig-proj-black-wallpaper.png" |
|
141 |
|
|
105 | 142 |
echo "Adjusting logging..." |
106 | 143 |
cp "$RESOURCE_FOLDER/log4j.properties" "$TARGET_GVSIG_FOLDER" |
107 | 144 |
|
108 | 145 |
|
109 |
echo "Adjusting JAVA_HOME..." |
|
110 |
echo "****************************************************" |
|
111 |
echo "***** FIXME: JAVA_HOME in OLPC filesystem **********" |
|
112 |
echo "****************************************************" |
|
113 |
replaceInFile "$TARGET_GVSIG_FOLDER/gvSIG.sh" "^export JAVA_HOME='.*'$" "export JAVA_HOME='/usr/lib/jvm/java-6-sun-1.6.0.21_i586'" |
|
146 |
echo "Adjusting removing JAVA_HOME from gvSIG.sh (will be initialized at activity startup)..." |
|
147 |
replaceInFile "$TARGET_GVSIG_FOLDER/gvSIG.sh" "export[ ]JAVA_HOME=.*$" "#export JAVA_HOME=INITIALIZED BY ACTIVITY" |
|
114 | 148 |
|
115 | 149 |
echo "Adjusting JVM memory settings..." |
116 | 150 |
replaceInFile "$TARGET_GVSIG_FOLDER/gvSIG.sh" "GVSIG_INITIAL_MEM=[0-9]*[MG]" "GVSIG_INITIAL_MEM=80M" |
117 |
replaceInFile "$TARGET_GVSIG_FOLDER/gvSIG.sh" "GVSIG_MAX_MEM=[0-9]*[MG]" "GVSIG_MAX_MEM=256M"
|
|
151 |
replaceInFile "$TARGET_GVSIG_FOLDER/gvSIG.sh" "GVSIG_MAX_MEM=[0-9]*[MG]" "GVSIG_MAX_MEM=250M"
|
|
118 | 152 |
replaceInFile "$TARGET_GVSIG_FOLDER/gvSIG.sh" "GVSIG_MAX_PERM_SIZE=[0-9]*[MG]" "GVSIG_MAX_PERM_SIZE=64M" |
153 |
|
|
154 |
GDAL_FILES=`ls $TARGET_GVSIG_FOLDER/native/libgdal.so* 2> /dev/null` |
|
155 |
if [ -n "$GDAL_FILES" ] ; then |
|
156 |
echo "Removing gdal symbolic links" |
|
157 |
rm $TARGET_GVSIG_FOLDER/native/libgdal.so $TARGET_GVSIG_FOLDER/native/libgdal.so.1 |
|
158 |
|
|
159 |
echo "Copying post-install script to fix gdal symbolic links" |
|
160 |
cp "$RESOURCE_FOLDER/fix_gdal_links.sh" "$ACTIVITY_FOLDER/post-install/scripts/" |
|
161 |
fi |
org.gvsig.batovi/trunk/org.gvsig.batovi/prepare-bundle.sh | ||
---|---|---|
112 | 112 |
echo "Copying base activity files..." |
113 | 113 |
tar c --exclude-vcs --exclude-backups org.gvsig.batovi.activity | tar x -C "$WORK_FOLDER" |
114 | 114 |
|
115 |
ACTIVITY_FOLDER="$WORK_FOLDER/org.gvsig.batovi.activity" |
|
116 |
|
|
115 | 117 |
# set bundle version |
116 | 118 |
echo "Updating bundle version ($XO_PKG_VERSION)...." |
117 |
cp "$WORK_FOLDER"/org.gvsig.batovi.activity/activity/activity.info "$WORK_FOLDER"/tmp.info
|
|
118 |
sed "s/[$][{]version[}]/$XO_PKG_VERSION/" "$WORK_FOLDER"/tmp.info > "$WORK_FOLDER"/org.gvsig.batovi.activity/activity/activity.info
|
|
119 |
cp "$ACTIVITY_FOLDER/activity/activity.info" "$WORK_FOLDER/tmp.info"
|
|
120 |
sed "s/[$][{]version[}]/$XO_PKG_VERSION/" "$WORK_FOLDER"/tmp.info > "$ACTIVITY_FOLDER/activity/activity.info"
|
|
119 | 121 |
rm "$WORK_FOLDER"/tmp.info |
120 | 122 |
info=`cat "$WORK_FOLDER"/org.gvsig.batovi.activity/activity/activity.info` |
121 | 123 |
if [ -e "$info" ] ; then |
... | ... | |
129 | 131 |
GVSIG_FILES=`ls $SOURCE_GVSIG_FOLDER` |
130 | 132 |
tar c --exclude-vcs --exclude-backups -C $SOURCE_GVSIG_FOLDER $GVSIG_FILES | tar x -C $TARGET_GVSIG_FOLDER |
131 | 133 |
|
134 |
# clean install folder |
|
135 |
echo "Clean gvSIG install folder..." |
|
136 |
rm $TARGET_GVSIG_FOLDER/install/* |
|
132 | 137 |
|
138 |
# clean install folder |
|
139 |
echo "Clean gvSIG plugins install folder..." |
|
140 |
to_remove=`find $TARGET_GVSIG_FOLDER/gvSIG/extensiones -name "install" -type d` |
|
141 |
for file_to_remove in $to_remove |
|
142 |
do |
|
143 |
echo " $file_to_remove" |
|
144 |
rm -r "$file_to_remove" |
|
145 |
done |
|
146 |
|
|
133 | 147 |
# Call customizer script |
134 | 148 |
echo "Calling customized gvSIG Installation script ($SCRIPT_PATH/resources/customize-gvSIG.sh)..." |
135 | 149 |
echo "" |
136 |
"$SCRIPT_PATH/resources/customize-gvSIG.sh" -g "$TARGET_THEMATICMAP_FOLDER" -r "$SCRIPT_PATH/resources" |
|
150 |
set -e |
|
151 |
"$SCRIPT_PATH/resources/customize-gvSIG.sh" -g "$TARGET_GVSIG_FOLDER" -r "$SCRIPT_PATH/resources" -w "$WORK_FOLDER" -a "$ACTIVITY_FOLDER" |
|
137 | 152 |
echo "" |
153 |
set +e |
|
138 | 154 |
echo "customized script Done. Resuming..." |
139 | 155 |
|
140 | 156 |
|
org.gvsig.batovi/trunk/org.gvsig.batovi/org.gvsig.batovi.activity/post-install/README.rst | ||
---|---|---|
1 |
#TODO: explain user-gvsig-home and user-home folders |
|
1 |
=========================================== |
|
2 |
gvSIG batovi Activity Post-intall process |
|
3 |
=========================================== |
|
4 |
|
|
5 |
|
|
6 |
This folder contains all supported *post-intall* actions implemented in gvSIG activity. |
|
7 |
|
|
8 |
|
|
9 |
user-gvsig-home |
|
10 |
================ |
|
11 |
|
|
12 |
Files of this folder will be **merged** (copy only files than no exists on target folder) with *~/gvSIG* folder of user intallation in first gvSIG activity execution. |
|
13 |
|
|
14 |
|
|
15 |
After that this folder will be renamed to *user-gvsig-home.done*. |
|
16 |
|
|
17 |
|
|
18 |
user-home |
|
19 |
=========== |
|
20 |
|
|
21 |
Files of this folder will be **merged** (copy only files than no exists on target folder) to *user home* folder. |
|
22 |
|
|
23 |
After that this folder will be removed. |
|
24 |
|
|
25 |
scripts |
|
26 |
======== |
|
27 |
|
|
28 |
Excecutes contained scripts in first gvSIG activity execution. Only *Pyhon* (files ``.py``) and *Shell* (files ``.sh``) are allowed (other files will be ignored). |
|
29 |
|
|
30 |
Before all execution this environ variables will be set: |
|
31 |
|
|
32 |
* ``GVSIG_ACTIVITY``: root folder of gvSIG activity (usually ``~/Activities/org.gvsig.batovi.activity``) |
|
33 |
|
|
34 |
* ``GVSIG_HOME``: root folder of gvSIG installation (usually ``$GVSIG_ACTIVITY/gvSIG``) |
|
35 |
|
|
36 |
After the script excution will be renamed (adds ``.done``) to prevent future executions. |
|
37 |
|
|
38 |
When all script were executed, this folder will be renamed (adds ``.done``). |
|
39 |
|
|
40 |
See log file for problems in script executions. |
org.gvsig.batovi/trunk/org.gvsig.batovi/org.gvsig.batovi.activity/GvSIGActivity.py | ||
---|---|---|
1 |
import sys, os, shutil
|
|
1 |
import os, shutil, stat
|
|
2 | 2 |
import gtk, gobject |
3 | 3 |
import popen2 |
4 |
from os import path |
|
5 |
Path = path |
|
4 |
from os import path as Path |
|
6 | 5 |
|
7 | 6 |
import logging |
8 | 7 |
import sugar.activity.activity as activity |
... | ... | |
10 | 9 |
from sugar.datastore import datastore |
11 | 10 |
|
12 | 11 |
""" |
12 |
Alternative paths to locate JRE |
|
13 |
""" |
|
14 |
JAVA_HOME_PATHS=( |
|
15 |
#"/usr/lib/jvm/jre", # gcj path DOESN'T WORK!!! |
|
16 |
str(Path.join(Path.expanduser("~"),"Activities/Java.activity/jre")), # Java activity path |
|
17 |
) |
|
18 |
|
|
19 |
# LOG level config |
|
20 |
logging.basicConfig(level=logging.DEBUG) |
|
21 |
#logging.basicConfig(level=logging.INFO) |
|
22 |
|
|
23 |
|
|
24 |
""" |
|
13 | 25 |
gvSIG batovi activity |
14 | 26 |
|
15 | 27 |
Requires: |
16 | 28 |
|
17 | 29 |
* Sugar builds > 706 |
18 | 30 |
|
19 |
* OpenJDK installed.
|
|
31 |
* A java installed or the Java activity installed
|
|
20 | 32 |
|
21 |
To see more information look at http://wiki.laptop.org/go/Java
|
|
33 |
For more information see: http://www.mediagala.com/rap/foro/viewtopic.php?f=8&t=166
|
|
22 | 34 |
|
23 |
You can try to execute this in terminal activity:: |
|
24 |
|
|
25 |
sudo yum -y install java-1.6.0-openjdk |
|
26 |
|
|
27 | 35 |
On first _run_ executes son post-install actions. |
28 | 36 |
|
29 | 37 |
""" |
30 | 38 |
class GvSIGActivity(Activity): |
39 |
# gvSIG Home path (where is gvSIG activity) |
|
40 |
gvsig_activity=None |
|
41 |
|
|
42 |
# gvSIG Home path (where is gvSIG installation) |
|
43 |
gvsig_home=None |
|
44 |
|
|
45 |
|
|
46 |
#Java Home |
|
47 |
java_home=None |
|
48 |
|
|
49 |
|
|
31 | 50 |
def __init__(self, handle): |
32 |
logging.debug('Starting GvSIG handler.')
|
|
33 |
|
|
34 |
Activity.__init__(self, handle)
|
|
35 |
self.handle = handle
|
|
51 |
logging.debug('Creating GvSIG handler.')
|
|
52 |
|
|
53 |
Activity.__init__(self, handle) |
|
54 |
self.handle = handle |
|
36 | 55 |
|
37 |
# Register run() to run from gtk_main_loop
|
|
38 |
# as soon as it gets idle.
|
|
39 |
# Which is kludge to make it run after the loop has begun
|
|
40 |
self.idleFunc = gobject.idle_add(self.run)
|
|
56 |
# Register run() to run from gtk_main_loop |
|
57 |
# as soon as it gets idle. |
|
58 |
# Which is kludge to make it run after the loop has begun |
|
59 |
self.idleFunc = gobject.idle_add(self.run) |
|
41 | 60 |
|
42 | 61 |
def run(self): |
62 |
# Remove run() because we want it to run only once |
|
63 |
gobject.source_remove(self.idleFunc) |
|
43 | 64 |
|
44 |
# Remove run() because we want it to run only once |
|
45 |
gobject.source_remove(self.idleFunc) |
|
65 |
# locate and check jre |
|
66 |
if not self.initializeJavaHome(): |
|
67 |
# Exiting with a error |
|
68 |
self.showMessageError("Can't found any JRE to run gvSIG:\nSee http://www.mediagala.com/rap/foro/viewtopic.php?f=8&t=166\nfor more information") |
|
69 |
logging.error("No JRE found!!!") |
|
70 |
logging.debug("Closing activity"); |
|
71 |
self.close(True) |
|
72 |
return |
|
46 | 73 |
|
74 |
# setup environ properties |
|
75 |
self.gvsig_activity=activity.get_bundle_path() |
|
76 |
self.gvsig_home=Path.join(self.gvsig_activity, 'gvSIG') |
|
47 | 77 |
|
48 |
# do post-install actions |
|
49 |
self.postInstall() |
|
78 |
os.environ['GVSIG_HOME']=self.gvsig_home |
|
79 |
os.environ['GVSIG_ACTIVITY']=self.gvsig_activity |
|
80 |
os.environ['JAVA_HOME']=self.java_home |
|
50 | 81 |
|
51 |
gvSIG_sh = Path.join(activity.get_bundle_path(), 'gvSIG', 'gvSIG.sh') |
|
82 |
# do post-install actions |
|
83 |
self.postInstall() |
|
52 | 84 |
|
53 |
if not Path.exists(gvSIG_sh):
|
|
54 |
raise Exception("Missing gvSIG launcher: %s" % gvSIG_sh)
|
|
85 |
# identify gvSIG launcher
|
|
86 |
gvSIG_sh = Path.join(activity.get_bundle_path(), 'gvSIG', 'gvSIG.sh')
|
|
55 | 87 |
|
56 |
# check execution permission |
|
57 |
if not os.access(gvSIG_sh, os.X_OK): |
|
58 |
# set excecution permission |
|
59 |
os.chmod(gvSIG_sh,os.stat(gvSIG_sh)+stat.S_IEXEC) |
|
60 |
|
|
61 |
try: |
|
62 |
# execute gvSIG.sh |
|
88 |
if not Path.exists(gvSIG_sh): |
|
89 |
raise Exception("Missing gvSIG launcher: %s" % gvSIG_sh) |
|
63 | 90 |
|
64 |
logging.debug("Executing '%s'" % gvSIG_sh);
|
|
65 |
gvSIG_process = popen2.Popen4('%s' % gvSIG_sh, 16)
|
|
66 |
logging.debug(gvSIG_process.fromchild.read()) |
|
67 |
rcode = gvSIG_process.wait()
|
|
68 |
logging.debug('gvSIG.sh returned with code=%d' % rcode)
|
|
91 |
# check execution permission
|
|
92 |
self.fixExcecutionFilePermission(gvSIG_sh)
|
|
93 |
|
|
94 |
try:
|
|
95 |
logging.info("Executing '%s'" % gvSIG_sh);
|
|
69 | 96 |
|
70 |
finally: |
|
71 |
logging.debug("Closing activity"); |
|
72 |
self.close(True) |
|
97 |
# execute gvSIG.sh |
|
98 |
gvSIG_process = popen2.Popen4('%s' % gvSIG_sh, 16) |
|
73 | 99 |
|
100 |
# writing stout in log file |
|
101 |
logging.info(gvSIG_process.fromchild.read()) |
|
102 |
|
|
103 |
# wait until gvSIG exit |
|
104 |
rcode = gvSIG_process.wait() |
|
105 |
|
|
106 |
logging.info('gvSIG.sh returned with code=%d' % rcode) |
|
107 |
|
|
108 |
finally: |
|
109 |
logging.debug("Closing activity"); |
|
110 |
self.close(True) |
|
111 |
|
|
112 |
def showMessageError(self, message): |
|
113 |
md = gtk.MessageDialog(self, |
|
114 |
gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, |
|
115 |
gtk.BUTTONS_CLOSE, message) |
|
116 |
md.run() |
|
117 |
md.destroy() |
|
118 |
|
|
74 | 119 |
""" |
120 |
Initialize property ``java_home`` |
|
121 |
|
|
122 |
Try to locate a valid java in ``JAVA_HOME_PATHS`` list |
|
123 |
|
|
124 |
Check that existe a *bin/java* executable file inside of it. |
|
125 |
|
|
126 |
If not JRE found returns False. Otherwise returns True |
|
127 |
""" |
|
128 |
def initializeJavaHome(self): |
|
129 |
for jhome in JAVA_HOME_PATHS: |
|
130 |
logging.debug("check jre in %s" % jhome) |
|
131 |
if not Path.exists(jhome): |
|
132 |
logging.debug("%s not found" % jhome) |
|
133 |
continue |
|
134 |
if self.checkJavaExecutable(jhome): |
|
135 |
self.java_home=jhome |
|
136 |
logging.debug("ussing '%s' for JAVA_HOME" % jhome) |
|
137 |
return True |
|
138 |
else: |
|
139 |
logging.debug("No Java available in register paths: %s" % repr(JAVA_HOME_PATHS)) |
|
140 |
return False |
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
""" |
|
146 |
Check ``javaHome`` folder: check that exist a *bin/java* executable file |
|
147 |
|
|
148 |
Returns True/False |
|
149 |
""" |
|
150 |
def checkJavaExecutable(self, javaHome): |
|
151 |
javaExe=Path.join(javaHome,"bin","java") |
|
152 |
if not Path.exists(javaExe): |
|
153 |
return False |
|
154 |
return os.access(javaExe, os.X_OK) |
|
155 |
|
|
156 |
""" |
|
75 | 157 |
Run post install actions. |
76 | 158 |
|
77 | 159 |
This actions usually will be execute just once, in first activity run |
... | ... | |
79 | 161 |
def postInstall(self): |
80 | 162 |
self.installInGvSIGUserHome() |
81 | 163 |
self.installInUserHome() |
164 |
self.execScripts() |
|
82 | 165 |
|
83 | 166 |
""" |
167 |
*Post Intall process:* Excecutes install scripts |
|
168 |
|
|
169 |
This actions usually will be execute just once, in first activity run. |
|
170 |
""" |
|
171 |
def execScripts(self): |
|
172 |
# check if ther is any file to copy to |
|
173 |
sourceFolder = Path.join(activity.get_bundle_path(), 'post-install', 'scripts') |
|
174 |
|
|
175 |
if not Path.exists(sourceFolder): |
|
176 |
# No files to execute |
|
177 |
return |
|
178 |
|
|
179 |
everyScriptOk = True |
|
180 |
|
|
181 |
# for all file/dir in souceFolder |
|
182 |
scriptFiles = os.listdir(sourceFolder) |
|
183 |
|
|
184 |
for aFile in scriptFiles: |
|
185 |
fext = Path.splitext(aFile)[1] |
|
186 |
aFilePath = Path.join(sourceFolder,aFile) |
|
187 |
if fext == "py": |
|
188 |
# Exec python script |
|
189 |
execOk = self.execPython(aFilePath) |
|
190 |
if execOk: |
|
191 |
shutil.move(aFilePath,aFilePath+".done") |
|
192 |
else: |
|
193 |
everyScriptOk=False |
|
194 |
|
|
195 |
|
|
196 |
elif fext == "sh": |
|
197 |
# Exec Shell script |
|
198 |
execOk = self.execShell(aFilePath) |
|
199 |
if execOk: |
|
200 |
shutil.move(aFilePath,aFilePath+".done") |
|
201 |
else: |
|
202 |
everyScriptOk=False |
|
203 |
|
|
204 |
elif fext == "done": |
|
205 |
# Nothing to do |
|
206 |
pass |
|
207 |
|
|
208 |
else: |
|
209 |
# Ignoring file |
|
210 |
logging.debug("Ignoring post-install script: " + aFilePath) |
|
211 |
|
|
212 |
|
|
213 |
if everyScriptOk: |
|
214 |
# rename folder to avoid execution on next application open |
|
215 |
shutil.move(sourceFolder, sourceFolder+".done") |
|
216 |
|
|
217 |
""" |
|
218 |
Excecutes a python script file |
|
219 |
""" |
|
220 |
def execPython(self,aFile): |
|
221 |
logging.debug("Executing python script '%s'" % aFile); |
|
222 |
try: |
|
223 |
# open file in read-only mode |
|
224 |
f = file(aFile,"r") |
|
225 |
|
|
226 |
# exec script |
|
227 |
try: |
|
228 |
exec f |
|
229 |
finally: |
|
230 |
f.close() |
|
231 |
|
|
232 |
return True |
|
233 |
except Exception, exc: |
|
234 |
logging.error("Excecuting file %s: %s" % (aFile,exc)); |
|
235 |
return False |
|
236 |
|
|
237 |
""" |
|
238 |
Fix (set) execution permission of a file |
|
239 |
""" |
|
240 |
def fixExcecutionFilePermission(self, aFile): |
|
241 |
# check execution permission |
|
242 |
if not os.access(aFile, os.X_OK): |
|
243 |
# set excecution permission |
|
244 |
os.chmod(aFile,os.stat(aFile)+stat.S_IEXEC) |
|
245 |
|
|
246 |
""" |
|
247 |
Excecutes a shell script file |
|
248 |
""" |
|
249 |
def execShell(self,aFile): |
|
250 |
logging.debug("Executing '%s'" % aFile); |
|
251 |
try: |
|
252 |
mProcess = popen2.Popen4('%s' % aFile, 16) |
|
253 |
logging.debug(mProcess.fromchild.read()) |
|
254 |
rcode = mProcess.wait() |
|
255 |
return rcode == 0 |
|
256 |
except Exception, exc: |
|
257 |
logging.error("Excecuting file %s: %s" % (aFile,exc)); |
|
258 |
return False |
|
259 |
|
|
260 |
|
|
261 |
""" |
|
84 | 262 |
*Post Intall process:* Install files in user home |
85 | 263 |
|
86 | 264 |
Move files from ``{activity_folder}/post-install/user-home`` to ``$HOME`` |
87 | 265 |
|
88 |
**NOTE**: if a file/dir is
|
|
266 |
**NOTE**: if a file/dir already exist **will be ignored** (Keeping untouched original files)
|
|
89 | 267 |
""" |
90 | 268 |
def installInUserHome(self): |
91 | 269 |
# check if ther is any file to copy to |
92 |
sourceFolder = Path.join(activity.get_bundle_path(), 'post-install', 'user-gvsig-home')
|
|
270 |
sourceFolder = Path.join(activity.get_bundle_path(), 'post-install', 'user-home') |
|
93 | 271 |
|
94 | 272 |
if not Path.exists(sourceFolder): |
95 | 273 |
# No files to copy |
... | ... | |
97 | 275 |
|
98 | 276 |
homeUserFolder = Path.expanduser("~") |
99 | 277 |
|
100 |
#move files without override ignoring which already exists
|
|
101 |
self.moveFiles(sourceFolder,homeUserFolder, False)
|
|
278 |
#merge folder
|
|
279 |
self.mergeFolder(sourceFolder,homeUserFolder)
|
|
102 | 280 |
|
103 |
#delete source folder to prevent rerun of this step
|
|
104 |
os.rmdir(sourceFolder)
|
|
281 |
#rename source folder to prevent rerun of this step
|
|
282 |
os.rename(sourceFolder,sourceFolder+".done")
|
|
105 | 283 |
|
106 | 284 |
#done |
107 | 285 |
return |
... | ... | |
127 | 305 |
|
128 | 306 |
|
129 | 307 |
#move files |
130 |
self.moveFiles(sourceFolder,homeGvsigUserFolder)
|
|
308 |
self.mergeFolder(sourceFolder,homeGvsigUserFolder)
|
|
131 | 309 |
|
132 |
#delete source folder to prevent rerun of this step
|
|
133 |
os.rmdir(sourceFolder)
|
|
310 |
#rename source folder to prevent rerun of this step
|
|
311 |
os.rename(sourceFolder,sourceFolder+".done")
|
|
134 | 312 |
|
135 | 313 |
#done |
136 | 314 |
return |
... | ... | |
156 | 334 |
toMoveList = os.listdir(sourceFolder) |
157 | 335 |
for toMove in toMoveList: |
158 | 336 |
|
159 |
if not overrideTarget:
|
|
160 |
# check if exists target
|
|
161 |
target = Path.join(targetFolder,toMove)
|
|
162 |
if Path.exists(target):
|
|
337 |
target = Path.join(targetFolder,toMove)
|
|
338 |
# check if exists target |
|
339 |
if Path.exists(target):
|
|
340 |
if overrideTarget:
|
|
163 | 341 |
if ignoreExisting: |
164 | 342 |
continue |
343 |
|
|
344 |
else: |
|
345 |
if ignoreExisting: |
|
346 |
continue |
|
165 | 347 |
else: |
166 |
raise Exception("%s alredy exists in target folder %s" % (basename, targetFolder))
|
|
348 |
raise Exception("%s alredy exists in target folder %s" % (toMove, targetFolder))
|
|
167 | 349 |
|
350 |
|
|
168 | 351 |
# move file/dir |
169 | 352 |
shutil.move(Path.join(sourceFolder, toMove), targetFolder) |
170 | 353 |
|
354 |
|
|
355 |
""" |
|
356 |
Merge folder content: Copy all missing folders and files from |
|
357 |
``sourceFolder`` to ``targetFolder``. |
|
171 | 358 |
|
359 |
Process doesn't override existing files in ``targetFolder`` |
|
360 |
""" |
|
361 |
def mergeFolder(self,sourceFolder,targetFolder): |
|
362 |
# get folder contents |
|
363 |
names = os.listdir(sourceFolder) |
|
172 | 364 |
|
365 |
if not Path.exists(targetFolder): |
|
366 |
# Create target folder if not exists |
|
367 |
os.makedirs(targetFolder) |
|
368 |
|
|
369 |
for name in names: |
|
370 |
srcname = Path.join(sourceFolder, name) |
|
371 |
dstname = Path.join(targetFolder, name) |
|
372 |
if Path.isdir(srcname): |
|
373 |
# Recursive call to mergeFolder |
|
374 |
self.mergeFolder(srcname,dstname) |
|
375 |
else: |
|
376 |
if not Path.exists(dstname): |
|
377 |
# Copy new file |
|
378 |
shutil.copy(srcname,dstname) |
|
379 |
else: |
|
380 |
# skip existing file |
|
381 |
continue |
|
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
173 | 387 |
Also available in: Unified diff