5
5
6
6
import os .path
7
7
import sys
8
- import optparse
8
+ import argparse
9
9
import collections
10
10
import functools
11
11
import re
17
17
18
18
import pdl
19
19
20
+ try :
21
+ unicode
22
+ except NameError :
23
+ # Define unicode for Py3
24
+ def unicode (s , * _ ):
25
+ return s
26
+
20
27
# Path handling for libraries and templates
21
28
# Paths have to be normalized because Jinja uses the exact template path to
22
29
# determine the hash used in the cache filename, and we need a pre-caching step
@@ -53,27 +60,16 @@ def init_defaults(config_tuple, path, defaults):
53
60
return collections .namedtuple ('X' , keys )(* values )
54
61
55
62
try :
56
- cmdline_parser = optparse . OptionParser ()
57
- cmdline_parser .add_option ("--output_base" )
58
- cmdline_parser .add_option ("--jinja_dir" )
59
- cmdline_parser .add_option ("--config" )
60
- cmdline_parser .add_option ("--config_value" , action = "append" , type = "string " )
61
- arg_options , _ = cmdline_parser .parse_args ()
63
+ cmdline_parser = argparse . ArgumentParser ()
64
+ cmdline_parser .add_argument ("--output_base" , type = unicode , required = True )
65
+ cmdline_parser .add_argument ("--jinja_dir" , type = unicode , required = True )
66
+ cmdline_parser .add_argument ("--config" , type = unicode , required = True )
67
+ cmdline_parser .add_argument ("--config_value" , default = [], action = "append " )
68
+ arg_options = cmdline_parser .parse_args ()
62
69
jinja_dir = arg_options .jinja_dir
63
- if not jinja_dir :
64
- raise Exception ("jinja directory must be specified" )
65
- jinja_dir = jinja_dir .decode ('utf8' )
66
70
output_base = arg_options .output_base
67
- if not output_base :
68
- raise Exception ("Base output directory must be specified" )
69
- output_base = output_base .decode ('utf8' )
70
71
config_file = arg_options .config
71
- if not config_file :
72
- raise Exception ("Config file name must be specified" )
73
- config_file = config_file .decode ('utf8' )
74
72
config_values = arg_options .config_value
75
- if not config_values :
76
- config_values = []
77
73
except Exception :
78
74
# Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html
79
75
exc = sys .exc_info ()[1 ]
@@ -631,7 +627,7 @@ def main():
631
627
"Array_h.template" ,
632
628
"DispatcherBase_h.template" ,
633
629
"Parser_h.template" ,
634
- "CBOR_h .template" ,
630
+ "encoding_h .template" ,
635
631
]
636
632
637
633
protocol_cpp_templates = [
@@ -641,7 +637,7 @@ def main():
641
637
"Object_cpp.template" ,
642
638
"DispatcherBase_cpp.template" ,
643
639
"Parser_cpp.template" ,
644
- "CBOR_cpp .template" ,
640
+ "encoding_cpp .template" ,
645
641
]
646
642
647
643
forward_h_templates = [
0 commit comments