diff options
-rw-r--r-- | README.hacking | 60 | ||||
-rwxr-xr-x | docs/doxygen/other/doxypy.py | 56 | ||||
-rwxr-xr-x | dtools/bin/update_fsf_address | 26 | ||||
-rw-r--r-- | gr-audio/doc/audio.dox | 8 |
4 files changed, 72 insertions, 78 deletions
diff --git a/README.hacking b/README.hacking index 2d0a1c395f..0b5bf6d0c3 100644 --- a/README.hacking +++ b/README.hacking @@ -120,8 +120,8 @@ http://gnuradio.org/redmine/projects/gnuradio/wiki/Coding_guide_impl#Unit-testin When writing programs that are executable from the command line, please follow these guidelines for command line argument names (short and long) and types of the arguments. We list them below using the -Python optparse syntax. In general, the default value should be coded -into the help string using the "... [default=%default]" syntax. +Python argparse syntax. In general, the default value should be coded +into the help string using the "... [default=%(default)r]" syntax. ** Mandatory options by gr::block @@ -132,7 +132,7 @@ option parsing will automatically be set up for you. Any program using an audio source shall include: - add_option("-I", "--audio-input", type="string", default="", + add_argument("-I", "--audio-input", default="", help="pcm input device name. E.g., hw:0,0 or /dev/dsp") The default must be "". This allows an audio module-dependent default @@ -141,7 +141,7 @@ to be specified in the user preferences file. *** Audio sink - add_option("-O", "--audio-output", type="string", default="", + add_argument("-O", "--audio-output", default="", help="pcm output device name. E.g., hw:0,0 or /dev/dsp") The default must be "". This allows an audio module-dependent default @@ -162,69 +162,69 @@ following parameters, please use these options to specify them: To specify a frequency (typically an RF center frequency) use: - add_option("-f", "--freq", type="eng_float", default=<your-default-here>, - help="set frequency to FREQ [default=%default]") + add_argument("-f", "--freq", type=eng_float, default=<your-default-here>, + help="set frequency to FREQ [default=%(default)r]") To specify a decimation factor use: - add_option("-d", "--decim", type="intx", default=<your-default-here>, - help="set decimation rate to DECIM [default=%default]") + add_argument("-d", "--decim", type=intx, default=<your-default-here>, + help="set decimation rate to DECIM [default=%(default)r]") To specify an interpolation factor use: - add_option("-i", "--interp", type="intx", default=<your-default-here>, - help="set interpolation rate to INTERP [default=%default]") + add_argument("-i", "--interp", type=intx, default=<your-default-here>, + help="set interpolation rate to INTERP [default=%(default)r]") To specify a gain setting use: - add_option("-g", "--gain", type="eng_float", default=<your-default-here>, - help="set gain in dB [default=%default]") + add_argument("-g", "--gain", type=eng_float, default=<your-default-here>, + help="set gain in dB [default=%(default)r]") If your application specifies both a tx and an rx gain, use: - add_option("", "--rx-gain", type="eng_float", default=<your-default-here>, - help="set receive gain in dB [default=%default]") + add_argument("--rx-gain", type=eng_float, default=<your-default-here>, + help="set receive gain in dB [default=%(default)r]") - add_option("", "--tx-gain", type="eng_float", default=<your-default-here>, - help="set transmit gain in dB [default=%default]") + add_argument("--tx-gain", type=eng_float, default=<your-default-here>, + help="set transmit gain in dB [default=%(default)r]") To specify the number of channels of something use: - add_option("-n", "--nchannels", type="intx", default=1, - help="specify number of channels [default=%default]") + add_argument("-n", "--nchannels", type=intx, default=1, + help="specify number of channels [default=%(default)r]") To specify an output filename use: - add_option("-o", "--output-filename", type="string", default=<your-default-here>, - help="specify output-filename [default=%default]") + add_argument("-o", "--output-filename", default=<your-default-here>, + help="specify output-filename [default=%(default)r]") To specify a rate use: - add_option("-r", "--bit-rate", type="eng_float", default=<your-default-here>, - help="specify bit-rate [default=%default]") + add_argument("-r", "--bit-rate", type=eng_float, default=<your-default-here>, + help="specify bit-rate [default=%(default)r]") or - add_option("-r", "--sample-rate", type="eng_float", default=<your-default-here>, - help="specify sample-rate [default=%default]") + add_argument("-r", "--sample-rate", type=eng_float, default=<your-default-here>, + help="specify sample-rate [default=%(default)r]") If your application has a verbose option, use: - add_option('-v', '--verbose', action="store_true", default=False, - help="verbose output") + add_argument('-v', '--verbose', action="store_true", + help="verbose output") If your application allows the user to specify the "fast USB" options, use: - add_option("", "--fusb-block-size", type="intx", default=0, - help="specify fast USB block size [default=%default]") + add_argument("--fusb-block-size", type=intx, default=0, + help="specify fast USB block size [default=%(default)r]") - add_option("", "--fusb-nblocks", type="intx", default=0, - help="specify number of fast USB blocks [default=%default]") + add_argument("--fusb-nblocks", type=intx, default=0, + help="specify number of fast USB blocks [default=%(default)r]") diff --git a/docs/doxygen/other/doxypy.py b/docs/doxygen/other/doxypy.py index 15d3e0824d..a9af32ab53 100755 --- a/docs/doxygen/other/doxypy.py +++ b/docs/doxygen/other/doxypy.py @@ -15,7 +15,7 @@ add the following lines to your Doxyfile: INPUT_FILTER = "python /path/to/doxypy.py" """ -__version__ = "0.4.1" +__version__ = "0.4.2" __date__ = "5th December 2008" __website__ = "http://code.foosel.org/doxypy" @@ -42,7 +42,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import sys import re -from optparse import OptionParser, OptionGroup +from argparse import ArgumentParser class FSM(object): """Implements a finite state machine. @@ -85,7 +85,7 @@ class FSM(object): self.current_state = to_state self.current_input = input self.current_transition = transition - if options.debug: + if args.debug: print >>sys.stderr, "# FSM: executing (%s -> %s) for line '%s'" % (from_state, to_state, input) callback(match) return @@ -179,7 +179,7 @@ class Doxypy(object): def __closeComment(self): """Appends any open comment block and triggering block to the output.""" - if options.autobrief: + if args.autobrief: if len(self.comment) == 1 \ or (len(self.comment) > 2 and self.comment[1].strip() == ''): self.comment[0] = self.__docstringSummaryToBrief(self.comment[0]) @@ -207,7 +207,7 @@ class Doxypy(object): """Flushes the current outputbuffer to the outstream.""" if self.output: try: - if options.debug: + if args.debug: print >>sys.stderr, "# OUTPUT: ", self.output print >>self.outstream, "\n".join(self.output) self.outstream.flush() @@ -227,7 +227,7 @@ class Doxypy(object): Closes the current commentblock and starts a new comment search. """ - if options.debug: + if args.debug: print >>sys.stderr, "# CALLBACK: resetCommentSearch" self.__closeComment() self.startCommentSearch(match) @@ -238,7 +238,7 @@ class Doxypy(object): Saves the triggering line, resets the current comment and saves the current indentation. """ - if options.debug: + if args.debug: print >>sys.stderr, "# CALLBACK: startCommentSearch" self.defclass = [self.fsm.current_input] self.comment = [] @@ -250,7 +250,7 @@ class Doxypy(object): Closes the current commentblock, resets the triggering line and appends the current line to the output. """ - if options.debug: + if args.debug: print >>sys.stderr, "# CALLBACK: stopCommentSearch" self.__closeComment() @@ -262,7 +262,7 @@ class Doxypy(object): Closes the open comment block, resets it and appends the current line. """ - if options.debug: + if args.debug: print >>sys.stderr, "# CALLBACK: appendFileheadLine" self.__closeComment() self.comment = [] @@ -274,7 +274,7 @@ class Doxypy(object): The comment delimiter is removed from multiline start and ends as well as singleline comments. """ - if options.debug: + if args.debug: print >>sys.stderr, "# CALLBACK: appendCommentLine" (from_state, to_state, condition, callback) = self.fsm.current_transition @@ -311,13 +311,13 @@ class Doxypy(object): def appendNormalLine(self, match): """Appends a line to the output.""" - if options.debug: + if args.debug: print >>sys.stderr, "# CALLBACK: appendNormalLine" self.output.append(self.fsm.current_input) def appendDefclassLine(self, match): """Appends a line to the triggering block.""" - if options.debug: + if args.debug: print >>sys.stderr, "# CALLBACK: appendDefclassLine" self.defclass.append(self.fsm.current_input) @@ -378,37 +378,31 @@ class Doxypy(object): self.fsm.makeTransition(line) self.__flushBuffer() -def optParse(): - """Parses commandline options.""" - parser = OptionParser(prog=__applicationName__, version="%prog " + __version__) +def argParse(): + """Parses commandline args.""" + parser = ArgumentParser(prog=__applicationName__) - parser.set_usage("%prog [options] filename") - parser.add_option("--autobrief", - action="store_true", dest="autobrief", + parser.add_argument("--version", action="version", + version="%(prog)s " + __version__ + ) + parser.add_argument("--autobrief", action="store_true", help="use the docstring summary line as \\brief description" ) - parser.add_option("--debug", - action="store_true", dest="debug", + parser.add_argument("--debug", action="store_true", help="enable debug output on stderr" ) + parser.add_argument("filename", metavar="FILENAME") - ## parse options - global options - (options, filename) = parser.parse_args() - - if not filename: - print >>sys.stderr, "No filename given." - sys.exit(-1) - - return filename[0] + return parser.parse_args() def main(): """Starts the parser on the file given by the filename as the first argument on the commandline. """ - filename = optParse() + global args + args = argParse() fsm = Doxypy() - fsm.parseFile(filename) + fsm.parseFile(args.filename) if __name__ == "__main__": main() diff --git a/dtools/bin/update_fsf_address b/dtools/bin/update_fsf_address index 608ba0a8e2..0017fa11a9 100755 --- a/dtools/bin/update_fsf_address +++ b/dtools/bin/update_fsf_address @@ -23,7 +23,7 @@ import re import os import os.path import sys -from optparse import OptionParser +from argparse import ArgumentParser dry_run = False modified_files = [] @@ -109,22 +109,22 @@ def handle_file_or_dir(file_or_dir): def main(): global dry_run - usage = '%prog: [options] [file_or_dir...]' - parser = OptionParser (usage=usage) - parser.add_option('-l', '--list-modified-files', action='store_true', default=False, - help='List modified files to stdout [default=%default]') - parser.add_option('', '--dry-run', action='store_true', default=False, - help="Don't modify any files, just report what would be modified [default=%default]") - (options, args) = parser.parse_args() + parser = ArgumentParser() + parser.add_argument('-l', '--list-modified-files', action='store_true', + help='List modified files to stdout') + parser.add_argument('--dry-run', action='store_true', + help="Don't modify any files, just report what would be modified") + parser.add_argument('file_or_dir', metavar='FILE-OR-DIR', nargs='*') + args = parser.parse_args() - dry_run = options.dry_run - if options.dry_run: - options.list_modified_files = True + dry_run = args.dry_run + if args.dry_run: + args.list_modified_files = True - for file_or_dir in args: + for file_or_dir in args.file_or_dir: handle_file_or_dir(file_or_dir) - if options.list_modified_files: + if args.list_modified_files: for f in modified_files: sys.stdout.write(f + '\n') diff --git a/gr-audio/doc/audio.dox b/gr-audio/doc/audio.dox index d706bbb6ae..648f126104 100644 --- a/gr-audio/doc/audio.dox +++ b/gr-audio/doc/audio.dox @@ -41,21 +41,21 @@ after importing by using: \section audio_usage Usage -For an audio source, a typical OptionParser option and it's use looks +For an audio source, a typical ArgumentParser option and it's use looks like: \code - parser.add_option("-O", "--audio-output", type="string", default="", + parser.add_argument("-O", "--audio-output", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") audio_rate = 32e3 audio_sink = audio.sink (int (audio_rate), options.audio_output) \endcode -Similarly, an audio sink would have a typical OptionParser option and +Similarly, an audio sink would have a typical ArgumentParser option and its use would look like: \code - parser.add_option("-I", "--audio-input", type="string", default="", + parser.add_argument("-I", "--audio-input", default="", help="pcm input device name. E.g., hw:0,0 or /dev/dsp") audio_rate = 32e3 audio_source = audio.source(int(audio_rate), audio_input) |