当前位置: 首页>>代码示例>>Python>>正文


Python getopt.GetoptError方法代码示例

本文整理汇总了Python中getopt.GetoptError方法的典型用法代码示例。如果您正苦于以下问题:Python getopt.GetoptError方法的具体用法?Python getopt.GetoptError怎么用?Python getopt.GetoptError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在getopt的用法示例。


在下文中一共展示了getopt.GetoptError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def main(self, argv: List[str]) -> None:
        try:
            opts, args = getopt.getopt(argv, "hlvV ", ['help', 'log', 'version', 'version', 'dependency-versions'])
        except getopt.GetoptError:
            self.help_command()
        for opt, _ in opts:
            if opt in ['-h', '--help']:
                self.help_command()
            if opt in ['-v', '-V', '--version']:
                self.version_command()
            if opt in ['--dependency-versions']:
                self.dependency_versions_command()
        if len(args):
            if args[0] in ('run', 'start', 'go'):
                self.run_command(args[1:])
        self.help_command() 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:18,代码来源:__init__.py

示例2: ParseArguments

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def ParseArguments(argv):
  """Parses command-line arguments.

  Args:
    argv: Command-line arguments, including the executable name, used to
      execute this application.

  Returns:
    Tuple (args, option_dict) where:
      args: List of command-line arguments following the executable name.
      option_dict: Dictionary of parsed flags that maps keys from DEFAULT_ARGS
        to their values, which are either pulled from the defaults, or from
        command-line flags.
  """
  option_dict = DEFAULT_ARGS.copy()

  try:
    opts, args = getopt.gnu_getopt(argv[1:], OPTIONS, LONG_OPTIONS)
  except getopt.GetoptError, e:
    print >>sys.stderr, 'Error: %s' % e
    PrintUsageExit(1) 
开发者ID:elsigh,项目名称:browserscope,代码行数:23,代码来源:dev_appserver_main.py

示例3: main

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def main():
    ##
    # Handle command line input
    ##

    num_clips = 5000000

    try:
        opts, _ = getopt.getopt(sys.argv[1:], 'n:t:c:oH',
                                ['num_clips=', 'train_dir=', 'clips_dir=', 'overwrite', 'help'])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt in ('-n', '--num_clips'):
            num_clips = int(arg)
        if opt in ('-t', '--train_dir'):
            c.TRAIN_DIR = c.get_dir(arg)
        if opt in ('-c', '--clips_dir'):
            c.TRAIN_DIR_CLIPS = c.get_dir(arg)
        if opt in ('-o', '--overwrite'):
            c.clear_dir(c.TRAIN_DIR_CLIPS)
        if opt in ('-H', '--help'):
            usage()
            sys.exit(2)

    # set train frame dimensions
    assert os.path.exists(c.TRAIN_DIR)
    c.FULL_HEIGHT, c.FULL_WIDTH = c.get_train_frame_dims()

    ##
    # Process data for training
    ##

    process_training_data(num_clips) 
开发者ID:dyelax,项目名称:Adversarial_Video_Generation,代码行数:38,代码来源:process_data.py

示例4: test_invalid_opt

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def test_invalid_opt():
    with pytest.raises(getopt.GetoptError):
        _parsebase(['--invalid', 'opt'])
    with pytest.raises(getopt.GetoptError):
        _parsebase(['--test=10%']) 
开发者ID:mme,项目名称:vergeml,代码行数:7,代码来源:test_cmd.py

示例5: test_config_plugin

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def test_config_plugin():
    args, _ = _parsebase(['--device=gpu', '--device-memory=20%'])
    assert(args == {'device': 'gpu', 'device-memory': '20%'})
    with pytest.raises(getopt.GetoptError):
        _parsebase(['--device-id=gpu', '--device-memory=20%']) 
开发者ID:mme,项目名称:vergeml,代码行数:7,代码来源:test_cmd.py

示例6: _parsebase

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def _parsebase(argv):
    """Parse until the second part of the command.
    """
    shortopts = 'vf:m:' # version, file, model
    longopts = ['version', 'file=', 'model=', 'samples-dir=', 'test-split=', 'val-split=',
                'cache-dir=', 'random-seed=', 'trainings-dir=', 'project-dir=',
                'cache=', 'device=', 'device-memory=']

    args, rest = getopt.getopt(argv, shortopts, longopts)

    args = dict(args)
    # don't match prefix
    for opt in map(lambda s: s.rstrip("="), longopts):
        # pylint: disable=W0640
        if ''f'--{opt}' in args and not any(map(lambda a: a.startswith('--' + opt), argv)):
            # find the key that does not match
            keys = map(lambda a: a.split("=")[0].lstrip("-"), argv)
            keys = list(filter(lambda k: k in opt, keys))
            if keys:
                raise getopt.GetoptError('Invalid key', opt='--' + keys[0])
            else:
                raise getopt.GetoptError('Invalid key')

    # convert from short to long names
    for sht, lng in (('-v', '--version'), ('-m', '--model'), ('-f', '--file')):
        if sht in args:
            args[lng] = args[sht]
            del args[sht]

    args = {k.strip('-'):v for k, v in args.items()}

    return args, rest 
