Improve argument parsing.

This commit is contained in:
Merlijn Wajer 2013-05-10 17:33:25 +02:00
parent a5ec64431d
commit 1022db5eaf
2 changed files with 19 additions and 13 deletions

View File

@ -16,23 +16,32 @@ import optparse
parser = optparse.OptionParser(description='Create input devices. '
'TODO')
parser.add_option('-c', '--config', type=str, action='append',
default=[],
help='Merge configuration file with default '
'configuration (allowed to be used multiple times)')
#parser.add_option('-c', '--config', type=str, action='append',
# default=[],
# help='Merge configuration file with default '
# 'configuration (allowed to be used multiple times)')
parser.add_option('-C', '--compat', action='store_true',
help='Enable compatibility mode; for Python < 2.7')
args, _ = parser.parse_args()
args, cfg = parser.parse_args()
# Unpickle from stdin ; currently this is the default and only way
f = pickle.Unpickler(sys.stdin)
conf = f.load()
print conf
for path in args.config:
for path in cfg:
config = imp.load_source('', path).config
conf.update(config)
# XXX: We cannot just use update; as it will override everything in say EV_TE
for k, v in config.iteritems():
if k in conf:
conf[k].update(v)
else:
conf[k] = v
#conf.update(config)
print conf
m = KeyMapper(conf)

View File

@ -14,22 +14,19 @@ parser = optparse.OptionParser(description='Read input devices. '
'TODO')
parser.add_option('-D', '--dump', action='store_false',
default=True, help='Dump will marshall all the events to stdout')
parser.add_option('-i', '--input-file', action='append',
type=str, default=[],
help='Read events from this input device')
parser.add_option('-C', '--compat', action='store_true',
help='Enable compatibility mode; for Python < 2.7')
args, _ = parser.parse_args()
args, input_file = parser.parse_args()
if len(args.input_file) == 0:
if len(input_file) == 0:
parser.print_help()
exit(0)
# TODO: Support multiple input files + epoll; InputDevices?
f = InputDevice(args.input_file[0])
f = InputDevice(input_file[0])
config = parse_conf(f)
m = KeyMapper(config)