-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZ
executable file
·194 lines (133 loc) · 6.84 KB
/
Z
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env python
"""
Main running script for lazyrunner.
"""
# Import all the relevant stuff
import sys
from optparse import OptionParser, OptionGroup, IndentedHelpFormatter
import re
import os
from itertools import izip
import subprocess, logging
from treedict import TreeDict
from lazyrunner import manager, initialize, clean, creation
# A few global configuration options
preset_name_cache_file = '.preset_completions'
if __name__ == '__main__':
########################################
# Configure the action parser
usage = '\n%s [options] preset1, preset2, ...' % sys.argv[0]
description = "Queued Runner -- module based scientific programming."
formatter = IndentedHelpFormatter(max_help_position = 50, width=96)
parser = OptionParser(usage=usage, description=description, formatter=formatter)
##############################
# Now go through and add in all the names
running_options = OptionGroup(parser, "Run Options")
running_options.add_option('-d','--directory', dest="directory", type="string",
help="Use a base directory instead of the current directory.",
metavar="<directory>",
default=None)
running_options.add_option('-g', '--debug', dest='debug_mode', action="store_true",
help="Sets the logging level to debug, so all log.debug() "
"messages are printed; turns on compiler debug flags.",
default=False)
running_options.add_option('-v', '--verbose', dest='verbose_mode', action="store_true",
help="Turns on more detailed printing of lazyrunner actions and messages.",
default=False)
running_options.add_option('', '--no-compile', dest='no_compile', action="store_true",
help="Disable automatic recompiling of extension modules.",
default=False)
parser.add_option_group(running_options)
####################
# Cache options
cache_options = OptionGroup(parser, "Cache Options and Commands")
cache_options.add_option('', '--nocache', dest='no_cache', action="store_true",
help="Disable use of the disk cache.",
default=False)
cache_options.add_option('', '--cache-read-only', '--ro', dest="cache_read_only", action="store_true",
help="Make the cache read-only; useful for testing new modules.",
default=False)
cache_options.add_option('','--cache-directory', dest="cache_directory", type="string",
help="Use an alternate cache directory instead of the one defined "
"in conf.py.",
metavar="<directory>",
default=None)
parser.add_option_group(cache_options)
####################
# Creating new things
creation_options = OptionGroup(parser, "Creating / Initializing Options")
creation_options.add_option('', '--init', dest="init", action="store_true",
help="Initialize a new project in the current working directory.",
default=False)
creation_options.add_option('-f', '--force', dest="force", action="store_true",
help="Force operation to stop only under fatal errors.",
default=False)
creation_options.add_option('-m', '--new-module', dest="new_module", type="string",
help=
"Write a new processing module template file. The argument "
"is of the form '[dir[.subdir]].module'. For 'dir.ModName', a "
"template module named 'ModName' is created in 'dir/modname.py'.",
default = None, metavar="<Module Name>")
parser.add_option_group(creation_options)
####################
# Query options
query_options = OptionGroup(parser, "Querying and Information Options")
query_options.add_option('-l', '--list-presets', dest="list_presets", action="store_true",
help="List available presets and exit.",
default=False)
parser.add_option_group(query_options)
####################
# Cleaning options
cleaning_options = OptionGroup(parser, "Cleaning / Deletion Options")
cleaning_options.add_option('', '--clean', dest="clean", action="store_true",
help="Clean all intermediate compiling files.",
default=False)
parser.add_option_group(cleaning_options)
################################################################################
options, args = parser.parse_args()
####################
# See what's going on...
def print_use_help():
print "Usage: %s\n" % usage
print "\nUse --help to get a list of options."
sys.exit(1)
##################################################
# Put in common options; sanitize input options
opttree = TreeDict()
opttree.project_directory = options.directory if options.directory else os.getcwd()
opttree.debug_mode = options.debug_mode
opttree.verbose = options.verbose_mode
opttree.no_cache = options.no_cache
opttree.force = options.force
opttree.cache_read_only = options.cache_read_only
opttree.cache_directory = options.cache_directory
opttree.no_compile = options.no_compile
opttree.config_file = "conf"
presets = args
if options.list_presets:
m = RunManager(opttree)
print ""
print "Available presets:"
print "-"*50
print m.getPresetHelp()
print ""
m.updatePresetCompletionCache(preset_name_cache_file)
elif options.init:
import lazyrunner.creation as creation
creation.createInitial(opttree)
elif options.new_module is not None:
creation.createNewModule(opttree, options.new_module)
RunManager(opttree).updatePresetCompletionCache(preset_name_cache_file)
elif options.clean:
clean(opttree)
initialize(opttree)
manager().updatePresetCompletionCache(preset_name_cache_file)
else:
print ""
if len(args) == 0:
print "Warning: Running with no presets specified; use --help to get a list of options.\n"
initialize(opttree)
m = manager()
m.updatePresetCompletionCache(preset_name_cache_file)
m.getResults(None, presets)
print ""