From 9181e13af0d7400f20636525cf5879c2036c4119 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 14 Sep 2017 04:58:17 +0200 Subject: T388: nicer options handling and output. --- scripts/build-command-templates | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'scripts') diff --git a/scripts/build-command-templates b/scripts/build-command-templates index 6801defbb..6cfaa2bc1 100755 --- a/scripts/build-command-templates +++ b/scripts/build-command-templates @@ -22,36 +22,27 @@ import sys import os -import getopt +import argparse import copy import functools -import pprint - from lxml import etree as ET ## Get arguments -if len(sys.argv) < 4: - print("Usage: {0} ".format(sys.argv[0])) - sys.exit(1) - -input_file = sys.argv[1] -schema_file = sys.argv[2] -output_dir = sys.argv[3] +parser = argparse.ArgumentParser(description='Converts new-style XML interface definitions to old-style command templates') +parser.add_argument('--debug', help='Enable debug information output', action='store_true') +parser.add_argument('INPUT_FILE', type=str, help="XML interface definition file") +parser.add_argument('SCHEMA_FILE', type=str, help="RelaxNG schema file") +parser.add_argument('OUTPUT_DIR', type=str, help="Output directory") +args = parser.parse_args() -debug = False -try: - opts, args = getopt.getopt(sys.argv[4:], '', ['debug=', ]) - for opt, arg in opts: - if opt == '--debug': - if arg == "1": - debug = True -except getopt.GetoptError as err: - pass - +input_file = args.INPUT_FILE +schema_file = args.SCHEMA_FILE +output_dir = args.OUTPUT_DIR +debug = args.debug ## Load and validate the inputs @@ -176,7 +167,7 @@ def make_node_def(props): node_def += "end: sudo sh -c \"{0}\"\n".format(props["owner"]) if debug: - print("The content of node_def:", node_def) + print("The contents of the node.def file:\n", node_def) return node_def -- cgit v1.2.3