开发者ID:mme,项目名称:vergeml,代码行数:34,代码来源:__main__.py

示例7: main

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def main(argv):
    try:
        opts, args = getopt.getopt(argv, "hi:d", ["ip="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    if not opts:
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt == "-h":
            print '### HELP? ma LOL ###'
            sys.exit()
        elif opt == "-i":
            ipToCheck = arg
         

    print '## Checking IP:',arg

    print '## Verify EGBL...'
    verifyConfig()
     
    print '## Check vulnerability...'
    verifyVuln(ipToCheck) 
开发者ID:fnatalucci,项目名称:NSAEQGRPFortinetVerify,代码行数:28,代码来源:check_fortinet_vuln.py

示例8: init

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def init(argv):
    """Read the args and return all variable
    Will return:
        - the number of error encounter
        - the absolute path of the output directory
        - an array of collection id given as args (in fact everything that is
            not a recognised arg
        - the absolute path of the save file
    Return int(error), string(output_dir), array(collections_id),
        string(save_file)
    """
    error = 0
    output_dir = os.getcwd()
    collections_id_list = []
    save_file = os.path.join(output_dir, "addons.lst")
    if len(argv) == 1 and not os.path.isfile(save_file):
        print("No save file found")
        usage(argv[0], 0)
    try:
        opts, args = getopt.getopt(argv[1:],"ho:")
    except getopt.GetoptError:
        usge(argv[0], 2)
    else:
        for opt, arg in opts:
            if opt == 'h':
                usge(argv[0], 0)
            elif opt == '-o':
                output_dir = os.path.abspath(arg)
                save_file = os.path.join(output_dir, "addons.lst")
        if not os.path.exists(output_dir):
            print(output_dir + ": path doesn't exist\nEnd of program")
            error += 1
        collections_id_list = argv[len(opts) * 2 + 1:]
    return error, output_dir, collections_id_list, save_file 
开发者ID:Geam,项目名称:steam_workshop_downloader,代码行数:36,代码来源:workshop.py

示例9: run

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def run(self, args):
    rid = RegressiveImageryDictionary()
    load_default_dict = True
    load_default_exc = True
    html_output = False
    title = "RID Analysis"

    try:
      optlist, args = getopt.getopt(sys.argv[1:], 'd:e:ht:',
                                    ['add-dict=', 'add-exc='])
      for (o, v) in optlist:
        if o == '-d':
          rid.load_dictionary_from_file(v)
          load_default_dict = False
        elif o == '-e':
          rid.load_exclusion_list_from_file(v)
          load_default_exc = False
        elif o == '--add-dict':
          rid.load_dictionary_from_file(v)
        elif o == '--add-exc':
          rid.load_exclusion_list_from_file(v)
        elif o == '-h':
          html_output = True
        elif o == '-t':
          title = v
        else:
          sys.stderr.write("%s: illegal option '%s'\n" % (args[0], o))
          self.usage(args)
    except getopt.GetoptError, e:
      sys.stderr.write("%s: %s\n" % (args[0], e.msg))
      self.usage(args)
      sys.exit(1) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:34,代码来源:rid.py

示例10: main

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def main(argv):
    trainIds = False
    try:
        opts, args = getopt.getopt(argv,"ht")
    except getopt.GetoptError:
        printError( 'Invalid arguments' )
    for opt, arg in opts:
        if opt == '-h':
            printHelp()
            sys.exit(0)
        elif opt == '-t':
            trainIds = True
        else:
            printError( "Handling of argument '{}' not implementend".format(opt) )

    if len(args) == 0:
        printError( "Missing input json file" )
    elif len(args) == 1:
        printError( "Missing output image filename" )
    elif len(args) > 2:
        printError( "Too many arguments" )

    inJson = args[0]
    outImg = args[1]

    if trainIds:
        json2instanceImg( inJson , outImg , 'trainIds' )
    else:
        json2instanceImg( inJson , outImg )

# call the main method 
开发者ID:pierluigiferrari,项目名称:fcn8s_tensorflow,代码行数:33,代码来源:json2instanceImg.py

示例11: main

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def main(argv):
    trainIds = False
    try:
        opts, args = getopt.getopt(argv,"ht")
    except getopt.GetoptError:
        printError( 'Invalid arguments' )
    for opt, arg in opts:
        if opt == '-h':
            printHelp()
            sys.exit(0)
        elif opt == '-t':
            trainIds = True
        else:
            printError( "Handling of argument '{}' not implementend".format(opt) )

    if len(args) == 0:
        printError( "Missing input json file" )
    elif len(args) == 1:
        printError( "Missing output image filename" )
    elif len(args) > 2:
        printError( "Too many arguments" )

    inJson = args[0]
    outImg = args[1]

    if trainIds:
        json2labelImg( inJson , outImg , "trainIds" )
    else:
        json2labelImg( inJson , outImg )

# call the main method 
开发者ID:pierluigiferrari,项目名称:fcn8s_tensorflow,代码行数:33,代码来源:json2labelImg.py

示例12: main

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def main():
    try:
        options, args = getopt.getopt(sys.argv[1:], ["help"])
    except getopt.GetoptError as e:
        pass

    match = re.findall(r'[\w.]+', " ".join(args).lower())
    words = "_".join(match)
    response = get_response(words)
    if not response:
        return
    root = read_xml(response)
    show(root) 
开发者ID:Flowerowl,项目名称:ici,代码行数:15,代码来源:ici.py

示例13: main

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def main(argv):
    smali_path = ''
    output_path = ''

    try:
        opts, args = getopt.getopt(argv,"ha:o:")
    except getopt.GetoptError:
        print_help()
        sys.exit(2)

    if (not opts):
        print_help()
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            print_help()
            sys.exit()
        elif opt == '-a':
            smali_path = arg
        elif opt == '-o':
            output_path = arg
        
    if (not smali_path or not output_path):
        print_help()
        sys.exit()

    output_path = convert_path(output_path)
    smali_path = convert_path(smali_path)
    output_path = os.path.join(output_path, 'output')
    
    print('Start parsing entry path:' + str(smali_path))
    parse_dir(smali_path)
    print('Total split:' + str(cur_dex_num))
    split_smali_files(smali_path, output_path)
    compile_smali(output_path) 
开发者ID:DXCyber409,项目名称:py3util,代码行数:38,代码来源:smali_split.py

示例14: main

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def main(argv):
    app_unzip_path = ''
    smali_output_path = ''
    mode = ''

    try:
        opts, args = getopt.getopt(argv,"hd:o:m:")
    except getopt.GetoptError:
        print_help()
        sys.exit(2)

    if (not opts):
        print_help()
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            print_help()
            sys.exit()
        elif opt == '-d':
            app_unzip_path = arg
        elif opt == '-o':
            smali_output_path = arg
        elif opt == '-m' and arg in ('one', 'each'):
            mode = arg
        
    if (not app_unzip_path or not smali_output_path or not mode):
        print_help()
        sys.exit()
    
    dex_files = list_dexfile(app_unzip_path)
    print('dex file list:' + str(dex_files))
    if (not dex_files):
        print('dex file list empty!')
        sys.exit()
    
    if (mode == 'each'):
        smali_dex(dex_files, app_unzip_path, smali_output_path)
    elif (mode == 'one'):
        smali_dex_all_in_one(dex_files, app_unzip_path, smali_output_path) 
开发者ID:DXCyber409,项目名称:py3util,代码行数:42,代码来源:smali_decompile.py

示例15: cli_opts

# 需要导入模块: import getopt [as 别名]
# 或者: from getopt import GetoptError [as 别名]
def cli_opts(argv, inp, call_conv):
  import sys, getopt
  
  def print_ft_exit():
    print call_conv
    sys.exit(2)
    
  try:
    opts, args = getopt.getopt(argv, ':'.join(inp.keys()) + ':')
  except getopt.GetoptError as e:
    print_ft_exit()
    print e
  except Exception as e:
    print e
    
  if len(opts) != len(inp):
    print 'Invalid option count'
    print_ft_exit()
  
  out = { }
  for opt, arg in opts:
    if opt in inp.keys():
      if inp[opt][0](arg):
        out[opt] = inp[opt][1](arg)
      else:
        print 'Invalid input type for argument %s' % opt
        print_ft_exit()
    else:
      print 'No option of form %s' % opt
      print_ft_exit()
    
  return out 
开发者ID:robhowley,项目名称:nhlscrapi,代码行数:34,代码来源:gamedata.py


注:本文中的getopt.GetoptError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。