50 self.__add_package_def('LXML', setup= 'lxml', url=self.get_src_base_path("lxml_2.2.8.tar.gz"), local="lxml-2.2.8.tar.gz") |
52 self.__add_package_def('LXML', setup= 'lxml', url=self.get_src_base_path("lxml_2.2.8.tar.gz"), local="lxml-2.2.8.tar.gz") |
51 |
53 |
52 def __init_normal_install(self): |
54 def __init_normal_install(self): |
53 system_str = platform.system() |
55 system_str = platform.system() |
54 self.NORMAL_INSTALL = [ #(key,method, option_str, extra_env) |
56 self.NORMAL_INSTALL = [ #(key,method, option_str, extra_env) |
|
57 ('SETUPTOOLS-HG', 'pip', None, None), |
55 ('MYSQL', 'pip', None, None), |
58 ('MYSQL', 'pip', None, None), |
56 ('PIL', 'easy_install', None, None), |
59 ('PIL', 'easy_install', None, None), |
57 ('DJANGO','pip', None, None), |
60 ('DJANGO','pip', None, None), |
58 ('JOGGING','pip', None, None), |
61 ('JOGGING','pip', None, None), |
59 ('DJANGO-EXTENSIONS', 'pip', None, None), |
62 ('DJANGO-EXTENSIONS', 'pip', None, None), |
60 ('DJANGO-REGISTRATION', 'easy_install', '-Z', None), |
63 ('DJANGO-REGISTRATION', 'easy_install', '-Z', None), |
61 ('DJANGO-TAGGING', 'pip', None, None), |
64 ('DJANGO-TAGGING', 'pip', None, None), |
62 ('DJANGO-PISTON', 'pip', None, None), |
65 ('DJANGO-PISTON', 'pip', None, None), |
63 ('SETUPTOOLS-HG', 'pip', None, None), |
|
64 ('HTTPLIB2', 'pip', None, None), |
66 ('HTTPLIB2', 'pip', None, None), |
65 ('OAUTH2', 'easy_install', None, None), |
67 ('OAUTH2', 'easy_install', None, None), |
66 ('DJANGO-OAUTH-PLUS', 'pip', None, None), |
68 ('DJANGO-OAUTH-PLUS', 'pip', None, None), |
67 ] |
69 ] |
68 if system_str == "Windows": |
70 if system_str == "Windows": |
79 |
81 |
80 if system_str == 'Linux': |
82 if system_str == 'Linux': |
81 self.NORMAL_INSTALL.insert(0, ('DISTRIBUTE', 'pip', None, None)) |
83 self.NORMAL_INSTALL.insert(0, ('DISTRIBUTE', 'pip', None, None)) |
82 |
84 |
83 |
85 |
84 def extend_parser(parser): |
86 def generate_install_methods(path_locations, src_base, Logger, call_subprocess): |
85 |
87 |
86 parser.add_option( |
88 res_env = ResourcesEnv(src_base) |
87 '--index-url', |
89 |
88 metavar='INDEX_URL', |
90 def extend_parser(parser): |
89 dest='index_url', |
91 parser.add_option( |
90 default='http://pypi.python.org/simple/', |
92 '--index-url', |
91 help='base URL of Python Package Index') |
93 metavar='INDEX_URL', |
92 parser.add_option( |
94 dest='index_url', |
93 '--type-install', |
95 default='http://pypi.python.org/simple/', |
94 metavar='type_install', |
96 help='base URL of Python Package Index') |
95 dest='type_install', |
97 parser.add_option( |
96 default='local', |
98 '--type-install', |
97 help='type install : local, url, setup') |
99 metavar='type_install', |
98 parser.add_option( |
100 dest='type_install', |
99 '--ignore-packages', |
101 default='local', |
100 metavar='ignore_packages', |
102 help='type install : local, url, setup') |
101 dest='ignore_packages', |
103 parser.add_option( |
102 default=None, |
104 '--ignore-packages', |
103 help='list of comma separated keys for package to ignore') |
105 metavar='ignore_packages', |
104 |
106 dest='ignore_packages', |
105 |
107 default=None, |
106 def adjust_options(options, args): |
108 help='list of comma separated keys for package to ignore') |
107 pass |
109 |
108 |
110 |
109 |
111 def adjust_options(options, args): |
110 def after_install(options, home_dir): |
112 pass |
111 global RES_ENV |
113 |
112 #global path_locations |
114 |
113 home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir) |
115 def after_install(options, home_dir): |
114 base_dir = os.path.dirname(home_dir) |
116 |
115 src_dir = os.path.join(home_dir, 'src') |
117 global logger |
116 tmp_dir = os.path.join(home_dir, 'tmp') |
118 |
117 ensure_dir(src_dir) |
119 verbosity = options.verbose - options.quiet |
118 ensure_dir(tmp_dir) |
120 logger = Logger([(Logger.level_for_integer(2-verbosity), sys.stdout)]) |
119 system_str = platform.system() |
121 |
120 |
122 |
121 res_source_key = options.type_install |
123 home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir) |
122 |
124 base_dir = os.path.dirname(home_dir) |
123 ignore_packages = [] |
125 src_dir = os.path.join(home_dir, 'src') |
124 |
126 tmp_dir = os.path.join(home_dir, 'tmp') |
125 if options.ignore_packages : |
127 ensure_dir(src_dir) |
126 ignore_packages = options.ignore_packages.split(",") |
128 ensure_dir(tmp_dir) |
127 |
129 system_str = platform.system() |
128 logger.indent += 2 |
130 |
129 try: |
131 res_source_key = options.type_install |
130 |
132 |
131 if 'PYLUCENE' not in ignore_packages and system_str != "Windows": |
133 ignore_packages = [] |
132 #get pylucene |
134 |
133 logger.notify("Get Pylucene from %s " % RES_ENV.URLS['PYLUCENE'][res_source_key]) |
135 if options.ignore_packages : |
134 pylucene_src = os.path.join(src_dir,"pylucene.tar.gz") |
136 ignore_packages = options.ignore_packages.split(",") |
135 if res_source_key == 'local': |
137 |
136 shutil.copy(RES_ENV.URLS['PYLUCENE'][res_source_key], pylucene_src) |
138 logger.indent += 2 |
|
139 try: |
|
140 |
|
141 if 'PYLUCENE' not in ignore_packages and system_str != "Windows": |
|
142 #get pylucene |
|
143 logger.notify("Get Pylucene from %s " % res_env.URLS['PYLUCENE'][res_source_key]) |
|
144 pylucene_src = os.path.join(src_dir,"pylucene.tar.gz") |
|
145 if res_source_key == 'local': |
|
146 shutil.copy(res_env.URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
147 else: |
|
148 urllib.urlretrieve(res_env.URLS['PYLUCENE'][res_source_key], pylucene_src) |
|
149 tf = tarfile.open(pylucene_src,'r:gz') |
|
150 pylucene_base_path = os.path.join(src_dir,"pylucene") |
|
151 logger.notify("Extract Pylucene to %s " % pylucene_base_path) |
|
152 tf.extractall(pylucene_base_path) |
|
153 tf.close() |
|
154 |
|
155 pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0]) |
|
156 jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc")) |
|
157 |
|
158 #install jcc |
|
159 |
|
160 #patch for linux |
|
161 if system_str == 'Linux' : |
|
162 olddir = os.getcwd() |
|
163 patch_dest_path = os.path.join(lib_dir,'site-packages','setuptools-0.6c11-py'+'%s.%s' % (sys.version_info[0], sys.version_info[1])+'.egg') |
|
164 if os.path.isfile(patch_dest_path): |
|
165 # must unzip egg |
|
166 # rename file and etract all |
|
167 shutil.move(patch_dest_path, patch_dest_path + ".zip") |
|
168 zf = zipfile.ZipFile(patch_dest_path + ".zip",'r') |
|
169 zf.extractall(patch_dest_path) |
|
170 os.remove(patch_dest_path + ".zip") |
|
171 logger.notify("Patch jcc : %s " % (patch_dest_path)) |
|
172 os.chdir(patch_dest_path) |
|
173 p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11")) |
|
174 p.apply() |
|
175 os.chdir(olddir) |
|
176 |
|
177 logger.notify("Install jcc") |
|
178 call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'], |
|
179 cwd=jcc_src_path, |
|
180 filter_stdout=filter_python_develop, |
|
181 show_stdout=True) |
|
182 #install pylucene |
|
183 |
|
184 logger.notify("Install pylucene") |
|
185 #modify makefile |
|
186 makefile_path = os.path.join(pylucene_src_path,"Makefile") |
|
187 logger.notify("Modify makefile %s " % makefile_path) |
|
188 shutil.move( makefile_path, makefile_path+"~" ) |
|
189 |
|
190 destination= open( makefile_path, "w" ) |
|
191 source= open( makefile_path+"~", "r" ) |
|
192 destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\n") |
|
193 destination.write("ANT=ant\n") |
|
194 destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\n") |
|
195 |
|
196 if system_str == "Darwin": |
|
197 if sys.version_info >= (2,6): |
|
198 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\n") |
|
199 else: |
|
200 destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\n") |
|
201 destination.write("NUM_FILES=2\n") |
|
202 elif system_str == "Windows": |
|
203 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\n") |
|
204 destination.write("NUM_FILES=2\n") |
|
205 else: |
|
206 if sys.version_info >= (2,6) and sys.version_info <= (2,7): |
|
207 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared\n") |
|
208 else: |
|
209 destination.write("JCC=$(PYTHON) -m jcc --shared\n") |
|
210 destination.write("NUM_FILES=2\n") |
|
211 for line in source: |
|
212 destination.write( line ) |
|
213 source.close() |
|
214 destination.close() |
|
215 os.remove(makefile_path+"~" ) |
|
216 |
|
217 logger.notify("pylucene make") |
|
218 call_subprocess(['make'], |
|
219 cwd=os.path.abspath(pylucene_src_path), |
|
220 filter_stdout=filter_python_develop, |
|
221 show_stdout=True) |
|
222 |
|
223 logger.notify("pylucene make install") |
|
224 call_subprocess(['make', 'install'], |
|
225 cwd=os.path.abspath(pylucene_src_path), |
|
226 filter_stdout=filter_python_develop, |
|
227 show_stdout=True) |
|
228 |
|
229 |
|
230 if 'PSYCOPG2' not in ignore_packages and system_str == "Windows": |
|
231 #get psycopg2 |
|
232 psycopg2_src = os.path.join(src_dir,"psycopg2.zip") |
|
233 shutil.copy(res_env.URLS['PSYCOPG2'][res_source_key], psycopg2_src) |
|
234 #extract psycopg2 |
|
235 zf = zipfile.ZipFile(psycopg2_src) |
|
236 psycopg2_base_path = os.path.join(src_dir,"psycopg2") |
|
237 zf.extractall(psycopg2_base_path) |
|
238 zf.close() |
|
239 |
|
240 psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0]) |
|
241 shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib', 'psycopg2'))) |
|
242 shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.0.10-py2.6.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib', 'site-packages'))) |
|
243 |
|
244 for key, method, option_str, extra_env in res_env.NORMAL_INSTALL: |
|
245 if key not in ignore_packages: |
|
246 normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir) |
|
247 |
|
248 logger.notify("Clear source dir") |
|
249 shutil.rmtree(src_dir) |
|
250 |
|
251 finally: |
|
252 logger.indent -= 2 |
|
253 script_dir = join(base_dir, bin_dir) |
|
254 logger.notify('Run "%s Package" to install new packages that provide builds' |
|
255 % join(script_dir, 'easy_install')) |
|
256 |
|
257 |
|
258 def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir): |
|
259 global logger |
|
260 logger.notify("Install %s from %s with %s" % (key,res_env.URLS[key][res_source_key],method)) |
|
261 if method == 'pip': |
|
262 if sys.platform == 'win32': |
|
263 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', '-E', os.path.abspath(home_dir), res_env.URLS[key][res_source_key]] |
137 else: |
264 else: |
138 urllib.urlretrieve(RES_ENV.URLS['PYLUCENE'][res_source_key], pylucene_src) |
265 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), res_env.URLS[key][res_source_key]] |
139 tf = tarfile.open(pylucene_src,'r:gz') |
266 if option_str : |
140 pylucene_base_path = os.path.join(src_dir,"pylucene") |
267 args.insert(4,option_str) |
141 logger.notify("Extract Pylucene to %s " % pylucene_base_path) |
268 call_subprocess(args, |
142 tf.extractall(pylucene_base_path) |
269 cwd=os.path.abspath(tmp_dir), |
143 tf.close() |
270 filter_stdout=filter_python_develop, |
144 |
271 show_stdout=True, |
145 pylucene_src_path = os.path.join(pylucene_base_path, os.listdir(pylucene_base_path)[0]) |
272 extra_env=extra_env) |
146 jcc_src_path = os.path.abspath(os.path.join(pylucene_src_path,"jcc")) |
273 else: |
147 |
274 if sys.platform == 'win32': |
148 #install jcc |
275 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), res_env.URLS[key][res_source_key]] |
149 |
|
150 #patch for linux |
|
151 if system_str == 'Linux' : |
|
152 olddir = os.getcwd() |
|
153 patch_dest_path = os.path.join(lib_dir,'site-packages','setuptools-0.6c11-py'+'%s.%s' % (sys.version_info[0], sys.version_info[1])+'.egg') |
|
154 if os.path.isfile(patch_dest_path): |
|
155 # must unzip egg |
|
156 # rename file and etract all |
|
157 shutil.move(patch_dest_path, patch_dest_path + ".zip") |
|
158 zf = zipfile.ZipFile(patch_dest_path + ".zip",'r') |
|
159 zf.extractall(patch_dest_path) |
|
160 os.remove(patch_dest_path + ".zip") |
|
161 logger.notify("Patch jcc : %s " % (patch_dest_path)) |
|
162 os.chdir(patch_dest_path) |
|
163 p = patch.fromfile(os.path.join(jcc_src_path,"jcc","patches","patch.43.0.6c11")) |
|
164 p.apply() |
|
165 os.chdir(olddir) |
|
166 |
|
167 logger.notify("Install jcc") |
|
168 call_subprocess([os.path.abspath(os.path.join(home_dir, 'bin', 'python')), 'setup.py', 'install'], |
|
169 cwd=jcc_src_path, |
|
170 filter_stdout=filter_python_develop, |
|
171 show_stdout=True) |
|
172 #install pylucene |
|
173 |
|
174 logger.notify("Install pylucene") |
|
175 #modify makefile |
|
176 makefile_path = os.path.join(pylucene_src_path,"Makefile") |
|
177 logger.notify("Modify makefile %s " % makefile_path) |
|
178 shutil.move( makefile_path, makefile_path+"~" ) |
|
179 |
|
180 destination= open( makefile_path, "w" ) |
|
181 source= open( makefile_path+"~", "r" ) |
|
182 destination.write("PREFIX_PYTHON="+os.path.abspath(home_dir)+"\\n") |
|
183 destination.write("ANT=ant\\n") |
|
184 destination.write("PYTHON=$(PREFIX_PYTHON)/bin/python\\n") |
|
185 |
|
186 if system_str == "Darwin": |
|
187 if sys.version_info >= (2,6): |
|
188 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n") |
|
189 else: |
|
190 destination.write("JCC=$(PYTHON) -m jcc --shared --arch x86_64 --arch i386\\n") |
|
191 destination.write("NUM_FILES=2\\n") |
|
192 elif system_str == "Windows": |
|
193 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64 --arch i386\\n") |
|
194 destination.write("NUM_FILES=2\\n") |
|
195 else: |
276 else: |
196 if sys.version_info >= (2,6) and sys.version_info <= (2,7): |
277 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), res_env.URLS[key][res_source_key]] |
197 destination.write("JCC=$(PYTHON) -m jcc.__main__ --shared\\n") |
278 if option_str : |
198 else: |
279 args.insert(1,option_str) |
199 destination.write("JCC=$(PYTHON) -m jcc --shared\\n") |
280 call_subprocess(args, |
200 destination.write("NUM_FILES=2\\n") |
281 cwd=os.path.abspath(tmp_dir), |
201 for line in source: |
282 filter_stdout=filter_python_develop, |
202 destination.write( line ) |
283 show_stdout=True, |
203 source.close() |
284 extra_env=extra_env) |
204 destination.close() |
285 |
205 os.remove(makefile_path+"~" ) |
286 |
206 |
287 def ensure_dir(dir): |
207 logger.notify("pylucene make") |
288 global logger |
208 call_subprocess(['make'], |
289 if not os.path.exists(dir): |
209 cwd=os.path.abspath(pylucene_src_path), |
290 logger.notify('Creating directory %s' % dir) |
210 filter_stdout=filter_python_develop, |
291 os.makedirs(dir) |
211 show_stdout=True) |
292 |
212 |
293 def filter_python_develop(line): |
213 logger.notify("pylucene make install") |
294 if not line.strip(): |
214 call_subprocess(['make', 'install'], |
|
215 cwd=os.path.abspath(pylucene_src_path), |
|
216 filter_stdout=filter_python_develop, |
|
217 show_stdout=True) |
|
218 |
|
219 |
|
220 if 'PSYCOPG2' not in ignore_packages and system_str == "Windows": |
|
221 #get psycopg2 |
|
222 psycopg2_src = os.path.join(src_dir,"psycopg2.zip") |
|
223 shutil.copy(RES_ENV.URLS['PSYCOPG2'][res_source_key], psycopg2_src) |
|
224 #extract psycopg2 |
|
225 zf = zipfile.ZipFile(psycopg2_src) |
|
226 psycopg2_base_path = os.path.join(src_dir,"psycopg2") |
|
227 zf.extractall(psycopg2_base_path) |
|
228 zf.close() |
|
229 |
|
230 psycopg2_src_path = os.path.join(psycopg2_base_path, os.listdir(psycopg2_base_path)[0]) |
|
231 shutil.copytree(os.path.join(psycopg2_src_path, 'psycopg2'), os.path.abspath(os.path.join(home_dir, 'Lib', 'psycopg2'))) |
|
232 shutil.copy(os.path.join(psycopg2_src_path, 'psycopg2-2.0.10-py2.6.egg-info'), os.path.abspath(os.path.join(home_dir, 'Lib', 'site-packages'))) |
|
233 |
|
234 for key, method, option_str, extra_env in RES_ENV.NORMAL_INSTALL: |
|
235 if key not in ignore_packages: |
|
236 normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir) |
|
237 |
|
238 logger.notify("Clear source dir") |
|
239 shutil.rmtree(src_dir) |
|
240 |
|
241 finally: |
|
242 logger.indent -= 2 |
|
243 script_dir = join(base_dir, bin_dir) |
|
244 logger.notify('Run "%s Package" to install new packages that provide builds' |
|
245 % join(script_dir, 'easy_install')) |
|
246 |
|
247 |
|
248 def normal_install(key, method, option_str, extra_env, res_source_key, home_dir, tmp_dir): |
|
249 global logger |
|
250 logger.notify("Install %s from %s with %s" % (key,RES_ENV.URLS[key][res_source_key],method)) |
|
251 if method == 'pip': |
|
252 if sys.platform == 'win32': |
|
253 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'pip')), 'install', '-E', os.path.abspath(home_dir), RES_ENV.URLS[key][res_source_key]] |
|
254 else: |
|
255 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'pip')), 'install', '-E', os.path.abspath(home_dir), RES_ENV.URLS[key][res_source_key]] |
|
256 if option_str : |
|
257 args.insert(4,option_str) |
|
258 call_subprocess(args, |
|
259 cwd=os.path.abspath(tmp_dir), |
|
260 filter_stdout=filter_python_develop, |
|
261 show_stdout=True, |
|
262 extra_env=extra_env) |
|
263 else: |
|
264 if sys.platform == 'win32': |
|
265 args = [os.path.abspath(os.path.join(home_dir, 'Scripts', 'easy_install')), RES_ENV.URLS[key][res_source_key]] |
|
266 else: |
|
267 args = [os.path.abspath(os.path.join(home_dir, 'bin', 'easy_install')), RES_ENV.URLS[key][res_source_key]] |
|
268 if option_str : |
|
269 args.insert(1,option_str) |
|
270 call_subprocess(args, |
|
271 cwd=os.path.abspath(tmp_dir), |
|
272 filter_stdout=filter_python_develop, |
|
273 show_stdout=True, |
|
274 extra_env=extra_env) |
|
275 |
|
276 |
|
277 def ensure_dir(dir): |
|
278 global logger |
|
279 if not os.path.exists(dir): |
|
280 logger.notify('Creating directory %s' % dir) |
|
281 os.makedirs(dir) |
|
282 |
|
283 def filter_python_develop(line): |
|
284 global logger |
|
285 if not line.strip(): |
|
286 return Logger.DEBUG |
|
287 for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
288 'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
289 'creating ', 'Copying ']: |
|
290 if line.startswith(prefix): |
|
291 return Logger.DEBUG |
295 return Logger.DEBUG |
292 return Logger.NOTIFY |
296 for prefix in ['Searching for', 'Reading ', 'Best match: ', 'Processing ', |
|
297 'Moving ', 'Adding ', 'running ', 'writing ', 'Creating ', |
|
298 'creating ', 'Copying ']: |
|
299 if line.startswith(prefix): |
|
300 return Logger.DEBUG |
|
301 return Logger.NOTIFY |
|
302 |
|
303 return adjust_options, extend_parser, after_install |