summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Pinkava <j-pi@seznam.cz>2015-11-24 11:32:57 +0100
committerJiří Pinkava <j-pi@seznam.cz>2016-05-03 07:21:47 +0200
commitd6082662fdcf65e5fa2de83ddfda91c9dd9b2ed1 (patch)
treede1003ec8814e6151946e0c41af4dc5cf1df3629
parented99f139c22988d9c7b0cccd7e8da01407919460 (diff)
grcc: replace OptionParser by ArgumentParser
-rwxr-xr-xgr-utils/python/utils/grcc25
1 files changed, 11 insertions, 14 deletions
diff --git a/gr-utils/python/utils/grcc b/gr-utils/python/utils/grcc
index 82db5435db..776af799d3 100755
--- a/gr-utils/python/utils/grcc
+++ b/gr-utils/python/utils/grcc
@@ -22,7 +22,7 @@
import os
import sys
-from optparse import OptionParser
+from argparse import ArgumentParser
import warnings
warnings.simplefilter('ignore')
@@ -57,28 +57,25 @@ class GRCC:
def main():
- usage="%prog: [options] filename"
description = "Compiles a GRC file (.grc) into a GNU Radio Python program. The program is stored in ~/.grc_gnuradio by default, but this location can be changed with the -d option."
- parser = OptionParser(conflict_handler="resolve", usage=usage, description=description)
- parser.add_option("-d", "--directory", type="string", default='{0}/.grc_gnuradio/'.format(os.environ["HOME"]),
- help="Specify the directory to output the compile program [default=%default]")
- parser.add_option("-e", "--execute", action="store_true", default=False,
- help="Run the program after compiling [default=%default]")
- (options, args) = parser.parse_args ()
-
- if len(args) != 1:
- sys.stderr.write("Please specify a GRC file name to compile.\n")
- sys.exit(1)
+ parser = ArgumentParser(description=description)
+ parser.add_argument("-d", "--directory",
+ default='{0}/.grc_gnuradio/'.format(os.environ["HOME"]),
+ help="Specify the directory to output the compile program [default=%(default)s]")
+ parser.add_argument("-e", "--execute", action="store_true", default=False,
+ help="Run the program after compiling [default=%(default)s]")
+ parser.add_argument('grc_file', metavar="GRC_FILE", help=".grc file to compile")
+ args = parser.parse_args()
try:
- g = GRCC(args[0], options.directory + "/")
+ g = GRCC(args.grc_file, args.directory + "/")
except Exception as e:
sys.stderr.write(str(e) + "\n")
sys.stderr.write("Error during file compilation.\n")
sys.exit(1)
- if options.execute:
+ if args.execute:
g.exec_program()