-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckdependencies.py
executable file
·168 lines (126 loc) · 6.28 KB
/
checkdependencies.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
#!/usr/bin/env python2
import imp, os, sys, subprocess
from distutils import spawn
try:
import pip
except:
pip = None
dirname = os.path.dirname(__file__)
from lib import wireutils
wireutils.color_printing_config.name = "Perdyshot"
wireutils.color_printing_config.color = wireutils.ansi_colors.DARKCYAN
def readBool(text):
reply = wireutils.color_input(text + ' (y/n): ')
if reply == 'y':
return True
elif reply == 'n':
return False
else:
print
wireutils.color_print("Invalid option. Please answer y or n for yes or no.\n", color = wireutils.ansi_colors.RED)
return readBool(text)
def hasModule(name):
try:
imp.find_module(name)
return True
except ImportError:
return False
def checkModule(name):
installed = hasModule(name)
if installed:
if not args.get("quiet") and args.get("clean"):
print wireutils.format("m {name}: y", name = name)
elif not args.get("quiet"):
wireutils.color_print("Module {name} installed.", name = name, color = wireutils.ansi_colors.GREEN)
else:
if args.get("clean"):
print wireutils.format("m {name}: n", name = name)
else:
wireutils.color_print("Module {name} not installed.", name = name, color = wireutils.ansi_colors.RED)
return installed
def installModule(name):
if pip and not args.get("dry") and not args.get("clean"):
pip.main(["install", "-U", name])
def moduleNeedsInstalling(name):
installed = checkModule(name)
if not args.get("dry"):
if installed or args.get("clean"):
return False
elif ROOT:
return readBool("Do you wish to install it now?")
def manualInstallNotify(name, tutorial):
if not args.get("dry") and not args.get("clean"):
if not readBool("%s can't be automatically installled.\nPlease refer to {blue}{line}%s{endc} to install it manually.\nDo you wish to continue?" % (name, tutorial)):
sys.exit()
def checkApplication(name, friendlyName, tutorial):
installed = spawn.find_executable(name) != None
if installed:
if not args.get("quiet") and args.get("clean"):
print wireutils.format("a {name}: y", name = name)
elif not args.get("quiet"):
wireutils.color_print("Executable {name} ({readable}) found.", name = name, readable = friendlyName, color=wireutils.ansi_colors.GREEN)
else:
if args.get("clean"):
print wireutils.format("a {name}: n", name = name)
else:
wireutils.color_print("Executable {name} ({readable}) not found.", name = name, readable = friendlyName, color=wireutils.ansi_colors.RED)
if not installed and not args.get("dry"):
manualInstallNotify(friendlyName, tutorial)
if __name__ == "__main__":
try:
try:
import argparse
parser = argparse.ArgumentParser(description = 'Checks the Perdyshot dependencies.', usage="%(prog)s [options]")
parser.add_argument('-o', '--omit', help="Omit an update step", default="", choices=["module", "app", "m", "a"], dest="omit")
parser.add_argument('--dry-run', help="Don't actually do anything", action = 'store_true', dest="dry")
parser.add_argument('-q', '--quiet', help="Supress most output", action = 'store_true', dest="quiet")
parser.add_argument('--porcelain', help="Machine-readable output (implies --dry-run)", action = 'store_true', dest="clean")
args = vars(parser.parse_args())
except Exception:
wireutils.color_print("Argparse library missing. Will not be able to parse cli arguments.\n", color=wireutils.ansi_colors.DARKRED)
args = {}
if not args.get("quiet") and not args.get("clean"):
wireutils.color_print("""Perdyshot Dependency Checker
{bold}============================{endc}
""",
strip = True)
ROOT = os.geteuid() == 0
if not args.get("dry") and not args.get("clean"):
if not ROOT:
if not readBool("You aren't root.\nInstalling missing packages will not be supported.\nDo you wish to continue?"):
sys.exit()
print
if not pip:
if not readBool("{bold}pip{endc} isn't installed.\nInstalling missing packages will not be supported.\nDo you wish to continue?"):
sys.exit()
print
if args.get("omit") not in ["module", "m"]:
if not args.get("quiet") and not args.get("clean"):
wireutils.color_print("Checking module dependencies for Perdyshot ...\n{bold}----------------------------------------------{endc}\n")
if moduleNeedsInstalling("argparse"):
installModule("argparse")
if moduleNeedsInstalling("configobj"):
installModule("configobj")
if not checkModule("gi"):
manualInstallNotify("gi", "http://python-gtk-3-tutorial.readthedocs.org/en/latest/install.html")
if moduleNeedsInstalling("gtk"):
installModule("PyGTK")
if moduleNeedsInstalling("PIL"):
installModule("Pillow")
if not checkModule("PyQt4"):
manualInstallNotify("PyQt4", "http://pyqt.sourceforge.net/Docs/PyQt4/installation.html")
if moduleNeedsInstalling("validate"):
installModule("validate")
if moduleNeedsInstalling("enum"):
installModule("enum34")
if moduleNeedsInstalling("datetime"):
installModule("DateTime")
if not args.get("omit") and not args.get("quiet") and not args.get("clean"):
print
if args.get("omit") not in ["app", "a"]:
if not args.get("quiet") and not args.get("clean"):
wireutils.color_print("Checking application dependencies for Perdyshot ...\n{bold}---------------------------------------------------{endc}\n")
checkApplication("convert", "ImageMagick", "http://www.imagemagick.org/script/binary-releases.php")
checkApplication("xclip", "xclip", "https://github.com/milki/xclip/blob/master/INSTALL")
except (KeyboardInterrupt, EOFError):
print