summaryrefslogtreecommitdiff
path: root/gr-utils/python/utils
diff options
context:
space:
mode:
Diffstat (limited to 'gr-utils/python/utils')
-rwxr-xr-xgr-utils/python/utils/gr_modtool28
-rwxr-xr-xgr-utils/python/utils/gr_plot_char33
-rwxr-xr-xgr-utils/python/utils/gr_plot_const30
-rw-r--r--gr-utils/python/utils/gr_read_file_metadata20
-rwxr-xr-xgr-utils/python/utils/grcc25
-rw-r--r--gr-utils/python/utils/plot_data.py1
6 files changed, 65 insertions, 72 deletions
diff --git a/gr-utils/python/utils/gr_modtool b/gr-utils/python/utils/gr_modtool
index e714cf48e5..d9016840be 100755
--- a/gr-utils/python/utils/gr_modtool
+++ b/gr-utils/python/utils/gr_modtool
@@ -24,19 +24,27 @@
from gnuradio.modtool import *
+def setup_parser():
+ modules = get_modtool_modules(globals().values())
+ parser = ModTool.get_parser()
+ subparsers = parser.add_subparsers(title="Commands")
+ epilog = []
+ for module in modules:
+ subparser = subparsers.add_parser(module.name,
+ description=module.description)
+ module.setup_parser(subparser)
+ subparser.set_defaults(module=module)
+ epilog.append(" {:<22}{}".format(module.name, module.description))
+ parser.epilog = '\n'.join(epilog)
+ return parser
+
def main():
""" Here we go. Parse command, choose class and run. """
- cmd_dict = get_class_dict(globals().values())
- command = get_command_from_argv(cmd_dict.keys())
- if command is None:
- print 'Usage:' + Templates['usage']
- exit(2)
- modtool = cmd_dict[command]()
- try:
- (options, args) = modtool.parser.parse_args()
- modtool.setup(options, args)
- modtool.run()
+ parser = setup_parser()
+ args = parser.parse_args()
+ try:
+ args.module().run(args)
except ModToolException as err:
print >> sys.stderr, err
exit(1)
diff --git a/gr-utils/python/utils/gr_plot_char b/gr-utils/python/utils/gr_plot_char
index a2b93a63c6..ee644557bb 100755
--- a/gr-utils/python/utils/gr_plot_char
+++ b/gr-utils/python/utils/gr_plot_char
@@ -26,29 +26,26 @@ except ImportError:
print "Please install SciPy to run this script (http://www.scipy.org/)"
raise SystemExit, 1
-from optparse import OptionParser
+from argparse import ArgumentParser
from gnuradio.plot_data import plot_data
def main():
- usage="%prog: [options] input_filenames"
description = "Takes a GNU Radio byte/char binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples."
- parser = OptionParser(conflict_handler="resolve", usage=usage, description=description)
- parser.add_option("-B", "--block", type="int", default=1000,
- help="Specify the block size [default=%default]")
- parser.add_option("-s", "--start", type="int", default=0,
- help="Specify where to start in the file [default=%default]")
- parser.add_option("-R", "--sample-rate", type="float", default=1.0,
- help="Set the sampler rate of the data [default=%default]")
-
- (options, args) = parser.parse_args ()
- if len(args) < 1:
- parser.print_help()
- raise SystemExit, 1
- filenames = args
-
- datatype=scipy.int8
- dc = plot_data(datatype, filenames, options)
+ parser = ArgumentParser(conflict_handler="resolve", description=description)
+ parser.add_argument("-B", "--block", type=int, default=1000,
+ help="Specify the block size [default=%(default)r]")
+ parser.add_argument("-s", "--start", type=int, default=0,
+ help="Specify where to start in the file [default=%(default)r]")
+ parser.add_argument("-R", "--sample-rate", type=float, default=1.0,
+ help="Set the sampler rate of the data [default=%(default)r]")
+ parser.add_argument("files", metavar="FILE", nargs="+",
+ help="Input file with complex samples")
+
+ args = parser.parse_args()
+
+ datatype = scipy.int8
+ dc = plot_data(datatype, args.files, args)
if __name__ == "__main__":
try:
diff --git a/gr-utils/python/utils/gr_plot_const b/gr-utils/python/utils/gr_plot_const
index e2580dd58f..28f6a540da 100755
--- a/gr-utils/python/utils/gr_plot_const
+++ b/gr-utils/python/utils/gr_plot_const
@@ -33,7 +33,7 @@ except ImportError:
print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)"
raise SystemExit, 1
-from optparse import OptionParser
+from argparse import ArgumentParser
class draw_constellation:
def __init__(self, filename, options):
@@ -221,24 +221,20 @@ def find(item_in, list_search):
def main():
- usage="%prog: [options] input_filename"
description = "Takes a GNU Radio complex binary file and displays the I&Q data versus time and the constellation plot (I vs. Q). You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples."
- parser = OptionParser(conflict_handler="resolve", usage=usage, description=description)
- parser.add_option("-B", "--block", type="int", default=1000,
- help="Specify the block size [default=%default]")
- parser.add_option("-s", "--start", type="int", default=0,
- help="Specify where to start in the file [default=%default]")
- parser.add_option("-R", "--sample-rate", type="float", default=1.0,
- help="Set the sampler rate of the data [default=%default]")
-
- (options, args) = parser.parse_args ()
- if len(args) != 1:
- parser.print_help()
- raise SystemExit, 1
- filename = args[0]
-
- dc = draw_constellation(filename, options)
+ parser = ArgumentParser(conflict_handler="resolve", description=description)
+ parser.add_argument("-B", "--block", type=int, default=1000,
+ help="Specify the block size [default=%(default)r]")
+ parser.add_argument("-s", "--start", type=int, default=0,
+ help="Specify where to start in the file [default=%(default)r]")
+ parser.add_argument("-R", "--sample-rate", type=float, default=1.0,
+ help="Set the sampler rate of the data [default=%(default)r]")
+ parser.add_argument("file", metavar="FILE", nargs=1,
+ help="Input file with complex samples")
+ args = parser.parse_args()
+
+ dc = draw_constellation(args.file[0], args)
if __name__ == "__main__":
try:
diff --git a/gr-utils/python/utils/gr_read_file_metadata b/gr-utils/python/utils/gr_read_file_metadata
index 429b38310f..2a907687d6 100644
--- a/gr-utils/python/utils/gr_read_file_metadata
+++ b/gr-utils/python/utils/gr_read_file_metadata
@@ -21,7 +21,7 @@
#
import sys
-from optparse import OptionParser
+from argparse import ArgumentParser
import pmt
from gnuradio.blocks import parse_file_metadata
@@ -69,19 +69,15 @@ def main(filename, detached=False):
handle.seek(nread, 0)
print "\n\n"
+
if __name__ == "__main__":
- usage="%prog: [options] filename"
description = "Read in a GNU Radio file with meta data, extracts the header and prints it."
- parser = OptionParser(conflict_handler="resolve",
- usage=usage, description=description)
- parser.add_option("-D", "--detached", action="store_true", default=False,
+ parser = ArgumentParser(conflict_handler="resolve", description=description)
+ parser.add_argument("-D", "--detached", action="store_true",
help="Used if header is detached.")
- (options, args) = parser.parse_args ()
-
- if(len(args) < 1):
- sys.stderr.write("No filename given\n")
- sys.exit(1)
+ parser.add_argument("file", metavar="FILE", nargs=1,
+ help="Input file");
+ args = parser.parse_args()
- filename = args[0]
- main(filename, options.detached)
+ main(args.file[0], args.detached)
diff --git a/gr-utils/python/utils/grcc b/gr-utils/python/utils/grcc
index b9bd1551b9..e93802f051 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')
@@ -63,28 +63,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()
diff --git a/gr-utils/python/utils/plot_data.py b/gr-utils/python/utils/plot_data.py
index 2ae3b1d5b3..7d80c714fe 100644
--- a/gr-utils/python/utils/plot_data.py
+++ b/gr-utils/python/utils/plot_data.py
@@ -34,7 +34,6 @@ except ImportError:
print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)"
raise SystemExit, 1
-from optparse import OptionParser
class plot_data:
def __init__(self, datatype, filenames, options):