Python getopt 模块,GetoptError() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用getopt.GetoptError()

项目:encore.ai    作者:dyelax    | 项目源码 | 文件源码
def main():
    artist = 'kanye_west'
    model_path = '../save/models/kanye_west/kanye_west.ckpt-30000'
    num_save = 1000

    try:
        opts, _ = getopt.getopt(sys.argv[1:], 'l:a:N:', ['load_path=', 'artist_name=', 'num_save='])
    except getopt.GetoptError:
        sys.exit(2)

    for opt, arg in opts:
        if opt in ('-l', '--load_path'):
            model_path = arg
        if opt in ('-a', '--artist_name'):
            artist = arg
        if opt in ('-n', '--num_save'):
            num_save = int(arg)

    save(artist, model_path, num_save)
项目:casebox-vagrant    作者:KETSE    | 项目源码 | 文件源码
def main(argv):
    _file = ''
    _var = ''
    try:
        opts, args = getopt.getopt(argv, "f:v", ["file=", "var="])
    except getopt.GetoptError:
        print 'var.py -f <file> -v <variable>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'var.py -f <file>  -v <variable>'
            sys.exit()
        elif opt in ("-f", "--file"):
            _file = arg
        elif opt in ("-v", "--var"):
            _var = '{' + arg + '}'
    f = open(_file)
    data = yaml.load(f)
    print _var.format(data)

    f.close()
项目:hadan-gcloud    作者:youkpan    | 项目源码 | 文件源码
def main(argv):
   inputfile = False
   outputfile = False
   try:
      opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
   except getopt.GetoptError:
      print('vec2bin.py -i <inputfile> -o <outputfile>')
      sys.exit(2)
   for opt, arg in opts:
      if opt == '-h':
         print('test.py -i <inputfile> -o <outputfile>')
         sys.exit()
      elif opt in ("-i", "--ifile"):
         inputfile = arg
      elif opt in ("-o", "--ofile"):
         outputfile = arg

   if not inputfile or not outputfile:
       print('vec2bin.py -i <inputfile> -o <outputfile>')
       sys.exit(2)

   print('Converting %s to binary file format' % inputfile)
   vec2bin(inputfile, outputfile)
项目:atoolbox    作者:liweitianux    | 项目源码 | 文件源码
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hi:",
                                   ["help", "infile="])
    except getopt.GetoptError as err:
        print(err)
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit(1)
        elif opt in ("-i", "--infile"):
            infile = arg
        else:
            assert False, "unhandled option"

    for line in open(infile):
        if re.match(r"^\s*#", line) or re.match(r"^\s*$", line):
            continue
        ra, dec = line.split()
        ra_deg = s_ra2deg(ra)
        dec_deg = s_dec2deg(dec)
        print("%.8f %.8f" % (ra_deg, dec_deg))
项目:broadview-collector    作者:openstack    | 项目源码 | 文件源码
def main():

    host = None
    port = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "h:p:")
    except getopt.GetoptError as err:
        print str(err)  
        usage()
        sys.exit(2)
    for o, a in opts:
        if o == "-h":
            host = a
        elif o == "-p":
            port = a
        else:
            assert False, "unhandled option"

    x = PTECMPResolution(host, port)
    x.send()
项目:broadview-collector    作者:openstack    | 项目源码 | 文件源码
def main():

    host = None
    port = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "h:p:")
    except getopt.GetoptError as err:
        # print help information and exit:
        print str(err)  # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    for o, a in opts:
        if o == "-h":
            host = a
        elif o == "-p":
            port = a
        else:
            assert False, "unhandled option"

    x = PTDropReason(host, port)
    x.send()
项目:broadview-collector    作者:openstack    | 项目源码 | 文件源码
def main():

    host = None
    port = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "h:p:")
    except getopt.GetoptError as err:
        # print help information and exit:
        print str(err)  # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    for o, a in opts:
        if o == "-h":
            host = a
        elif o == "-p":
            port = a
        else:
            assert False, "unhandled option"

    x = PTLAGResolution(host, port)
    x.send()
项目:broadview-collector    作者:openstack    | 项目源码 | 文件源码
def main():

    host = None
    port = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "h:p:")
    except getopt.GetoptError as err:
        # print help information and exit:
        print str(err)  # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    for o, a in opts:
        if o == "-h":
            host = a
        elif o == "-p":
            port = a
        else:
            assert False, "unhandled option"

    x = PTProfile(host, port)
    x.send()
