-í
U‹<c       sI  d  Z  d Z d k Z d k Z d k Z d k Z d k Z d k Z d k Z d „  Z	 d d „ Z
 d „  Z e
 Z e i d ƒ Z e i d ƒ Z e i e e d	 „ Z e i i e i i e i i e i d
 „ Z d f  d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d f  d „  ƒ  YZ e Z d „  Z e d j o e ƒ  n d S(   s   CommandLine - Get and parse command line options

    NOTE: This still is very much work in progress !!!

    Different version are likely to be incompatible.

    TODO:

    · Incorporate the changes made by (see Inbox)
    · Add number range option using srange() 

    Copyright (c) 1997-2001, Marc-Andre Lemburg; mailto:mal@lemburg.com
    Copyright (c) 2000-2001, eGenix.com Software GmbH; mailto:info@egenix.com
    See the documentation for further information on copyrights,
    or contact the author. All Rights Reserved.
s   1.0Nc    s¨   g  } g  } x |  D]w } | i d j o/ | i | i ƒ | i o | i d ƒ n n3 | i o | i | i d ƒ n | i | i ƒ q Wt i	 | d ƒ | f Sd S(   sP    Convert the option list to a getopt flag string and long opt
        list

    s   -s   :s   =s    N(
   s   ss   ls   optionss   os   prefixs   appends   names   takes_arguments   strings   join(   s   optionss   ss   os   l(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   _getopt_flags s      

s   >>> c    s7   d k  } | i  |  ƒ } | t j o
 t ‚ n | Sd S(   sw    Get raw input from a terminal without echoing the characters to
        the terminal, e.g. for password queries.

    N(   s   getpasss   prompts   entrys   Nones   KeyboardInterrupt(   s   prompts   getpasss   entry(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   invisible_input. s     	
c    s,   h  } x |  D] } | | | i <q W| Sd S(   sC    Return a dictionary mapping option names to Option instances.
    N(   s   ds   optionss   options   name(   s   optionss   options   d(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   option_dict: s      s   \s*(-?\d+)\s*$s   \s*(-?\d+)\s*-\s*(-?\d+)\s*$c 
   sº   g  } | i }	 x  | |  d ƒ D] } | i | ƒ } | o! |	 t | i	 ƒ  d ƒ ƒ q n | i | ƒ } | o< t t | i	 ƒ  ƒ \ } } t | | d ƒ | t | ƒ )n q W| Sd S(   sö    Converts a textual representation of integer numbers and ranges
        to a Python list.

        Supported formats: 2,3,4,2-10,-1 - -3, 5 - -2

        Values are appended to the created list in the order specified
        in the string.

    s   ,i    i   N(   s   ls   appends   splits   ss   entrys   integers   matchs   ms   ints   groupss   integerRanges   maps   starts   ends   ranges   len(
   s   ss   splits   integers   integerRanges   ends   starts   ms   ls   entrys   append(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   srangeI s     	 %c    s`   y | |  ƒ }  Wn t j
 o n Xy | |  ƒ }  Wn t j
 o n X| | ƒ  |  ƒ Sd S(   s§    Return the corresponding absolute path for path.

        path is expanded in the usual shell ways before
        joining it with the current working directory.

    N(   s
   expandvarss   paths   AttributeErrors
   expandusers   joins   getcwd(   s   paths
   expandvarss
   expandusers   joins   getcwd(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   abspathd s    
 s   Optionc      sG   t  Z d  Z e Z d Z d Z d Z d Z d Z	 e d „ Z
 d „  Z RS(   s,    Option base class. Takes no argument.

    s    s   -i    i   c    sr   | d  d j o t d ‚ n | d d !d j o d |  _ | d |  _  n | d |  _  | o | |  _ n d  S(   Ni   s   -s    option names must start with "-"i   s   --(   s   names	   TypeErrors   selfs   prefixs   help(   s   selfs   names   help(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   __init__‡ s    	c    s»   |  } | i | i } | i o | d } n t | ƒ |  i j o* | d d |  i d t | i ƒ } n d |  i | f } | i } | i	 o | d | i
 } n d | | f Sd  S(   Ns    args   
s    i   s   %-*s s    (%s)s   %s %s(   s   selfs   os   prefixs   names   takes_arguments   lens   tabs   helps   descriptions   has_defaults   default(   s   selfs   names   os   description(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   __str__“ s    
*	
(   s   __name__s
   __module__s   __doc__s   Nones   defaults   helptexts   prefixs   takes_arguments   has_defaults   tabs   __init__s   __str__(    (    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   Option{ s    s   ArgumentOptionc      s   t  Z d  Z e e d „ Z RS(   sa    Option that takes an argument.

        An optional default argument can be given.
        
    c    sC   t  i |  | | ƒ | t j	 o | |  _ d |  _ n d |  _ d  S(   Ni   (	   s   Options   __init__s   selfs   names   helps   defaults   Nones   has_defaults   takes_argument(   s   selfs   names   helps   default(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   __init__© s
    	(   s   __name__s
   __module__s   __doc__s   Nones   __init__(    (    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   ArgumentOption¢ s    s   SwitchOptionc      s   t  Z d  Z e e d „ Z RS(   sD    Options that can be on or off. Has an optional default value.

    c    s:   t  i |  | | ƒ | t j	 o | |  _ d |  _ n d  S(   Ni   (   s   Options   __init__s   selfs   names   helps   defaults   Nones   has_default(   s   selfs   names   helps   default(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   __init__¸ s    	(   s   __name__s
   __module__s   __doc__s   Nones   __init__(    (    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   SwitchOption³ s    s   Applicationc      sU  t  Z d  Z g  Z e d d ƒ e d d ƒ e d d ƒ e d d ƒ e d d	 ƒ e d
 d ƒ g Z d Z d Z d Z d Z	 d Z
 d Z d Z d Z d Z d Z e Z e Z e d „ Z d „  Z d „  Z d d „ Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d  „  Z" d! „  Z# d" „  Z$ RS(#   sP    Command line application interface with builtin argument
        parsing.

    s   -vs   generate verbose outputs   -hs   show this help texts   --helps   --debugs   enable debuggings   --copyrights   show copyrights
   --exampless   show examples of usages    s   %(name)s [option] files...s6  Copyright (c) 1997-2001, Marc-Andre Lemburg; mailto:mal@lemburg.com
Copyright (c) 2000-2001, eGenix.com Software GmbH; mailto:info@egenix.com
See the documentation for further information on copyrights,
or contact the author. All Rights Reserved.
*** UNAUTHORIZED COPYING, USAGE or DISTRIBUTION PROHIBITED. ***i   i    c    sÝ  | t j o t i  } n t i i | d ƒ d |  _ |  i o  t i i |  i ƒ d |  _ n |  i |  _ |  i	 o |  i |  _	 n |  i	 |  _	 | d |  _
 t |  i ƒ |  _ x9 |  i D]. } |  i i | i ƒ o |  i | ƒ n q¾ Wg  |  _ ys |  i ƒ  } | t j	 o t | ‚ n |  i ƒ  } | t j	 o t | ‚ n |  i ƒ  } | t j o
 d } n Wna t j
 o	 } nN t j
 o Hd GHd } n0 Hd GH|  i o Ht i d ƒ n d } n Xt | ‚ d  S(   Ni    i   s   * User Breaks   * Internal Errori   (   s   argvs   Nones   syss   oss   paths   splits   selfs   filenames   names   headers	   argumentss   option_dicts   optionss
   option_maps   preset_optionss   options   has_keys
   add_options   filess   startups   rcs
   SystemExits   parses   mains   KeyboardInterrupts   debugs	   tracebacks	   print_exc(   s   selfs   argvs   options   rc(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   __init__sP     
 	


c    s$   |  i i | ƒ | |  i | i <d S(   s¨    Add a new Option instance to the Application dynamically.

            Note that this has to be done *before* .parse() is being
            executed.
        
        N(   s   selfs   optionss   appends   options
   option_maps   name(   s   selfs   option(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys
   add_optionNs     c    s   t  Sd S(   s·    Set user defined instance variables.

            If this method returns anything other than None, the
            process is terminated with the return value as exit code.

        N(   s   None(   s   self(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   startupYs     c    s   t  | ‚ d S(   sŸ    Exit the program.

            rc is used as exit code and passed back to the calling
            program. It defaults to 0 which usually means: OK.

        N(   s
   SystemExits   rc(   s   selfs   rc(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   exitcs     c    s™  h  |  _ } xJ |  i D]? } | i o | i | | i | i <n d | | i | i <q Wt |  i ƒ \ } } yž t i |  i | | ƒ \ } } |  i oY g  } xF | D]> } t i | ƒ } | o | i | ƒ n | | t | ƒ )q§ W| } n | |  _ | |  i |  _ Wn2 t i j
 o# } |  i | ƒ t i d ƒ n X|  i |  i ƒ } | t j	 o t i | ƒ n xð | D]è \ } }	 y t! i" |	 ƒ }	 Wn t# j
 o n Xd t! i$ | d d ƒ } y t& |  | ƒ }
 Wn^ t( j
 oR |	 d j o4 | i) | ƒ o | | d | | <n d | | <n |	 | | <n( X|
 |	 ƒ } | t j	 o t* | ‚ n qyW|  i+ |  i ƒ } | t j	 o t i | ƒ n d S(   sx   Parse the command line and fill in self.values and self.files.

            After having parsed the options, the remaining command line
            arguments are interpreted as files and passed to .handle_files()
            for processing.

            As final step the option handlers are called in the order
            of the options given on the command line.

        i    i   s   handles   -s   _s    N(,   s   selfs   valuess   optionss   os   has_defaults   defaults   prefixs   names   _getopt_flagss   flagss   lflagss   getopts	   argumentss   optlists   filess   globbings   ls   fs   globs   gfs   appends   lens
   optionlists   errors   whys   helps   syss   exits   handle_filess   rcs   Nones
   optionnames   values   strings   atois
   ValueErrors   replaces   handlernames   getattrs   handlers   AttributeErrors   has_keys
   SystemExits   check_files(   s   selfs   filess   gfs   os
   optionnames   whys   optlists   fs   ls   values   handlers   valuess   handlernames   rcs   flagss   lflags(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   parsems`     
 

 
	 c    s   t  Sd S(   sh   Apply some user defined checks on the files given in filelist.

            This may modify filelist in place. A typical application
            is checking that at least n files are given.
            
            If this method returns anything other than None, the
            process is terminated with the return value as exit code.
            
        N(   s   None(   s   selfs   filelist(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   check_files¸s    
 c    sÝ   |  i ƒ  |  i oU d GHy |  i |  i } Wn, t t t f j
 o |  i |  i } n Xd | GHn H|  i ƒ  |  i	 o d GHd |  i	 GHHn |  i
 o t i |  i
 |  i ƒ GHHn | o d d GHd G| GHHn d  S(   Ns	   Synopsis:s    s   Version:s    %ss   -iH   s   Note:(   s   selfs   print_headers   synopsiss   names	   NameErrors   KeyErrors	   TypeErrors   __dict__s   print_optionss   versions   abouts   strings   strips   note(   s   selfs   notes   synopsis(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   helpÅs*    




		c    s    d d GHd G| GHd d GHHd  S(   Ns   -iH   s   Note:(   s   note(   s   selfs   note(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   noticeÞs    			c    s&   d d GH|  i |  i GHd d GHHd  S(   Ns   -iH   (   s   selfs   headers   __dict__(   s   self(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   print_headerås    		c    sp   |  i } d GH| o d GHd  Sn t d „  | ƒ } t d „  | ƒ } | | } x | D] } d G| GHqX WHd  S(   Ns   Options and default settings:s     Nonec    s   |  i d j S(   Ns   --(   s   xs   prefix(   s   x(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   <lambda>ós    c    s   |  i d j S(   Ns   -(   s   xs   prefix(   s   x(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   <lambda>ôs    s    (   s   selfs   optionss   filters   longs   shorts   itemss   o(   s   selfs   shorts   os   itemss   optionss   long(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   print_optionsìs    	
 c    s   t  Sd S(   s3    This may process the files list in place.
        N(   s   None(   s   selfs   files(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   handle_filess     c    s   |  i ƒ  d Sd  S(   Ni    (   s   selfs   help(   s   selfs   arg(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   handle_h	s    
c    s   d |  _ d S(   s!    Turn on verbose output.
        i   N(   s   selfs   verbose(   s   selfs   value(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   handle_vs     c    s   |  i ƒ  d Sd  S(   Ni    (   s   selfs   help(   s   selfs   arg(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   handle__helps    
c    s   d |  _ d  S(   Ni   (   s   selfs   debug(   s   selfs   arg(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   handle__debugs    c    s+   |  i ƒ  t i |  i |  i ƒ GHHd Sd  S(   Ni    (   s   selfs   print_headers   strings   strips	   copyrights   __dict__(   s   selfs   arg(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   handle__copyrights    
c    sE   |  i ƒ  |  i o# d GHHt i |  i |  i ƒ GHHn d GHHd Sd  S(   Ns	   Examples:s   No examples available.i    (   s   selfs   print_headers   exampless   strings   strips   __dict__(   s   selfs   arg(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   handle__examples%s    

c    s   t  Sd S(   s3   Override this method as program entry point.

            The return value is passed to sys.exit() as argument.  If
            it is None, 0 is assumed (meaning OK). Unhandled
            exceptions are reported with exit status code 1 (see
            __init__ for further details).
            
        N(   s   None(   s   self(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   main2s    	 (%   s   __name__s
   __module__s   __doc__s   optionss   SwitchOptions   preset_optionss   headers   names   synopsiss   versions   abouts   exampless	   copyrights   globbings   debugs   verboses   Nones   valuess   filess   __init__s
   add_options   startups   exits   parses   check_filess   helps   notices   print_headers   print_optionss   handle_filess   handle_hs   handle_vs   handle__helps   handle__debugs   handle__copyrights   handle__exampless   main(    (    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   ApplicationÃ sB    N	@		

	K											c     sQ   d t  f d „  ƒ  Y} | ƒ  }  |  i d o |  i ƒ  n d G|  i GHd GHd  S(   Ns   MyApplicationc      s/   t  Z d Z e Z e d d ƒ g Z d „  Z RS(   Ns   Test Applications   -vs   verbosec    s	   d GHd  S(   Ns   VERBOSE, Yeah !(    (   s   selfs   arg(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   handle_vHs    (   s   __name__s
   __module__s   headers   __version__s   versions   Options   optionss   handle_v(    (    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   MyApplicationCs   s   -hs   files:s   Bye...(   s   Applications   MyApplications   cmds   valuess   helps   files(   s   cmds   MyApplication(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   _testAs    	s   __main__(   s   __doc__s   __version__s   syss   getopts   strings   globs   oss	   tracebacks   res   _getopt_flagss   invisible_inputs   option_dicts	   getpasswds   compiles
   _integerREs   _integerRangeREs   splits   sranges   paths
   expandvarss
   expandusers   joins   getcwds   abspaths   Options   ArgumentOptions   SwitchOptions   Applications   CommandLines   _tests   __name__(   s
   _integerREs   sranges   strings   invisible_inputs   abspaths   globs   SwitchOptions   _integerRangeREs   syss   Applications   _getopt_flagss   ArgumentOptions   __version__s   Options   option_dicts	   tracebacks   res   getopts   _tests	   getpasswds   oss   CommandLine(    (    s=   /mit/seven/lib/python2.2/site-packages/mx/Misc/CommandLine.pys   ? s&   ?		
*'ÿ }	