add systemwide install support

This commit is contained in:
utahta
2011-08-07 03:48:38 +09:00
parent 7b2fa2f0eb
commit 4993f466e9
6 changed files with 126 additions and 38 deletions
+41 -9
View File
@@ -6,15 +6,16 @@ from pythonbrew.util import makedirs, rm_r
from pythonbrew.define import PATH_BUILD, PATH_BIN, PATH_DISTS, PATH_PYTHONS,\
PATH_ETC, PATH_SCRIPTS, PATH_SCRIPTS_PYTHONBREW,\
PATH_SCRIPTS_PYTHONBREW_COMMANDS, PATH_BIN_PYTHONBREW,\
ROOT, PATH_LOG, PATH_PATCHES, PATH_ETC_CONFIG,\
PATH_SCRIPTS_PYTHONBREW_INSTALLER, PATH_VENVS, PATH_HOME_ETC
PATH_LOG, PATH_PATCHES, PATH_ETC_CONFIG,\
PATH_SCRIPTS_PYTHONBREW_INSTALLER, PATH_VENVS, PATH_HOME_ETC, ROOT
import stat
class PythonbrewInstaller(object):
"""pythonbrew installer:
"""
def install(self, installer_root):
@staticmethod
def install(installer_root):
# create directories
makedirs(PATH_PYTHONS)
makedirs(PATH_BUILD)
@@ -62,12 +63,43 @@ if __name__ == "__main__":
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)
# create a bashrc for pythonbrew
fp = open(os.path.join(PATH_ETC,'bashrc'), 'w')
for line in open(os.path.join(installer_root,'etc','bashrc')):
line = line.replace('@ROOT@', ROOT)
fp.write(line)
fp.close()
shutil.copy(os.path.join(installer_root,'etc','bashrc'), os.path.join(PATH_ETC,'bashrc'))
# copy config.cfg
shutil.copy(os.path.join(installer_root,'etc','config.cfg'), PATH_ETC_CONFIG)
@staticmethod
def systemwide_install():
profile = """\
#begin-pythonbrew
if [ -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}" ] ; then
export PYTHONBREW_ROOT=%(root)s
source "${PYTHONBREW_ROOT}/etc/bashrc"
fi
#end-pythonbrew
""" % {'root': ROOT}
if os.path.isdir('/etc/profile.d'):
fp = open('/etc/profile.d/pythonbrew.sh', 'w')
fp.write(profile)
fp.close()
elif os.path.isfile('/etc/profile'):
output = []
is_copy = True
fp = open('/etc/profile', 'r')
for line in fp:
if line.startswith('#begin-pythonbrew'):
is_copy = False
continue
elif line.startswith('#end-pythonbrew'):
is_copy = True
continue
if is_copy:
output.append(line)
fp.close()
output.append(profile)
fp = open('/etc/profile', 'w')
fp.write(''.join(output))
fp.close()