项目:broadview-collector    作者:openstack    | 项目源码 | 文件源码
def main():

    host = None
    port = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "h:p:")
    except getopt.GetoptError as err:
        # print help information and exit:
        print str(err)  # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    for o, a in opts:
        if o == "-h":
            host = a
        elif o == "-p":
            port = a
        else:
            assert False, "unhandled option"

    x = PTDropCounterReport(host, port)
    x.send()
项目:rtf2xml    作者:paulhtremblay    | 项目源码 | 文件源码
def __get_opts(self):
        self.__msv_jar = None
        try:
            options, arguments = getopt.getopt(sys.argv[1:], 'h', ['help', 'clean','local', 'msv-jar=' ])
        except getopt.GetoptError, error:
            sys.stderr.write(str(error))
            self.__help_message()
            sys.exit(1)
        self.__local = None
        self.__clean = None
        for opt, opt_arg in options:
            if 'msv-jar' in opt:
                self.__msv_jar = opt_arg
            if '-h' in opt or '--help' in opt:
                self.__help_message()
                sys.exit(0)
            if '--local' in opt:
                self.__local = 1
            if '--clean' in opt:
                self.__clean = 1
项目:office-interoperability-tools    作者:milossramek    | 项目源码 | 文件源码
def parsecmd():
    global rankfile, genranks
    try:
        opts, Names = getopt.getopt(sys.argv[1:], "hcr:", [])
    except getopt.GetoptError as err:
        # print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    for o, a in opts:
        if o in ("-c"):
            genranks=True
        elif o in ("-r"):
            rankfile = a
        elif o in ("-h"):
            usage()
            sys.exit(0)
        else:
            assert False, "unhandled option"
    return Names
项目:touch-pay-client    作者:HackPucBemobi    | 项目源码 | 文件源码
def main(argv):
    """Parse the arguments and start the main process."""
    try:
        opts, args = getopt.getopt(argv, "h", ["help"])
    except getopt.GetoptError:
        exit_with_parsing_error()
    for opt, arg in opts:
        arg = arg  # To avoid a warning from Pydev
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
    if len(args) == 2:
        params = list(get_dicts(*args))
        params.extend(get_dict_names(*args))
        compare_dicts(*params)
    else:
        exit_with_parsing_error()
项目:rapier    作者:apigee-labs    | 项目源码 | 文件源码
def main(args):
    generator = OASGenerator()
    usage = 'usage: gen_openapispec.py [-m, --yaml-merge] [-i, --include-impl] [-t --suppress-templates] filename'
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'mit', ['yaml-merge', 'include-impl', 'suppress-templates'])
    except getopt.GetoptError as err:
        sys.exit(str(err) + '\n' + usage)
    if not len(args) == 1:
        sys.exit(usage)        
    generator.set_opts(opts)
    Dumper = CustomAnchorDumper
    opts_keys = [k for k,v in opts]
    if False: #'--yaml-alias' not in opts_keys and '-m' not in opts_keys:
        Dumper.ignore_aliases = lambda self, data: True
    Dumper.add_representer(PresortedOrderedDict, yaml.representer.SafeRepresenter.represent_dict)
    Dumper.add_representer(validate_rapier.unicode_node, yaml.representer.SafeRepresenter.represent_unicode)
    Dumper.add_representer(validate_rapier.list_node, yaml.representer.SafeRepresenter.represent_list)
    openAPI_spec = generator.openAPI_spec_from_rapier(*args)
    openAPI_spec_yaml = yaml.dump(openAPI_spec, default_flow_style=False, Dumper=Dumper)
    openAPI_spec_yaml = str.replace(openAPI_spec_yaml, "'<<':", '<<:')
    print openAPI_spec_yaml
