Commit 9d2b33b7 authored by Matthieu Muffato's avatar Matthieu Muffato Committed by ens-bwalts
Browse files

Use a named tuple to better organise the data

parent a370a19d
......@@ -16,6 +16,7 @@
# limitations under the License.
import collections
import sys
import eHive
......@@ -43,17 +44,18 @@ def do_build():
## And here we select the mode
WrapperMode = collections.namedtuple('WrapperMode', ['function', 'args'])
available_modes = {
'version' : (do_version, []),
'build' : (do_build, []),
'check_exists' : (do_check_exists, ['module_name']),
'run' : (do_run, ['module_name', 'fd_in', 'fd_out', 'debug'])
'version' : WrapperMode(do_version, []),
'build' : WrapperMode(do_build, []),
'check_exists' : WrapperMode(do_check_exists, ['module_name']),
'run' : WrapperMode(do_run, ['module_name', 'fd_in', 'fd_out', 'debug'])
}
def usage(msg):
error = "Command-line error: " + msg + "\nUsage: \n"
for (mode, (_, args)) in available_modes.items():
error += "\t" + " ".join([sys.argv[0], mode] + args) + "\n"
for (mode, impl) in available_modes.items():
error += "\t" + " ".join([sys.argv[0], mode] + impl.args) + "\n"
print(error, file=sys.stderr)
sys.exit(1)
......@@ -63,11 +65,11 @@ if len(sys.argv) == 1:
mode = sys.argv[1]
if mode not in available_modes:
usage('Unknown mode "{0}"'.format(mode))
impl = available_modes[mode]
if len(sys.argv)-2 < len(available_modes[mode][1]):
usage('Not enough arguments for mode "' + mode + '". Expecting: ' + ' '.join(available_modes[mode][1]))
if len(sys.argv)-2 > len(available_modes[mode][1]):
usage('Too many arguments for mode "' + mode + '". Expecting: ' + (' '.join(available_modes[mode][1]) if available_modes[mode][1] else '(none)'))
available_modes[mode][0]()
if len(sys.argv)-2 < len(impl.args):
usage('Not enough arguments for mode "' + mode + '". Expecting: ' + ' '.join(impl.args))
if len(sys.argv)-2 > len(impl.args):
usage('Too many arguments for mode "' + mode + '". Expecting: ' + (' '.join(impl.args) if impl.args else '(none)'))
impl.function()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment