Skip to content

Commit

Permalink
refactoring script for own argument parser and fixing empty arguments f…
Browse files Browse the repository at this point in the history
…ix #15499
  • Loading branch information
behrisch committed Jan 4, 2025
1 parent 4b14325 commit 7acbc9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
25 changes: 8 additions & 17 deletions tools/output/generateMeanDataDefinitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import os
import logging
import optparse
import sys

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
Expand Down Expand Up @@ -112,16 +111,13 @@ def get_detector_output_type(provided_options):

logging.basicConfig()

option_parser = optparse.OptionParser()
option_parser.add_option("-d", "--detector-file",
help="Input detector FILE",
dest="detector_file",
type="string")
option_parser.add_option("-t", "--detector-type",
option_parser = sumolib.options.ArgumentParser()
option_parser.add_option("-d", "--detector-file", required=True,
help="Input detector FILE. Mandatory.")
option_parser.add_option("-t", "--detector-type", required=True,
choices=('e1', 'e2', 'e3'),
help="Type of detectors defined in the input. "
"Allowed values: e1, e2, e3. Mandatory.",
dest="detector_type",
type="string")
"Allowed values: e1, e2, e3. Mandatory.")
option_parser.add_option("-f", "--frequency",
help="The aggregation period the values the "
"detector collects shall be summed up. "
Expand All @@ -130,8 +126,6 @@ def get_detector_output_type(provided_options):
"the default. If specified, must be a "
"positive integer (seconds) representing "
"time range length.",
dest="frequency",
type="string",
default="")
option_parser.add_option("-l", "--lane-based-dump",
help="Generate lane based dump instead of "
Expand All @@ -151,15 +145,12 @@ def get_detector_output_type(provided_options):
"build from the detector's ID and this "
"suffix, with '.xml' extension. Defaults "
"to -results-aggregated.",
dest="output_suffix",
default="-results-aggregated")
option_parser.add_option("-o", "--output",
help="Output to write the mean data definition "
"to. Defaults to stdout.",
dest="output",
type="string")
"to. Defaults to stdout.")

(options, args) = option_parser.parse_args()
options = option_parser.parse_args()

output = sys.stdout
if options.output is not None:
Expand Down
6 changes: 2 additions & 4 deletions tools/sumolib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,9 @@ def parse_known_args(self, args=None, namespace=None, check_unknown=False):
config_args += value.split()
elif option.name in multi_value:
config_args += ["--" + option.name] + value.split()
elif value:
# permit negative values in cfg files
config_args += ["--" + option.name + "=" + value]
else:
config_args += ["--" + option.name]
# permit negative values and empty strings in cfg files
config_args += ["--" + option.name + "=" + value]
combined_args = args + config_args + [p for p in pos_args if p is not None]
namespace, unknown_args = argparse.ArgumentParser.parse_known_args(
self, args=combined_args, namespace=namespace)
Expand Down

0 comments on commit 7acbc9f

Please sign in to comment.