项目:rapier    作者:apigee-labs    | 项目源码 | 文件源码
def main():
    usage = 'usage: rapier [-v, --validate] [-p, --gen-python] [-j, --gen-js] [-m, --yaml-merge] [-i, --include-impl] [-t --suppress-templates] filename'
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'vpjmit', ['validate', 'gen-python', 'gen-js', 'yaml-merge', 'include-impl', 'suppress-templates'])
    except getopt.GetoptError as err:
        sys.exit(str(err) + '\n' + usage)
    if not len(args) == 1:
        sys.exit(usage)        
    opts_keys = [k for k,v in opts]

    if '-v' in opts_keys or '--validate' in opts_keys:
        validate_main(args[0])
    elif '-p' in opts_keys or '--gen-python' in opts_keys:
        gen_py_main(args[0])
    elif '-j' in opts_keys or '--gen-js' in opts_keys:
        gen_py_main(args[0])
    else:
        gen_oas_main(sys.argv)
项目:semantic-segmentation    作者:albertbuchard    | 项目源码 | 文件源码
def main(argv):
   phase = "train"
   model_string = "final_fcn_model.h5"
   try:
      opts, args = getopt.getopt(argv,"hp:m:",["phase=","model="])
   except getopt.GetoptError:
      print('run_FCN.py -p <phase> -m <model>')
      sys.exit(2)
   for opt, arg in opts:
      if opt == '-h':
         print('run_FCN.py -p <phase> -m <model>')
         sys.exit()
      elif opt in ("-p", "--phase"):
         phase = arg
      elif opt in ("-m", "--model"):
         model_string = arg
   return phase, model_string
项目:poloTrader    作者:GooTZ    | 项目源码 | 文件源码
def main(argv):
    mode = ''
    try:
        opts, args = getopt.getopt(argv,"m:h",["mode="])
    except getopt.GetoptError:
        print('run.py -m <TESTING/LIVE_TESTING/TRADING/FETCH_DATA>')
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            print('run.py -m <TESTING/LIVE_TESTING/TRADING/FETCH_DATA>')
            sys.exit()
        elif opt in ("-m", "--mode"):
            if arg in TradingMode.__members__:
                mode = TradingMode[arg]
            else:
                raise UnsupportedModeError(arg, "The given mode is not supported!")

    app.run(mode)
项目:azure-iot-sdk-python    作者:Azure    | 项目源码 | 文件源码
def get_iothub_opt(
        argv,
        connection_string,
        device_id):
    if len(argv) > 0:
        try:
            opts, args = getopt.getopt(
                argv, "hd:c:", [
                    "connectionstring=", "deviceid="])
        except getopt.GetoptError as get_opt_error:
            raise OptionError("Error: %s" % get_opt_error.msg)
        for opt, arg in opts:
            if opt == '-h':
                raise OptionError("Help:")
            elif opt in ("-c", "--connectionstring"):
                connection_string = arg
            elif opt in ("-d", "--deviceid"):
                device_id = arg

    if connection_string.find("HostName") < 0:
        raise OptionError(
            "Error: Hostname not found, not a valid connection string")

    return connection_string, device_id
项目:export-kobo    作者:pettarin    | 项目源码 | 文件源码
def read_command_line_parameters(argv):

    try:
        optlist, free = getopt.getopt(argv[1:], 'chtb:f:o:', ['book=', 'file=', 'output=', 'csv', 'help', 'titles'])
    #Python2#    except getopt.GetoptError, err:
    #Python3#
    except getopt.GetoptError as err:
        print_error(str(err))

    return dict(optlist)
### END read_command_line_parameters ###


### BEGIN usage ###
# usage()
# print script usage
项目:export-kobo    作者:pettarin    | 项目源码 | 文件源码
def read_command_line_parameters(argv):

    try:
        optlist, free = getopt.getopt(argv[1:], 'chtb:f:o:', ['book=', 'file=', 'output=', 'csv', 'help', 'titles'])
    #Python2#
    except getopt.GetoptError, err:
    #Python3#    except getopt.GetoptError as err:
        print_error(str(err))

    return dict(optlist)
### END read_command_line_parameters ###


### BEGIN usage ###
# usage()
# print script usage
项目:oss-github-analysis-project    作者:itu-oss-project-team    | 项目源码 | 文件源码
def main(argv):
    owner = ""
    repo = ""
    force = False

    try:
        opts, args = getopt.getopt(argv, "o:r:f", ["owner=", "repo=", "force"])
    except getopt.GetoptError:
        print('ERROR in input arguments!')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':  # Help case
            print('fetch_repo.py -o <owner> -r <repo> -f Ex: fetch_repo.py --owner itu-oss-project-team  --repo oss-github-analysis-project --force')
            sys.exit()
        elif opt in ("-o", "--owner"):
            owner = arg
        elif opt in ("-r", "--repo"):
            repo = arg
        elif opt in ("-f", "--force"):
            force = True

    github_harvester = GitHubHarvester()

    #github_harvester.fetch_repo(owner, repo, force_fetch = force)
    github_harvester.fetch_repo('itu-oss-project-team', 'oss-github-analysis-project', force_fetch = True)
