forked from Guake/guake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-lib.py
172 lines (128 loc) · 4.51 KB
/
install-lib.py
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python
# Beware:
# - this script is executed using the system's python, so with not easy control on which
# packages are available. Same, we cannot directly install new ones using pip.
# - the role of the first stage of this installer is just to install a fresh new virtualenv
# with a *controled* version of python, pip and virtualenv, and launch the second part of
# the installer, 'install-stage2.py', which will run in the virtualenv.
# Note:
# - I try to keep this installer python-2.6 friendly, but I really encourage you to install
# Python 2.7
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import shutil
import subprocess
import sys
from optparse import OptionParser
g_prefix = None
g_src_dir = os.path.abspath(os.path.dirname(__file__))
# Do *not* use optparse or argparse here, we are not sure on which version of python we are!
isWindows = False
if sys.platform.startswith('win32'):
isWindows = True
#
# Utility functions
#
class bcolors(object):
DEBUG = '\033[90m'
HEADER = '\033[95m'
OKBLUE = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
BOOT = '\033[94m'
ENDC = '\033[0m'
# Do *not* use color when:
# - on windows
# - not in a terminal except if we are in Travis CI
if (isWindows or (
not os.environ.get("TRAVIS") and
not sys.stdout.isatty() and
not os.environ.get("TERM") in {
"xterm",
"xterm-256colors"
})):
bcolors.HEADER = ''
bcolors.OKBLUE = ''
bcolors.OKGREEN = ''
bcolors.WARNING = ''
bcolors.FAIL = ''
bcolors.BOLD = ''
bcolors.UNDERLINE = ''
bcolors.BOOT = ''
bcolors.ENDC = ''
def flush():
sys.stdout.flush()
sys.stderr.flush()
def printInfo(text):
print(bcolors.OKBLUE + "[INFO ] " + bcolors.ENDC + text)
flush()
def printDebug(text):
print(bcolors.DEBUG + "[DEBUG] " + bcolors.ENDC + text, file=sys.stderr)
flush()
def printError(text):
print(bcolors.FAIL + "[ERROR] " + bcolors.ENDC + text, file=sys.stderr)
flush()
def printSeparator(char="-", color=bcolors.OKGREEN):
print(color + char * 79 + bcolors.ENDC)
flush()
def printNote(text):
print(bcolors.HEADER + "[NOTE ] " + bcolors.ENDC + text)
flush()
def printBoot(text):
print(bcolors.BOOT + "[BOOT ] " + bcolors.ENDC + text)
flush()
def run(cmd, cwd=None, shell=False):
print(bcolors.OKGREEN + "[CMD ]" + bcolors.ENDC + " {}".format(" ".join(cmd)))
flush()
subprocess.check_call(cmd, shell=shell, cwd=cwd)
def call(cmd, cwd=None, shell=False):
print(bcolors.OKGREEN + "[CMD ]" + bcolors.ENDC + " {}".format(" ".join(cmd)))
flush()
return subprocess.call(cmd, shell=shell, cwd=cwd)
def run_background(cmd, cwd=None, shell=False):
print(bcolors.OKGREEN + "[CMD (background)" + bcolors.ENDC + "] {}".format(" ".join(cmd)))
flush()
subprocess.Popen(cmd, cwd=cwd, shell=shell)
def execute(cmdLine):
return run([cmdLine], shell=True)
#
def addArgumentParser(description=None):
usage = "usage: %prog [options]\n\n{}".format(description)
parser = OptionParser(usage=usage)
parser.add_option("-p", "--prefix",
dest="prefix",
help="install architecture-independent files in PREFIX",
metavar="DIR",
default="/usr/local")
parser.add_option("-q", "--quiet",
action="store_false", dest="verbose", default=True,
help="don't print status messages to stdout")
return parser
def parse(parser):
(options, args) = parser.parse_args()
global g_prefix
g_prefix = options.prefix
return (options, args)
#
def makedirs(dirPath):
try:
os.makedirs(dirPath)
except:
pass
def copyFile(relativeSrcPath, relativeDestPath):
printInfo("Copying {} to {}".format(relativeSrcPath, relativeDestPath))
src_full_path = os.path.join(g_src_dir, relativeSrcPath)
src_file_name = os.path.basename(relativeSrcPath)
dst_full_path = os.path.join(g_prefix, relativeDestPath)
printDebug("Src full path: {}".format(src_full_path))
printDebug("Src file path: {}".format(src_file_name))
printDebug("Dst full path: {}".format(dst_full_path))
dst_dir = os.path.dirname(dst_full_path)
makedirs(dst_dir)
shutil.copy(src_full_path, dst_full_path)
printDebug("{} -> {}".format(relativeSrcPath, dst_full_path))