Message ID | 20230613180828.1235964-1-ashelat@redhat.com |
---|---|
State | New |
Headers | show |
Series | rteval-cmd: If no kernel version is provided to -S/--source-download, download default kernel version | expand |
On Tue, 13 Jun 2023, Anubhav Shelat wrote: > Previously, the usuage was "./rteval-cmd -S [KERNEL_VERSION]", and > rteval-cmd would throw an error if no kernel version was provided. > Now, rteval-cmd will download the default kernel version, as specified > in rteval/modules/loads/kcompile.py. > > Signed-off-by: Anubhav Shelat <ashelat@redhat.com> > --- > rteval-cmd | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/rteval-cmd b/rteval-cmd > index cf9326e7dfdd..cbba9cd2e451 100755 > --- a/rteval-cmd > +++ b/rteval-cmd > @@ -168,11 +168,13 @@ def parse_options(cfg, parser, cmdargs): > help='print rteval version and exit') > # if the -S/--source-download option doesn't include the version, set version to default > ind = None > - if sys.argv.count("-S") > 0: ind = sys.argv.index("-S") > - elif sys.argv.count("--source-download") > 0: ind = sys.argv.index("--source-download") > + if sys.argv.count("-S") > 0: > + ind = sys.argv.index("-S") > + elif sys.argv.count("--source-download") > 0: > + ind = sys.argv.index("--source-download") > if ind != None: > - if ind+1 == len(sys.argv): > - sys.argv.insert(ind+1, ModuleParameters()["source"]["default"].strip(".tar.xz")) > + if ind+1 == len(sys.argv): > + sys.argv.insert(ind+1, ModuleParameters()["source"]["default"].replace(".tar.xz", "")) > cmdargs.append(sys.argv[ind+1]) > > parser.add_option("-S", "--source-download", dest="rteval___srcdownload", > -- > 2.31.1 > > This patch works and does something that I would like to have. However the point of parsers like optparse and argparse are to hide sys.argv kind of details. I am wondering if there is something you can do with nargs in order to make this work in a cleaner fashion. I know you are working on converting deprecated optparse to argparse, so I would suggest that instead of fixing this here, finish your argparse work, and then try to reimplement this on top of that once it is accepted upstream. Thanks John
diff --git a/rteval-cmd b/rteval-cmd index cf9326e7dfdd..cbba9cd2e451 100755 --- a/rteval-cmd +++ b/rteval-cmd @@ -168,11 +168,13 @@ def parse_options(cfg, parser, cmdargs): help='print rteval version and exit') # if the -S/--source-download option doesn't include the version, set version to default ind = None - if sys.argv.count("-S") > 0: ind = sys.argv.index("-S") - elif sys.argv.count("--source-download") > 0: ind = sys.argv.index("--source-download") + if sys.argv.count("-S") > 0: + ind = sys.argv.index("-S") + elif sys.argv.count("--source-download") > 0: + ind = sys.argv.index("--source-download") if ind != None: - if ind+1 == len(sys.argv): - sys.argv.insert(ind+1, ModuleParameters()["source"]["default"].strip(".tar.xz")) + if ind+1 == len(sys.argv): + sys.argv.insert(ind+1, ModuleParameters()["source"]["default"].replace(".tar.xz", "")) cmdargs.append(sys.argv[ind+1]) parser.add_option("-S", "--source-download", dest="rteval___srcdownload",
Previously, the usuage was "./rteval-cmd -S [KERNEL_VERSION]", and rteval-cmd would throw an error if no kernel version was provided. Now, rteval-cmd will download the default kernel version, as specified in rteval/modules/loads/kcompile.py. Signed-off-by: Anubhav Shelat <ashelat@redhat.com> --- rteval-cmd | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)