项目:cqut_student_schedule_py    作者:acbetter    | 项目源码 | 文件源码
def get_username_password(self):
        """??????? ????????"""
        try:
            opts, args = getopt.getopt(self.argv[1:], 'hu:p:', ['username=', 'password='])
        except getopt.GetoptError:
            self.logger.info('????????????????')
            self.logger.info('cqut.py -u <username> -p <password>')
            sys.exit(-1)
        for opt, arg in opts:
            if opt in ('-u', '--username'):
                self.username = arg
            elif opt in ('-p', '--password'):
                self.password = arg
        if self.username is None:
            self.username = input('???????: ')
        if self.password is None:
            self.password = input('???????: ')
项目:POEditor-Android-Translator    作者:JavonDavis    | 项目源码 | 文件源码
def main(argv):
    option = ''
    try:
        opts, args = getopt.getopt(argv, "h:o:", ["option="])
    except getopt.GetoptError:
        print 'test.py -o <option[translate or build]>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'test.py -o <option[translate or build]>'
            sys.exit()
        elif opt in ("-o", "--option"):
            option = arg
    if option == 'translate':
        fname = str(raw_input("File name(Or absolute path to file if it is not in this directory):\n"))
        execute(fname)
    elif option == 'build':
        name_fname = str(raw_input("File name for csv containing string names(Or absolute path to file):\n"))
        values_fname = str(raw_input("File name for csv containing translation(Or absolute path to file):\n"))
        build_xml(name_fname, values_fname)
    else:
        print "Invalid option: " + option
        print "Option must be either translate or build"
项目:bifrost    作者:ledatelescope    | 项目源码 | 文件源码
def parseOptions(args):
    config = {}
    # Command line flags - default values
    config['args'] = []

    # Read in and process the command line flags
    try:
        opts, args = getopt.getopt(args, "h", ["help",])
    except getopt.GetoptError, err:
        # Print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage(exitCode=2)

    # Work through opts
    for opt, value in opts:
        if opt in ('-h', '--help'):
            usage(exitCode=0)
        else:
            assert False

    # Add in arguments
    config['args'] = args

    # Return configuration
    return config
项目:bifrost    作者:ledatelescope    | 项目源码 | 文件源码
def parseOptions(args):
    config = {}
    # Command line flags - default values
    config['args'] = []

    # Read in and process the command line flags
    try:
        opts, args = getopt.getopt(args, "h", ["help",])
    except getopt.GetoptError, err:
        # Print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage(exitCode=2)

    # Work through opts
    for opt, value in opts:
        if opt in ('-h', '--help'):
            usage(exitCode=0)
        else:
            assert False

    # Add in arguments
    config['args'] = args

    # Return configuration
    return config
项目:bifrost    作者:ledatelescope    | 项目源码 | 文件源码
def parseOptions(args):
    config = {}
    # Command line flags - default values
    config['args'] = []

    # Read in and process the command line flags
    try:
        opts, args = getopt.getopt(args, "h", ["help",])
    except getopt.GetoptError, err:
        # Print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage(exitCode=2)

    # Work through opts
    for opt, value in opts:
        if opt in ('-h', '--help'):
            usage(exitCode=0)
        else:
            assert False

    # Add in arguments
    config['args'] = args

    # Return configuration
    return config
项目:bifrost    作者:ledatelescope    | 项目源码 | 文件源码
def parseOptions(args):
    config = {}
    # Command line flags - default values
    config['args'] = []

    # Read in and process the command line flags
    try:
        opts, args = getopt.getopt(args, "h", ["help",])
    except getopt.GetoptError, err:
        # Print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage(exitCode=2)

    # Work through opts
    for opt, value in opts:
        if opt in ('-h', '--help'):
            usage(exitCode=0)
        else:
            assert False

    # Add in arguments
    config['args'] = args

    # Return configuration
    return config
