This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathpythonzinstaller.py
More file actions
113 lines (94 loc) · 3.7 KB
/
pythonzinstaller.py
File metadata and controls
113 lines (94 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import os
import sys
import glob
import shutil
import stat
import time
from pythonz.util import makedirs, rm_r
from pythonz.define import PATH_BUILD, PATH_BIN, PATH_DISTS, PATH_PYTHONS,\
PATH_ETC, PATH_SCRIPTS, PATH_SCRIPTS_PYTHONZ,\
PATH_SCRIPTS_PYTHONZ_COMMANDS, PATH_BIN_PYTHONZ,\
PATH_LOG, PATH_PATCHES,\
PATH_SCRIPTS_PYTHONZ_INSTALLER, PATH_HOME_ETC, ROOT,\
PATH_BASH_COMPLETION
class PythonzInstaller(object):
"""pythonz installer:
"""
@staticmethod
def install(installer_root):
# create directories
makedirs(PATH_PYTHONS)
makedirs(PATH_BUILD)
makedirs(PATH_DISTS)
makedirs(PATH_ETC)
makedirs(PATH_BASH_COMPLETION)
makedirs(PATH_BIN)
makedirs(PATH_LOG)
makedirs(PATH_HOME_ETC)
# create script directories
rm_r(PATH_SCRIPTS)
makedirs(PATH_SCRIPTS)
makedirs(PATH_SCRIPTS_PYTHONZ)
makedirs(PATH_SCRIPTS_PYTHONZ_COMMANDS)
makedirs(PATH_SCRIPTS_PYTHONZ_INSTALLER)
# copy all .py files
for path in glob.glob(os.path.join(installer_root,"*.py")):
shutil.copy(path, PATH_SCRIPTS_PYTHONZ)
for path in glob.glob(os.path.join(installer_root,"commands","*.py")):
shutil.copy(path, PATH_SCRIPTS_PYTHONZ_COMMANDS)
for path in glob.glob(os.path.join(installer_root,"installer","*.py")):
shutil.copy(path, PATH_SCRIPTS_PYTHONZ_INSTALLER)
# create patches direcotry
rm_r(PATH_PATCHES)
shutil.copytree(os.path.join(installer_root,"patches"), PATH_PATCHES)
# create a main file
with open("%s/pythonz_main.py" % PATH_SCRIPTS, "w") as f:
f.write("""import pythonz
if __name__ == "__main__":
pythonz.main()
""")
# create entry point file
with open(PATH_BIN_PYTHONZ, "w") as f:
f.write("""#!/usr/bin/env bash
$(which python || which python3) %s/pythonz_main.py "$@"
""" % PATH_SCRIPTS)
# mode 0755
os.chmod(PATH_BIN_PYTHONZ, 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 pythonz
shutil.copy(os.path.join(installer_root,'etc','bashrc'), os.path.join(PATH_ETC,'bashrc'))
# create a fish file for pythonz
shutil.copy(os.path.join(installer_root, 'etc', 'pythonz.fish'), os.path.join(PATH_ETC, 'pythonz.fish'))
#copy all *.sh files to bash_completion.d directory
for path in glob.glob(os.path.join(installer_root,"etc","bash_completion.d","*.sh")):
shutil.copy( path, PATH_BASH_COMPLETION )
@staticmethod
def systemwide_install():
profile = """\
#begin-pythonz
if [ -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}" ] ; then
export PYTHONZ_ROOT=%(root)s
source "${PYTHONZ_ROOT}/etc/bashrc"
fi
#end-pythonz
""" % {'root': ROOT}
if os.path.isdir('/etc/profile.d'):
with open('/etc/profile.d/pythonz.sh', 'w') as f:
f.write(profile)
elif os.path.isfile('/etc/profile'):
# create backup
shutil.copy('/etc/profile', '/tmp/profile.pythonz.%s' % int(time.time()))
output = []
is_copy = True
with open('/etc/profile', 'r') as f:
for line in f:
if line.startswith('#begin-pythonz'):
is_copy = False
continue
elif line.startswith('#end-pythonz'):
is_copy = True
continue
if is_copy:
output.append(line)
output.append(profile)
with open('/etc/profile', 'w') as f:
f.write(''.join(output))