Changeset 3339 for pykota

Show
Ignore:
Timestamp:
02/18/08 23:08:30 (17 years ago)
Author:
jerome
Message:

Can now add filtering expressions as part of the generated help.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/commandline.py

    r3337 r3339  
    7575        Initializes our option parser with additional attributes. 
    7676        """ 
     77        self.filterexpressions = [] 
    7778        self.examples = [] 
    7879        kwargs["version"] = "%s (PyKota) %s" % (os.path.basename(sys.argv[0]), 
     
    9293        result = [] 
    9394        result.append(optparse.OptionParser.format_help(self, formatter) + "\n") 
     95        result.append(self.format_filterexpressions()) 
    9496        result.append(self.format_examples()) 
    9597        result.append(self.format_copyright()) 
     
    99101    # Below are PyKota specific additions     
    100102    # 
     103    def format_filterexpressions(self, formatter=None) : 
     104        """Formats filter expressions our way.""" 
     105        if formatter is None : 
     106            formatter = self.formatter 
     107        result = []     
     108        if self.filterexpressions : 
     109            result.append(formatter.format_heading(_("filtering expressions"))) 
     110            formatter.indent() 
     111            result.append(formatter.format_description(_("Use the filtering expressions to extract only parts of the datas. Allowed filters are of the form 'key=value'."))) 
     112            result.append("\n") 
     113            result.append(formatter.format_heading(_("allowed keys for now"))) 
     114            formatter.indent()  
     115            for (expression, explanation) in self.filterexpressions : 
     116                result.append(formatter.format_description("%s : %s" % (expression, explanation))) 
     117            formatter.dedent()     
     118            result.append("\n") 
     119            result.append(formatter.format_heading(_("formatting of dates with the 'start' and 'end' filtering keys"))) 
     120            formatter.indent() 
     121            result.append(formatter.format_description(_("YYYY : year boundaries"))) 
     122            result.append(formatter.format_description(_("YYYYMM : month boundaries"))) 
     123            result.append(formatter.format_description(_("YYYYMMDD : day boundaries"))) 
     124            result.append(formatter.format_description(_("YYYYMMDDhh : hour boundaries"))) 
     125            result.append(formatter.format_description(_("YYYYMMDDhhmm : minute boundaries"))) 
     126            result.append(formatter.format_description(_("YYYYMMDDhhmmss : second boundaries"))) 
     127            result.append(formatter.format_description(_("yesterday[+-N] : yesterday more or less N days (e.g. : yesterday-15)"))) 
     128            result.append(formatter.format_description(_("today[+-N] : today more or less N days (e.g. : today-15)"))) 
     129            result.append(formatter.format_description(_("tomorrow[+-N] : tomorrow more or less N days (e.g. : tomorrow-15)"))) 
     130            result.append(formatter.format_description(_("now[+-N] : now more or less N days (e.g. now-15)"))) 
     131            formatter.dedent()     
     132            result.append("\n") 
     133        return "".join(result) 
     134         
     135 
     136  #'now' and 'today' are not exactly the same since today represents the first 
     137  #or last second of the day depending on if it's used in a start= or end= 
     138  #date expression. The utility to be able to specify dates in the future is 
     139  #a question which remains to be answered :-) 
     140  # 
     141  #Contrary to other PyKota management tools, wildcard characters are not  
     142  #expanded, so you can't use them. 
     143         
    101144    def format_examples(self, formatter=None) : 
    102145        """Formats examples our way.""" 
     
    128171        return "".join(result) 
    129172         
     173    def add_filterexpression(self, expression, doc) :     
     174        """Adds a filtering expression.""" 
     175        self.filterexpressions.append((expression, doc)) 
     176         
    130177    def add_example(self, command, doc) :     
    131178        """Adds an usage example."""