项目:bifrost    作者:ledatelescope    | 项目源码 | 文件源码
def parseOptions(args):
    config = {}
    # Command line flags - default values
    config['args'] = []

    # Read in and process the command line flags
    try:
        opts, args = getopt.getopt(args, "h", ["help",])
    except getopt.GetoptError, err:
        # Print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage(exitCode=2)
    # Work through opts
    for opt, value in opts:
        if opt in ('-h', '--help'):
            usage(exitCode=0)
        else:
            assert False

    # Add in arguments
    config['args'] = args

    # Return configuration
    return config
项目:DeepQA    作者:Conchylicultor    | 项目源码 | 文件源码
def main(argv):
   inputfile = False
   outputfile = False
   try:
      opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
   except getopt.GetoptError:
      print('vec2bin.py -i <inputfile> -o <outputfile>')
      sys.exit(2)
   for opt, arg in opts:
      if opt == '-h':
         print('test.py -i <inputfile> -o <outputfile>')
         sys.exit()
      elif opt in ("-i", "--ifile"):
         inputfile = arg
      elif opt in ("-o", "--ofile"):
         outputfile = arg

   if not inputfile or not outputfile:
       print('vec2bin.py -i <inputfile> -o <outputfile>')
       sys.exit(2)

   print('Converting %s to binary file format' % inputfile)
   vec2bin(inputfile, outputfile)
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def main(argv):
    """Parse the arguments and start the main process."""
    try:
        opts, args = getopt.getopt(argv, "h", ["help"])
    except getopt.GetoptError:
        exit_with_parsing_error()
    for opt, arg in opts:
        arg = arg  # To avoid a warning from Pydev
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
    if len(args) == 2:
        params = list(get_dicts(*args))
        params.extend(get_dict_names(*args))
        compare_dicts(*params)
    else:
        exit_with_parsing_error()
项目:WikipediaQuiz    作者:NicholasMoser    | 项目源码 | 文件源码
def handle_args():
    """Handle the command line arguments provided for the program.
    There is an argument for the number of articles to make it configurable.
    There is also an argument for the length of the passage to make it configurable.
    If the argument is not provided it uses the provided default.
    """
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'n:l:', ['numberofarticles=', 'passagelength='])
    except getopt.GetoptError:
        print('wikipedia_quiz.py -n <numberofarticles> -l <passagelength>')
        logging.error('Opt error encountered')
        sys.exit(2)
    number_of_articles = NUMBER_OF_ARTICLES_DEFAULT
    passage_length = PASSAGE_LENGTH_DEFAULT
    for opt, arg in opts:
        if opt in ('-n', '--numberofarticles'):
            number_of_articles = int(arg)
            logging.info('Number of articles parameter found')
        elif opt in ('-l', '--passagelength'):
            passage_length = int(arg)
            logging.info('Passage length parameter found')
    return number_of_articles, passage_length
项目:autoreg    作者:pbeyssac    | 项目源码 | 文件源码
def transfer(argv=sys.argv):
  try:
    opts, args = getopt.getopt(argv[1:], "n")
  except getopt.GetoptError:
    usage()
    return 1

  dry_run = False

  for o, a in opts:
      if o == "-n":
        dry_run = True

  if len(args) == 3:
    default_ttl = int(args[2])
  else:
    default_ttl = 86400
  axfr(args[0], args[1], default_ttl, dry_run=dry_run)
项目:bitcointalk-sentiment    作者:DolphinBlockchainIntelligence    | 项目源码 | 文件源码
def main(argv):
    input_file = ''
    save_to = ''
    try:
        opts, args = getopt.getopt(argv, "hi:o:")
    except getopt.GetoptError:
        print('graph_builder.py -i <JSON inputfile> -o <output image>')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print('graph_builder.py -i <JSON inputfile> -o <output image>')
            sys.exit()
        elif opt == '-i':
            input_file = arg
        elif opt == '-o':
            save_to = arg

    build_graph(input_file,save_to)
