This repository has been archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
snoing.py
executable file
·169 lines (163 loc) · 8.66 KB
/
snoing.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
#!/usr/bin/env python
#
# snoing
#
# Entry script decides what to do
#
# Author P G Jones - 12/05/2012 <[email protected]> : First revision
# Author P G Jones - 23/06/2012 <[email protected]> : Major refactor of snoing.
####################################################################################################
import sys
try:
a= 1
import packagemanager
except ImportError:
print "Error: Source the snoing environment file."
sys.exit(1)
import optparse
import textlogger
import installmode
import snoing_exceptions
import system
import os
import pickle
def print_error_message():
"""Print a standard error message if snoing fails."""
print "Snoing has failed, please consult the above error messages or the snoing.log file."
print "More help available in the snoplus companion."
sys.exit(1)
if __name__ == "__main__":
default_file_path = os.path.join(os.path.dirname(__file__), "settings.pkl")
if os.path.isfile(default_file_path):
default_file = open(default_file_path, "r")
defaults = pickle.load(default_file)
default_file.close()
try:
a = defaults['cache_path']
except KeyError, e:
defaults = {"cache_path" : defaults['cache'], "install_path" : defaults['install']}
else: # No defaults to load, thus create
defaults = {"cache_path" : "cache", "install_path" : "install"}
# First build the options and parse the calling command
parser = optparse.OptionParser(usage = "usage: %prog [options] [package]", version="%prog 2.0")
parser.add_option("-c", "--cache-path", type="string", help="Cache path.",
default=defaults["cache_path"])
parser.add_option("-i", "--install-path", type="string", help="Install path.",
default=defaults["install_path"])
parser.add_option("-v", "--verbose", action="store_true", help="Verbose Install?",
default=False)
parser.add_option("-l", "--list", action="store_true",
help="List packages, without installing anything.")
parser.add_option("-a", "--all", action="store_true", help="All packages?")
parser.add_option("-k", "--clean", action="store_true", help="Clean temporary files.")
parser.add_option("--curl-arguments", "--Ac", type="string", help=optparse.SUPPRESS_HELP)
parser.add_option("--root-arguments", "--Ar", type="string", help=optparse.SUPPRESS_HELP)
parser.add_option("--geant4-arguments", "--Ag", type="string", help=optparse.SUPPRESS_HELP)
parser.add_option("--xrootd-arguments", "--Ax", type="string", help=optparse.SUPPRESS_HELP)
installerGroup = optparse.OptionGroup(parser, "Optional Install modes",
("Default snoing action is to install non graphically, i.e."
" no viewer. This can be changed with the -g option."))
installerGroup.add_option("-g", "--graphical", action="store_true", help="Graphical install?",
default=False)
installerGroup.add_option("-x", "--grid", action="store_true", help="Grid install (NO X11)?",
default=False)
parser.add_option_group(installerGroup)
actionGroup = optparse.OptionGroup(parser, "Optional Actions",
("Default snoing action is to install the specified package,"
" which defaults to rat-dev."))
actionGroup.add_option("-q", "--query", action="store_true", help="Query Package Status?")
actionGroup.add_option("-r", "--remove", action="store_true", help="Remove the package?")
actionGroup.add_option("-R", "--force-remove", action="store_true", help=optparse.SUPPRESS_HELP,
default=False)
actionGroup.add_option("-d", "--dependency", action="store_true", help="Install dependencies only?")
actionGroup.add_option("-p", "--progress", "--update", action="store_true", help="Progress/update the package?")
parser.add_option_group(actionGroup)
githubGroup = optparse.OptionGroup(parser, "Github authentication Options",
"Supply a username or a github token, not both.")
githubGroup.add_option("-u", "--username", type="string", help="Github username")
githubGroup.add_option("-t", "--token", type="string", help="Github token")
parser.add_option_group(githubGroup)
(options, args) = parser.parse_args()
# Dump the new defaults
defaults["cache_path"] = options.cache_path
defaults["install_path"] = options.install_path
default_file = open(default_file_path, "w")
pickle.dump(defaults, default_file)
default_file.close()
# Now create the logger, direct logging to snoing.log file
logger = textlogger.TextLogger(os.path.join(os.path.dirname(__file__), "snoing.log"), options.verbose)
# Now create the system
if options.grid and options.graphical:
print_error_message()
elif options.grid:
install_mode = installmode.Grid
elif options.graphical:
logger.error("The graphical mode `-g` is obsolete, please reinstall your software without it.")
install_mode = installmode.Graphical
else:
install_mode = installmode.Normal
# Sort out the extra arguments
opt_args = {"root":[],"geant4":[],"curl":[],"xrootd":[]}
if options.root_arguments is not None:
opt_args["root"] = options.root_arguments.split()
if options.geant4_arguments is not None:
opt_args["geant4"] = options.geant4_arguments.split()
if options.curl_arguments is not None:
opt_args["curl"] = options.curl_arguments.split()
if options.xrootd_arguments is not None:
opt_args["xrootd"] = options.xrootd_arguments.split()
try:
install_system = system.System(logger, options.cache_path, options.install_path, install_mode, opt_args)
except snoing_exceptions.InstallModeException, e:
print e.args[0], "The existing installation is ", installmode.Text[e.SystemMode], ". You've requested the installation to be ", installmode.Text[e.CommandMode]
print "You can install to a new path using the -i option or delete the existing installation and start again."
print_error_message()
except snoing_exceptions.SystemException, e:
print e.args[0], ":", e.Details
print_error_message()
if options.clean:
install_system.clean_cache()
# Now create the package manage and populate it
package_manager = packagemanager.PackageManager(install_system, logger)
package_manager.register_packages(os.path.join(os.path.dirname(__file__), "versions"))
package_manager.authenticate(options.username, options.token)
# Default action is to assume installing, check for other actions
try:
if options.list:
pass
elif options.all: # Wish to act on all packages
if options.query: # Nothing todo, done automatically
pass
elif options.remove: # Wish to remove all packages
shutil.rmtree(install_system.get_install_path())
elif options.dependency: # Doesn't make sense
Log.warn("Input options don't make sense.")
PrintErrorMessage()
elif options.progress: # Update all installed
package_manager.update_all()
else: # Wish to install all
package_manager.install_all()
else: # Only act on one package
if options.grid == False: # Default local package
package_name = "rat-dev"
else: # Default grid package
package_name = "rat-4.5.0"
if len(args) != 0:
package_name = args[0]
if options.query: # Wish to query the package
logger.set_state("Checking package %s install status" % package_name)
if package_manager.check_installed(package_name):
logger.package_installed(package_name)
else:
logger.error(package_name + " is not installed")
elif options.remove or options.force_remove: # Wish to remove the package
package_manager.remove_package( package_name, options.force_remove )
elif options.dependency: # Wish to install only the dependencies
package_manager.install_package_dependencies( package_name )
elif options.progress: # Wish to update the package
package_manager.update_package( package_name )
else: # Wish to install the package
package_manager.install_package( package_name )
except snoing_exceptions.PackageException, e:
print e.Package, ":", e
print_error_message()