def main(argv): try: argv = FLAGS(argv) # set logging verbosity level if FLAGS.verbose: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) # check some parameters if len(argv) != 2: raise gflags.FlagsError("Missing URL") # Set control parameters control = livebox.Control() try: control.url = argv[1] for key in ('resolution', 'framerate', 'bitrate', 'audio', 'video', 'quality', 'hflip', 'vflip'): value = getattr(FLAGS, key) setattr(control, key, value) except ValueError, e: raise gflags.FlagsError(e) logging.debug(pprint.pformat(control.as_json())) # Run application application = Application(control, ffmpeg=FLAGS.ffmpeg) # Deal with the return value (returncode, status) = application.run() if returncode: logging.error(status) sys.exit(returncode)
def main_gflagged(argv, run_func): """Parse flags, check for errors; execute run_func(). run() has access to the gflags.FLAGS objects, if in same file as import of same""" if len(argv) == 1: print("\n" "At least one command flag is required.\n\n" "Use \n" " << {[0]} --help >>\n\n" "for basic information on available flags." "\n".format(argv)) sys.exit(1) try: argv = FLAGS(argv) # parse flags if len(FLAGS(argv)) > 1: raise gflags.FlagsError("No positional parameters accepted") except gflags.FlagsError as flagerr: print("Error:\n\n {0}\n\n\n".format(flagerr)) print("Usage: %s ARGS\n%s" % (sys.argv[0], FLAGS)) sys.exit(1) return run_func()
print >> logs, "%d features survived (ratio: %.2f)" % ( len(new), len(new) / len(self.weights)) self.weights = new def sparsify(self, z=1): '''duchi et al., 2008''' if __name__ == "__main__": flags.DEFINE_string("prune", None, "prune features w.r.t. FILE (word/tag format)") try: argv = FLAGS(sys.argv) if FLAGS.weights is None: raise flags.FlagsError("must specify weights by -w ...") except flags.FlagsError, e: print >> logs, 'Error: %s\nUsage: %s ARGS\n%s' % (e, sys.argv[0], FLAGS) sys.exit(1) FLAGS.featstat = True model = Model(FLAGS.weights) #.model, FLAGS.weights) if FLAGS.prune: model.prune(FLAGS.prune) if FLAGS.outputweights: model.write(FLAGS.outputweights)
def ParseArguments(argv): """Parse the arguments and do sanity checks.""" targets = [ c_helpers.CamelToSnake(node) for node in aio.aio_node_helper.ShortNames() ] hardware_types = ['aio', 'motor', 'cs'] flags = gflags.FLAGS gflags.DEFINE_bool('application', False, 'Flash an application bin.') gflags.DEFINE_bool('bootloader', False, 'Flash a bootloader bin.') gflags.DEFINE_bool('calib', False, 'Flash calibration parameters.') gflags.DEFINE_bool('config', False, 'Flash configuration parameters.') gflags.DEFINE_bool('erase', False, 'Erase all flash memory.') gflags.DEFINE_bool('serial', False, 'Flash a serial bin file.') gflags.DEFINE_integer('speed', 4000, 'JTAG Speed (kHz).') gflags.DEFINE_enum('hardware_type', None, hardware_types, 'Hardware type.') gflags.DEFINE_enum('target', None, targets, 'Target node to program') gflags.DEFINE_integer('retry', 3, 'How many retries to attempt during failures.') gflags.DEFINE_string('file', None, 'The file.') try: argv = flags(argv) if (flags.application or flags.bootloader or flags.calib or flags.config or flags.serial): if not flags.file: raise gflags.FlagsError( 'You must specify --file with --application, ' '--bootloader, --calib, --config or --serial.') if _ValidFileArg(flags.file, '.elf'): file_type = 'elf' elif _ValidFileArg(flags.file, '.bin'): file_type = 'bin' else: raise gflags.FlagsError( 'Unknown file type: "{}", expected .bin or .elf'.format( flags.file)) elif not flags.erase: raise gflags.FlagsError( 'Invalid argument combination! Pick one of: ' '--application, --bootloader, --calib, --config ' '--erase or --serial') if flags.bootloader or flags.application: if file_type == 'elf': if not flags.target: raise gflags.FlagsError( 'You must specify --target when using ' '--bootloader or --application with .elf ' 'files.') if not flags.hardware_type: raise gflags.FlagsError( 'You must specify a hardware_type.') elif flags.calib or flags.config or flags.serial: if file_type != 'bin': raise gflags.FlagsError( 'You must specify a bin file for this action.') except gflags.FlagsError, e: print e, flags sys.exit(1)