项目:bitcointalk-sentiment    作者:DolphinBlockchainIntelligence    | 项目源码 | 文件源码
def main(argv):
    warnings.filterwarnings('ignore', category=DeprecationWarning)
    input_file = ''
    model_file = ''
    output_folder = ''
    output_posts = ''
    try:
        opts, args = getopt.getopt(argv, "hi:m:f:n:")
    except getopt.GetoptError:
        print('bitcointalk_sentiment_classifier.py -i <inputfile> -m <model> -f <output folder> -n <number of output posts [number|fraction|all]>')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print('bitcointalk_sentiment_classifier.py -i <inputfile> -m <model> -f <output folder> -n <number of output posts [number|fraction|all]>')
            sys.exit()
        elif opt == '-i':
            input_file = arg
        elif opt == '-m':
            model_file = arg
        elif opt == '-f':
            output_folder = arg
        elif opt == '-n':
            output_posts = arg

    classify(input_file, model_file, output_folder, output_posts)
项目:bitcointalk-sentiment    作者:DolphinBlockchainIntelligence    | 项目源码 | 文件源码
def main(argv):
    input_file = ''
    save_to = ''
    try:
        opts, args = getopt.getopt(argv, "hi:o:")
    except getopt.GetoptError:
        print('graph_builder.py -i <JSON inputfile> -o <output image>')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print('graph_builder.py -i <JSON inputfile> -o <output image>')
            sys.exit()
        elif opt == '-i':
            input_file = arg
        elif opt == '-o':
            save_to = arg

    build_graph(input_file,save_to)
项目:unicorn-display    作者:actuino    | 项目源码 | 文件源码
def main(argv):
    global CONFIG_FILE_NAME
    try:
        opts, args = getopt.getopt(argv,"hc:",["help","config="])
    except getopt.GetoptError:
        print 'client.py -c <configfile> '
        sys.exit(2)
    for opt, arg in opts:
          if opt in ("-h", "--help"):
             print 'client.py -c <configfile> '
             sys.exit()
          elif opt in ("-c", "--config"):
             CONFIG_FILE_NAME = arg
    print 'Config file is "', CONFIG_FILE_NAME

    unicorndisplay.init(CONFIG_FILE_NAME)
项目:cidrToIps    作者:cldrn    | 项目源码 | 文件源码
def main(argv):
  inputfile = ''
  try:
    opts, args = getopt.getopt(argv,"i:",["ifile="])
  except getopt.GetoptError:
    print 'cidrToIps.py -i <inputfile>'
    sys.exit(2)
  for opt, arg in opts:
    if opt == '-h':
      print 'cidrToIps.py -i <inputfile>'
      sys.exit()
    elif opt in ("-i", "--ifile"):
      inputfile = arg

  print 'Reading IP ranges in CIDR notation from file:', inputfile
  fo = open(inputfile, "r+")
  for line in fo:
    for ip in IPNetwork(line):
      print '%s' % ip
项目:easyATT    作者:InfiniteSamuel    | 项目源码 | 文件源码
def main(argv):
    import getopt, imp
    def usage():
        print ('usage: %s [-h host] [-p port] [-n name] module.class' % argv[0])
        return 100
    try:
        (opts, args) = getopt.getopt(argv[1:], 'h:p:n:')
    except getopt.GetoptError:
        return usage()
    host = ''
    port = 8080
    name = 'WebApp'
    for (k, v) in opts:
        if k == '-h': host = v
        elif k == '-p': port = int(v)
        elif k == '-n': name = v
    if not args: return usage()
    path = args.pop(0)
    module = imp.load_source('app', path)
    WebAppHandler.APP_CLASS = getattr(module, name)
    print ('Listening %s:%d...' % (host,port))
    httpd = HTTPServer((host,port), WebAppHandler)
    httpd.serve_forever()
    return
项目:easyATT    作者:InfiniteSamuel    | 项目源码 | 文件源码
def main(argv):
    import getopt, fileinput
    def usage():
        print ('usage: %s [-c codec] file ...' % argv[0])
        return 100
    try:
        (opts, args) = getopt.getopt(argv[1:], 'c')
    except getopt.GetoptError:
        return usage()
    if not args: return usage()
    codec = 'utf-8'
    for (k, v) in opts:
        if k == '-c': codec = v
    for line in fileinput.input(args):
        line = latin2ascii(unicode(line, codec, 'ignore'))
        sys.stdout.write(line.encode('ascii', 'replace'))
    return
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def main(argv):
    """Parse the arguments and start the main process."""
    try:
        opts, args = getopt.getopt(argv, "h", ["help"])
    except getopt.GetoptError:
        exit_with_parsing_error()
    for opt, arg in opts:
        arg = arg  # To avoid a warning from Pydev
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
    if len(args) == 2:
        params = list(get_dicts(*args))
        params.extend(get_dict_names(*args))
        compare_dicts(*params)
    else:
        exit_with_parsing_error()
