44import shutil
55import re
66from pythonbrew .util import makedirs , symlink , Package , is_url , splitext , Link ,\
7- unlink , is_gzip , is_html , untar_file , Subprocess , rm_r ,\
8- is_macosx_snowleopard , is_python25 , is_python24 , is_python26
7+ unlink , is_html , Subprocess , rm_r ,\
8+ is_macosx_snowleopard , is_python25 , is_python24 , is_python26 ,\
9+ unpack_downloadfile
910from pythonbrew .define import PATH_BUILD , PATH_BIN , PATH_DISTS , PATH_PYTHONS ,\
1011 PATH_ETC , PATH_SCRIPTS , PATH_SCRIPTS_PYTHONBREW ,\
1112 PATH_SCRIPTS_PYTHONBREW_COMMANDS , INSTALLER_ROOT , PATH_BIN_PYTHONBREW ,\
1617from pythonbrew .log import logger
1718
1819def install_pythonbrew ():
19- makedirs (PATH_PYTHONS )
20- makedirs (PATH_BUILD )
21- makedirs (PATH_DISTS )
22- makedirs (PATH_ETC )
23- makedirs (PATH_BIN )
24- makedirs (PATH_LOG )
25- makedirs (PATH_SCRIPTS )
26- makedirs (PATH_SCRIPTS_PYTHONBREW )
27- makedirs (PATH_SCRIPTS_PYTHONBREW_COMMANDS )
28-
29- for path in glob .glob (os .path .join (INSTALLER_ROOT ,"*.py" )):
30- shutil .copy (path , PATH_SCRIPTS_PYTHONBREW )
31-
32- for path in glob .glob (os .path .join (INSTALLER_ROOT ,"commands" ,"*.py" )):
33- shutil .copy (path , PATH_SCRIPTS_PYTHONBREW_COMMANDS )
20+ PythonbrewInstaller ().install (INSTALLER_ROOT )
3421
35- rm_r (PATH_PATCHES )
36- shutil .copytree (os .path .join (INSTALLER_ROOT ,"patches" ), PATH_PATCHES )
22+ m = re .search ("(t?csh)" , os .environ .get ("SHELL" ))
23+ if m :
24+ shrc = "cshrc"
25+ yourshrc = m .group (1 )+ "rc"
26+ else :
27+ shrc = yourshrc = "bashrc"
3728
38- fp = open ("%s/pythonbrew_main.py" % PATH_SCRIPTS , "w" )
39- fp .write ("""import pythonbrew
29+ logger .info ("""
30+ Well-done! Congratulations!
31+
32+ The pythonbrew is installed as:
33+
34+ %(ROOT)s
35+
36+ Please add the following line to the end of your ~/.%(yourshrc)s
37+
38+ source %(PATH_ETC)s/%(shrc)s
39+
40+ After that, exit this shell, start a new one, and install some fresh
41+ pythons:
42+
43+ pythonbrew install 2.6.6
44+ pythonbrew install 2.5.5
45+
46+ For further instructions, run:
47+
48+ pythonbrew help
49+
50+ The default help messages will popup and tell you what to do!
51+
52+ Enjoy pythonbrew at %(ROOT)s!!
53+ """ % {'ROOT' :ROOT , 'yourshrc' :yourshrc , 'shrc' :shrc , 'PATH_ETC' :PATH_ETC })
54+
55+ class PythonbrewInstaller (object ):
56+ def install (self , installer_root ):
57+ makedirs (PATH_PYTHONS )
58+ makedirs (PATH_BUILD )
59+ makedirs (PATH_DISTS )
60+ makedirs (PATH_ETC )
61+ makedirs (PATH_BIN )
62+ makedirs (PATH_LOG )
63+ makedirs (PATH_SCRIPTS )
64+ makedirs (PATH_SCRIPTS_PYTHONBREW )
65+ makedirs (PATH_SCRIPTS_PYTHONBREW_COMMANDS )
66+
67+ for path in glob .glob (os .path .join (installer_root ,"*.py" )):
68+ shutil .copy (path , PATH_SCRIPTS_PYTHONBREW )
69+
70+ for path in glob .glob (os .path .join (installer_root ,"commands" ,"*.py" )):
71+ shutil .copy (path , PATH_SCRIPTS_PYTHONBREW_COMMANDS )
72+
73+ rm_r (PATH_PATCHES )
74+ shutil .copytree (os .path .join (installer_root ,"patches" ), PATH_PATCHES )
75+
76+ fp = open ("%s/pythonbrew_main.py" % PATH_SCRIPTS , "w" )
77+ fp .write ("""import pythonbrew
4078if __name__ == "__main__":
4179 pythonbrew.main()
4280""" )
43- fp .close ()
44-
45- fp = open (PATH_BIN_PYTHONBREW , "w" )
46- fp .write ("""#!/usr/bin/env bash
81+ fp .close ()
82+
83+ fp = open (PATH_BIN_PYTHONBREW , "w" )
84+ fp .write ("""#!/usr/bin/env bash
4785%s %s/pythonbrew_main.py "$@"
4886""" % (sys .executable , PATH_SCRIPTS ))
49- fp .close ()
50- os .chmod (PATH_BIN_PYTHONBREW , 0755 )
51- symlink (PATH_BIN_PYTHONBREW , PATH_BIN_PYBREW ) # pyb as pythonbrew
52-
53- os .system ("echo 'export PATH=%s/bin:%s/current/bin:${PATH}' > %s/bashrc" % (ROOT , PATH_PYTHONS , PATH_ETC ))
54- os .system ("echo 'setenv PATH %s/bin:%s/current/bin:$PATH' > %s/cshrc" % (ROOT , PATH_PYTHONS , PATH_ETC ))
87+ fp .close ()
88+ os .chmod (PATH_BIN_PYTHONBREW , 0755 )
89+ symlink (PATH_BIN_PYTHONBREW , PATH_BIN_PYBREW ) # pybrew is symbolic pythonbrew
90+
91+ os .system ("echo 'export PATH=%s/bin:%s/current/bin:${PATH}' > %s/bashrc" % (ROOT , PATH_PYTHONS , PATH_ETC ))
92+ os .system ("echo 'setenv PATH %s/bin:%s/current/bin:$PATH' > %s/cshrc" % (ROOT , PATH_PYTHONS , PATH_ETC ))
5593
5694class PythonInstaller (object ):
5795 def __init__ (self , arg , options ):
@@ -132,16 +170,13 @@ def download(self):
132170 sys .exit (1 )
133171
134172 def unpack (self ):
135- logger .info ("Extracting %s" % os .path .basename (self .download_file ))
136- if is_gzip (self .content_type , self .download_file ):
137- untar_file (self .download_file , self .build_dir )
138- else :
139- logger .error ("Cannot determine archive format of %s" % self .download_file )
173+ if not unpack_downloadfile (self .content_type , self .download_file , self .build_dir ):
174+ sys .exit (1 )
140175
141176 def patch (self ):
142177 version = self .pkg .version
143178 try :
144- s = Subprocess (log = self .logfile , shell = True , cwd = self .build_dir , print_cmd = False )
179+ s = Subprocess (log = self .logfile , cwd = self .build_dir )
145180 patches = []
146181 if is_macosx_snowleopard ():
147182 if is_python24 (version ):
@@ -179,11 +214,11 @@ def configure(self):
179214 elif is_python26 (version ):
180215 configure_option = '--with-universal-archs="intel" MACOSX_DEPLOYMENT_TARGET=10.6'
181216
182- s = Subprocess (log = self .logfile , shell = True , cwd = self .build_dir , print_cmd = False )
217+ s = Subprocess (log = self .logfile , cwd = self .build_dir )
183218 s .check_call ("./configure --prefix=%s %s %s" % (self .install_dir , self .options .configure , configure_option ))
184219
185220 def make (self ):
186- s = Subprocess (log = self .logfile , shell = True , cwd = self .build_dir , print_cmd = False )
221+ s = Subprocess (log = self .logfile , cwd = self .build_dir )
187222 if self .options .force :
188223 s .check_call ("make" )
189224 else :
@@ -194,7 +229,7 @@ def make_install(self):
194229 version = self .pkg .version
195230 if version == "1.5.2" or version == "1.6.1" :
196231 makedirs (self .install_dir )
197- s = Subprocess (log = self .logfile , shell = True , cwd = self .build_dir , print_cmd = False )
232+ s = Subprocess (log = self .logfile , cwd = self .build_dir )
198233 s .check_call ("make install" )
199234
200235 def install_setuptools (self ):
@@ -227,12 +262,12 @@ def install_setuptools(self):
227262 pyexec = os .path .join (install_dir ,"bin" ,"python" )
228263
229264 try :
230- s = Subprocess (log = self .logfile , shell = True , cwd = PATH_DISTS , print_cmd = False )
265+ s = Subprocess (log = self .logfile , cwd = PATH_DISTS )
231266 logger .info ("Installing distribute into %s" % install_dir )
232267 s .check_call ("%s %s" % (pyexec , filename ))
233268 if os .path .isfile ("%s/bin/easy_install" % (install_dir )) and not is_python3 :
234269 logger .info ("Installing pip into %s" % install_dir )
235- s .check_call ("%s/bin/easy_install pip" % (install_dir ), cwd = None )
270+ s .check_call ("%s/bin/easy_install pip" % (install_dir ))
236271 except :
237272 logger .error ("Failed to install setuptools. See %s/build.log to see why." % (ROOT ))
238273 logger .info ("Skip install setuptools." )
0 commit comments