Changeset 2605

Show
Ignore:
Timestamp:
12/05/05 14:15:17 (18 years ago)
Author:
jerome
Message:

Now all command line tools accept the -A | --arguments command line
option to specify the name of a file containing one argument per line.
NB : all other arguments are ignored, only the ones read from the file
are used for now.
This allows people to bypass the maximal command line's size, to
add several thousand users with a single command for example.

Location:
pykota/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/NEWS

    r2600 r2605  
    2424    - 1.24alpha5 : 
    2525     
     26        - All command line tools now accept -A | --arguments filename.args 
     27          as a way to bypass the shell's maximal command line size : 
     28          just put each argument on a line by itself in a file, and 
     29          pass the file's name as the -A | --arguments command line 
     30          option's argument. For now this won't be documented in 
     31          commands' helps. 
     32           
    2633        - dumpykota can now dump the complete database in XML  
    2734          format. 
  • pykota/trunk/pykota/tool.py

    r2558 r2605  
    254254        """Parses the command line, controlling options.""" 
    255255        # split options in two lists: those which need an argument, those which don't need any 
     256        short = "%sA:" % short 
     257        long.append("arguments=") 
    256258        withoutarg = [] 
    257259        witharg = [] 
     
    277279                withoutarg.append(option) 
    278280         
    279         # we begin with all possible options unset 
    280         parsed = {} 
    281         for option in withoutarg + witharg : 
    282             parsed[option] = None 
    283          
    284281        # then we parse the command line 
    285         args = []       # to not break if something unexpected happened 
    286         try : 
    287             options, args = getopt.getopt(argv, short, long) 
    288             if options : 
    289                 for (o, v) in options : 
    290                     # we skip the '-' chars 
    291                     lgo = len(o) 
    292                     i = 0 
    293                     while (i < lgo) and (o[i] == '-') : 
    294                         i = i + 1 
    295                     o = o[i:] 
    296                     if o in witharg : 
    297                         # needs an argument : set it 
    298                         parsed[o] = v 
    299                     elif o in withoutarg : 
    300                         # doesn't need an argument : boolean 
    301                         parsed[o] = 1 
    302                     else : 
    303                         # should never occur 
    304                         raise PyKotaToolError, "Unexpected problem when parsing command line" 
    305             elif (not args) and (not allownothing) and sys.stdin.isatty() : # no option and no argument, we display help if we are a tty 
     282        done = 0 
     283        while not done : 
     284            # we begin with all possible options unset 
     285            parsed = {} 
     286            for option in withoutarg + witharg : 
     287                parsed[option] = None 
     288            args = []       # to not break if something unexpected happened 
     289            try : 
     290                options, args = getopt.getopt(argv, short, long) 
     291                if options : 
     292                    for (o, v) in options : 
     293                        # we skip the '-' chars 
     294                        lgo = len(o) 
     295                        i = 0 
     296                        while (i < lgo) and (o[i] == '-') : 
     297                            i = i + 1 
     298                        o = o[i:] 
     299                        if o in witharg : 
     300                            # needs an argument : set it 
     301                            parsed[o] = v 
     302                        elif o in withoutarg : 
     303                            # doesn't need an argument : boolean 
     304                            parsed[o] = 1 
     305                        else : 
     306                            # should never occur 
     307                            raise PyKotaToolError, "Unexpected problem when parsing command line" 
     308                elif (not args) and (not allownothing) and sys.stdin.isatty() : # no option and no argument, we display help if we are a tty 
     309                    self.display_usage_and_quit() 
     310            except getopt.error, msg : 
     311                self.printInfo(msg) 
    306312                self.display_usage_and_quit() 
    307         except getopt.error, msg : 
    308             self.printInfo(msg) 
    309             self.display_usage_and_quit() 
     313            else :     
     314                if parsed["arguments"] or parsed["A"] : 
     315                    # arguments are in a file, we ignore all other arguments 
     316                    # and reset the list of arguments to the lines read from 
     317                    # the file. 
     318                    argsfile = open(parsed["arguments"] or parsed["A"], "r") 
     319                    argv = [ l.strip() for l in argsfile.readlines() ] 
     320                    argsfile.close() 
     321                    for i in range(len(argv)) : 
     322                        argi = argv[i] 
     323                        if argi.startswith('"') and argi.endswith('"') : 
     324                            argv[i] = argi[1:-1] 
     325                else :     
     326                    done = 1 
    310327        return (parsed, args) 
    311328