项目:patchwork    作者:Factual    | 项目源码 | 文件源码
def parse_args(argv):
    helpstring = 'dep-check.py [-c <config_file>] [-v -t -s]'

    fname = PATCHWORK_PATH + '/patchwork/config.json' # if not specified, look in current directory
    global VERBOSE
    global TEST
    global PERSIST
    try:
        opts, args = getopt.getopt(argv,"hvtsc:",["verbose","test","save","config="])
    except getopt.GetoptError:
        print(helpstring)
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print(helpstring)
            sys.exit()
        elif opt in ("-c", "--config"):
            fname = arg
        elif opt in ("-v", "--verbose"):
            VERBOSE = True
        elif opt in ("-t", "--test"):
            TEST = True
        elif opt in ("-s", "--save"):
            PERSIST = True
    return fname
项目:atg-commerce-iaas    作者:oracle    | 项目源码 | 文件源码
def main(argv):
    # Configure Parameters and Options
    options = 'e:u:p:P:'
    longOptions = ['endpoint=', 'user=', 'password=', 'pwdfile=']
    # Get Options & Arguments
    try:
        opts, args = getopt.getopt(argv, options, longOptions)
        # Read Module Arguments
        moduleArgs = readModuleArgs(opts, args)
    except getopt.GetoptError:
        usage()
    except Exception as e:
        print('Unknown Exception please check log file')
        logging.exception(e)
        sys.exit(1)

    return


# Main function to kick off processing
项目:atg-commerce-iaas    作者:oracle    | 项目源码 | 文件源码
def main(argv):
    # Configure Parameters and Options
    options = 'e:u:p:P:'
    longOptions = ['endpoint=', 'user=', 'password=', 'pwdfile=']
    # Get Options & Arguments
    try:
        opts, args = getopt.getopt(argv, options, longOptions)
        # Read Module Arguments
        moduleArgs = readModuleArgs(opts, args)
    except getopt.GetoptError:
        usage()
    except Exception as e:
        print('Unknown Exception please check log file')
        logging.exception(e)
        sys.exit(1)

    return


# Main function to kick off processing
项目:atg-commerce-iaas    作者:oracle    | 项目源码 | 文件源码
def main(argv):
    # Configure Parameters and Options
    options = 'e:u:p:P:'
    longOptions = ['endpoint=', 'user=', 'password=', 'pwdfile=']
    # Get Options & Arguments
    try:
        opts, args = getopt.getopt(argv, options, longOptions)
        # Read Module Arguments
        moduleArgs = readModuleArgs(opts, args)
    except getopt.GetoptError:
        usage()
    except Exception as e:
        print('Unknown Exception please check log file')
        logging.exception(e)
        sys.exit(1)

    return


# Main function to kick off processing
项目:atg-commerce-iaas    作者:oracle    | 项目源码 | 文件源码
def main(argv):
    # Configure Parameters and Options
    options = 'e:u:p:P:'
    longOptions = ['endpoint=', 'user=', 'password=', 'pwdfile=']
    # Get Options & Arguments
    try:
        opts, args = getopt.getopt(argv, options, longOptions)
        # Read Module Arguments
        moduleArgs = readModuleArgs(opts, args)
    except getopt.GetoptError:
        usage()
    except Exception as e:
        print('Unknown Exception please check log file')
        logging.exception(e)
        sys.exit(1)

    return


# Main function to kick off processing
项目:atg-commerce-iaas    作者:oracle    | 项目源码 | 文件源码
def main(argv):
    # Configure Parameters and Options
    options = 'e:u:p:P:'
    longOptions = ['endpoint=', 'user=', 'password=', 'pwdfile=']
    # Get Options & Arguments
    try:
        opts, args = getopt.getopt(argv, options, longOptions)
        # Read Module Arguments
        moduleArgs = readModuleArgs(opts, args)
    except getopt.GetoptError:
        usage()
    except Exception as e:
        print('Unknown Exception please check log file')
        logging.exception(e)
        sys.exit(1)

    return


