|
6 | 6 | from pythonbrew.define import PATH_BUILD, PATH_BIN, PATH_DISTS, PATH_PYTHONS,\ |
7 | 7 | PATH_ETC, PATH_SCRIPTS, PATH_SCRIPTS_PYTHONBREW,\ |
8 | 8 | PATH_SCRIPTS_PYTHONBREW_COMMANDS, PATH_BIN_PYTHONBREW,\ |
9 | | - ROOT, PATH_LOG, PATH_PATCHES, PATH_ETC_CONFIG,\ |
10 | | - PATH_SCRIPTS_PYTHONBREW_INSTALLER, PATH_VENVS, PATH_HOME_ETC |
| 9 | + PATH_LOG, PATH_PATCHES, PATH_ETC_CONFIG,\ |
| 10 | + PATH_SCRIPTS_PYTHONBREW_INSTALLER, PATH_VENVS, PATH_HOME_ETC, ROOT |
11 | 11 | import stat |
12 | 12 |
|
13 | 13 | class PythonbrewInstaller(object): |
14 | 14 | """pythonbrew installer: |
15 | 15 | """ |
16 | 16 |
|
17 | | - def install(self, installer_root): |
| 17 | + @staticmethod |
| 18 | + def install(installer_root): |
18 | 19 | # create directories |
19 | 20 | makedirs(PATH_PYTHONS) |
20 | 21 | makedirs(PATH_BUILD) |
@@ -62,12 +63,43 @@ def install(self, installer_root): |
62 | 63 | os.chmod(PATH_BIN_PYTHONBREW, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR|stat.S_IRGRP|stat.S_IXGRP|stat.S_IROTH|stat.S_IXOTH) |
63 | 64 |
|
64 | 65 | # create a bashrc for pythonbrew |
65 | | - fp = open(os.path.join(PATH_ETC,'bashrc'), 'w') |
66 | | - for line in open(os.path.join(installer_root,'etc','bashrc')): |
67 | | - line = line.replace('@ROOT@', ROOT) |
68 | | - fp.write(line) |
69 | | - fp.close() |
| 66 | + shutil.copy(os.path.join(installer_root,'etc','bashrc'), os.path.join(PATH_ETC,'bashrc')) |
70 | 67 |
|
71 | 68 | # copy config.cfg |
72 | 69 | shutil.copy(os.path.join(installer_root,'etc','config.cfg'), PATH_ETC_CONFIG) |
73 | | - |
| 70 | + |
| 71 | + @staticmethod |
| 72 | + def systemwide_install(): |
| 73 | + profile = """\ |
| 74 | +#begin-pythonbrew |
| 75 | +if [ -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}" ] ; then |
| 76 | + export PYTHONBREW_ROOT=%(root)s |
| 77 | + source "${PYTHONBREW_ROOT}/etc/bashrc" |
| 78 | +fi |
| 79 | +#end-pythonbrew |
| 80 | +""" % {'root': ROOT} |
| 81 | + |
| 82 | + if os.path.isdir('/etc/profile.d'): |
| 83 | + fp = open('/etc/profile.d/pythonbrew.sh', 'w') |
| 84 | + fp.write(profile) |
| 85 | + fp.close() |
| 86 | + elif os.path.isfile('/etc/profile'): |
| 87 | + output = [] |
| 88 | + is_copy = True |
| 89 | + fp = open('/etc/profile', 'r') |
| 90 | + for line in fp: |
| 91 | + if line.startswith('#begin-pythonbrew'): |
| 92 | + is_copy = False |
| 93 | + continue |
| 94 | + elif line.startswith('#end-pythonbrew'): |
| 95 | + is_copy = True |
| 96 | + continue |
| 97 | + if is_copy: |
| 98 | + output.append(line) |
| 99 | + fp.close() |
| 100 | + output.append(profile) |
| 101 | + |
| 102 | + fp = open('/etc/profile', 'w') |
| 103 | + fp.write(''.join(output)) |
| 104 | + fp.close() |
| 105 | + |
0 commit comments