aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-05-19 11:46:52 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-07-03 16:08:53 +0200
commitb97d32fd322b8c6c543ede58813556d0b01f31c8 (patch)
tree90acd23ac9c6c0b767f800b32d9845f2dac549c0
parentac2a3802fa25d5f4832b1e2595534f7379c6c924 (diff)
downloadexternal_libqmi-b97d32fd322b8c6c543ede58813556d0b01f31c8.zip
external_libqmi-b97d32fd322b8c6c543ede58813556d0b01f31c8.tar.gz
external_libqmi-b97d32fd322b8c6c543ede58813556d0b01f31c8.tar.bz2
qmi-codegen: pass input and output files with command line options
-rwxr-xr-xbuild-aux/qmi-codegen/qmi-codegen70
-rw-r--r--src/Makefile.am4
2 files changed, 44 insertions, 30 deletions
diff --git a/build-aux/qmi-codegen/qmi-codegen b/build-aux/qmi-codegen/qmi-codegen
index aa113a8..6c5b168 100755
--- a/build-aux/qmi-codegen/qmi-codegen
+++ b/build-aux/qmi-codegen/qmi-codegen
@@ -20,46 +20,60 @@
import os
import sys
+import optparse
import json
from Client import Client
from MessageList import MessageList
import utils
-# Setup inputs
-if len(sys.argv) != 3:
- print "Usage: qmi-codegen <path to database.json> <path to output>"
- sys.exit(1)
+def codegen_main():
+ # Input arguments
+ arg_parser = optparse.OptionParser('%prog [options]')
+ arg_parser.add_option('', '--input', metavar='JSONFILE',
+ help='Input JSON-formatted database')
+ arg_parser.add_option('', '--output', metavar='OUTFILES',
+ help='Generate C code in OUTFILES.[ch]')
+ (opts, args) = arg_parser.parse_args();
-database_file_path = sys.argv[1]
-base_output_path = sys.argv[2]
+ if opts.input == None:
+ raise RuntimeError('Input JSON file is mandatory')
+ if opts.output == None:
+ raise RuntimeError('Output file pattern is mandatory')
-output_file_c = open(base_output_path + ".c", 'w')
-output_file_h = open(base_output_path + ".h", 'w')
+ # Prepare output file names
+ output_file_c = open(opts.output + ".c", 'w')
+ output_file_h = open(opts.output + ".h", 'w')
-# Load database file contents
-database_file = open(sys.argv[1])
-database_file_contents = database_file.read()
-database_file.close()
+ # Load database file contents
+ database_file = open(opts.input)
+ database_file_contents = database_file.read()
+ database_file.close()
-# Add common stuff to the output files
-utils.add_copyright(output_file_c);
-utils.add_copyright(output_file_h);
-utils.add_header_start(output_file_h, os.path.basename(base_output_path))
-utils.add_source_start(output_file_c, os.path.basename(base_output_path))
+ # Add common stuff to the output files
+ utils.add_copyright(output_file_c);
+ utils.add_copyright(output_file_h);
+ utils.add_header_start(output_file_h, os.path.basename(opts.output))
+ utils.add_source_start(output_file_c, os.path.basename(opts.output))
-# Get our message collection
-object_list_json = json.loads(database_file_contents)
-message_list = MessageList(object_list_json)
+ # Get our message collection
+ object_list_json = json.loads(database_file_contents)
+ message_list = MessageList(object_list_json)
-# Emit the message creation/parsing code
-message_list.emit(output_file_h, output_file_c)
+ # Emit the message creation/parsing code
+ message_list.emit(output_file_h, output_file_c)
-# Build our own client
-client = Client(object_list_json)
-client.emit(output_file_h, output_file_c, message_list)
+ # Build our own client
+ client = Client(object_list_json)
+ client.emit(output_file_h, output_file_c, message_list)
-utils.add_header_stop(output_file_h, os.path.basename(base_output_path))
+ utils.add_header_stop(output_file_h, os.path.basename(opts.output))
-output_file_c.close()
-output_file_h.close()
+ output_file_c.close()
+ output_file_h.close()
+
+ sys.exit(0)
+
+
+if __name__ == "__main__":
+ codegen_main()
diff --git a/src/Makefile.am b/src/Makefile.am
index 2fa6ba3..e3d4ae7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -40,8 +40,8 @@ qmi-enum-types.c: $(ENUMS) qmi-enum-types.h $(top_srcdir)/build-aux/templates/qm
# CTL service
qmi-ctl.stamp: $(top_srcdir)/data/qmi-service-ctl.json $(top_srcdir)/build-aux/qmi-codegen/*.py $(top_srcdir)/build-aux/qmi-codegen/qmi-codegen
$(AM_V_GEN) $(top_srcdir)/build-aux/qmi-codegen/qmi-codegen \
- $(top_srcdir)/data/qmi-service-ctl.json \
- qmi-ctl && \
+ --input $(top_srcdir)/data/qmi-service-ctl.json \
+ --output qmi-ctl && \
touch $@
# Additional dependencies