# Main function to kick off processing
项目:atg-commerce-iaas    作者:oracle    | 项目源码 | 文件源码
def main(argv):
    # Configure Parameters and Options
    options = 'e:u:p:P:'
    longOptions = ['endpoint=', 'user=', 'password=', 'pwdfile=']
    # Get Options & Arguments
    try:
        opts, args = getopt.getopt(argv, options, longOptions)
        # Read Module Arguments
        moduleArgs = readModuleArgs(opts, args)
    except getopt.GetoptError:
        usage()
    except Exception as e:
        print('Unknown Exception please check log file')
        logging.exception(e)
        sys.exit(1)

    return


# Main function to kick off processing
项目:atg-commerce-iaas    作者:oracle    | 项目源码 | 文件源码
def main(argv):
    # Configure Parameters and Options
    options = 'e:u:p:P:'
    longOptions = ['endpoint=', 'user=', 'password=', 'pwdfile=']
    # Get Options & Arguments
    try:
        opts, args = getopt.getopt(argv, options, longOptions)
        # Read Module Arguments
        moduleArgs = readModuleArgs(opts, args)
    except getopt.GetoptError:
        usage()
    except Exception as e:
        print('Unknown Exception please check log file')
        logging.exception(e)
        sys.exit(1)

    return


# Main function to kick off processing
项目:atg-commerce-iaas    作者:oracle    | 项目源码 | 文件源码
def main(argv):
    # Configure Parameters and Options
    options = 'e:u:p:P:'
    longOptions = ['endpoint=', 'user=', 'password=', 'pwdfile=']
    # Get Options & Arguments
    try:
        opts, args = getopt.getopt(argv, options, longOptions)
        # Read Module Arguments
        moduleArgs = readModuleArgs(opts, args)
    except getopt.GetoptError:
        usage()
    except Exception as e:
        print('Unknown Exception please check log file')
        logging.exception(e)
        sys.exit(1)

    return


# Main function to kick off processing
项目:tashaphyne    作者:linuxscout    | 项目源码 | 文件源码
def grabargs():
#  "Grab command-line arguments"
    fname = ''
    options={
    'strip':False,
    'full':False,
    'limit':False,
    'stat':False,
    'reduce':False,
}
    if not sys.argv[1:]:
        usage()
        sys.exit(0)
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hVtlv:f:l:",
                               ["help", "version","stat", "limit=", "file="],)
    except getopt.GetoptError:
        usage()
        sys.exit(0)
    for o, val in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit(0)
        if o in ("-V", "--version"):
            print scriptversion
            sys.exit(0)
        if o in ("-t", "--stat"):
            options['stat'] = True;
        if o in ("-l", "--limit"):
            try: options['limit'] = int(val);
            except: options['limit']=0;

        if o in ("-f", "--file"):
            fname = val
    utfargs=[]
    for a in args:
        utfargs.append( a.decode('utf8'));
    text= u' '.join(utfargs);

    #if text: print text.encode('utf8');
    return (fname, options)
项目:core-framework    作者:RedhawkSDR    | 项目源码 | 文件源码
def _getOptions(classtype):
    try:
        # IMPORTANT YOU CANNOT USE gnu_getopt OR OptionParser
        # because they will treat execparams with negative number
        # values as arguments.
        #
        # Since property ids *MUST* be valid XML names
        # they cannot start with -, therefore this is safe
        opts, args = getopt.getopt(sys.argv[1:], "i", ["interactive"])
        if len(opts)==0 and len(args)==0:
            print "usage: %s [options] [execparams]" % sys.argv[0]
            print
            print "The set of execparams is defined in the .prf for the component"
            print "They are provided as arguments pairs ID VALUE, for example:"
            print "     %s INT_PARAM 5 STR_PARAM ABCDED" % sys.argv[0]
            print
            print classtype.__doc__
            sys.exit(2)
    except getopt.GetoptError:
        print "usage: %s [options] [execparams]" % sys.argv[0]
        print
        print "The set of execparams is defined in the .prf for the component"
        print "They are provided as arguments pairs ID VALUE, for example:"
        print "     %s INT_PARAM 5 STR_PARAM ABCDED" % sys.argv[0]
        print
        print classtype.__doc__
        sys.exit(2)
    return opts, args