Пример #1
0
 def load_args_from_file(argfile):
     try:
         with open(argfile) as arg_f:
             args = [arg for line in arg_f for arg in line.split()]
             if '-A' in args or '--argumentfile' in args:
                 raise NestedArgumentFileError(argfile)
             return args
     except FileNotFoundError:
         raise ArgumentFileNotFoundError(argfile)
Пример #2
0
 def load_args_from_file(self, argfile):
     try:
         with open(argfile) as arg_f:
             args = [arg.strip() for line in arg_f for arg in line.split(' ', 1)]
             if '-A' in args or '--argumentfile' in args:
                 raise NestedArgumentFileError(argfile)
             self.config_from = argfile
             return args
     except FileNotFoundError:
         raise ArgumentFileNotFoundError(argfile) from None
Пример #3
0
 def preparse(self, args):
     args = sys.argv[1:] if args is None else args
     parsed_args = []
     args = (arg for arg in args)
     for arg in args:
         if arg in ('-A', '--argumentfile'):
             try:
                 argfile = next(args)
             except StopIteration:
                 raise ArgumentFileNotFoundError('')
             parsed_args += self.load_args_from_file(argfile)
         else:
             parsed_args.append(arg)
     return parsed_args
Пример #4
0
 def load_args_from_file(self, argfile):
     try:
         with FileReader(argfile) as arg_f:
             args = []
             for line in arg_f.readlines():
                 if line.strip().startswith("#"):
                     continue
                 for arg in line.split(" ", 1):
                     arg = arg.strip()
                     if not arg:
                         continue
                     args.append(arg)
             if "-A" in args or "--argumentfile" in args:
                 raise NestedArgumentFileError(argfile)
             if args:
                 self.config_from = argfile
             return args
     except FileNotFoundError:
         raise ArgumentFileNotFoundError(argfile) from None