Package acis_xmlrpc :: Module options
[hide private]
[frames] | no frames]

Source Code for Module acis_xmlrpc.options

 1  """ 
 2  Definitions of options that ACIS XML-RPC server accepts. 
 3  @since: May 2007 
 4  @author: Grant Kelly 
 5  """ 
 6   
 7  from optparse import Option, OptionParser 
 8   
 9  # A list of 2-tuples where 0 is a tuple of string keys (positional arguments) 
10  # and 1 is a dictionary of named arguments to parser.add_option. 
11  base_options = [ 
12  ( ("--help", "-h"),  
13      { 'action': "store_true", 'dest': "help", 'help': "Prints help menu."} ), 
14  ( ("--stn",),  
15      { 'dest': "stn", 'help': "Comma-separated list of station IDs"} ), 
16  ( ("--stntype",),  
17      { 'dest': "stntype", 'help': "Comma-separated list of station ID types"} ), 
18  ( ("--start",), 
19      { 'dest': "start", 'help': "YYYYMMDD format"} ), 
20  ( ("--end",), 
21      { 'dest': "end", 'help': "YYYYMMDD format"} ), 
22  ( ("--var",), 
23      { 'dest': "var", 'help': "Comma-separated list of data elements [example: --var tmax,tmin]"} ), 
24  ( ("--varstats",), 
25      { 'action': "store_true", 'dest': "varstats", 'help': "Give some statistics related to each var, like valid start and end dates."} ), 
26  ( ("--format",), 
27      { 'dest': "format", 'help': "Output format: [csv | tab | json | space | pipe ]" } ), 
28  ( ("--dateformat",), 
29      { 'dest': "dateformat", 'help': "Output format of the date: [ YYYYMMDD | MMDDYYYY | DDMMYYYY]"} ), 
30  ( ("--allow-incomplete",), 
31      { 'action': "store_true", 'dest': "allow_incomplete", 'help': "Allow an incomplete record to be summarized, otherwise returns missing."} ), 
32  ( (), 
33      {} ), 
34  ] 
35   
36 -def build_parser(options=base_options):
37 """ 38 Given a list of 2-tuple options, return an option parser 39 """ 40 parser = OptionParser(usage=" ",add_help_option=False) 41 for ops in options: 42 if ops[0]: 43 parser.add_option(*ops[0], **ops[1]) 44 return parser
45 46 47 48 49 # If run as main, run some tests 50 if __name__ == '__main__': 51 parser = build_parser(base_options) 52 inputs = [ 53 "--stn 123,456 --stntype coop,shef --start 20060101 --end 20061231 --var tmax,tmin", 54 "--stn=123 --start 20060101 --end=20061231 --var tmax", 55 "--stn 123 --start 20060101 --end --var tmax", 56 ] 57 for input in inputs: 58 options, args = parser.parse_args(input.split()) 59 print "GOT: ", input 60 print "SEE:" 61 print options 62 print args 63