<s> magic = '<STR_LIT>' <EOL> """<STR_LIT>""" <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> if sys . argv [ - <NUM_LIT:1> ] == '<STR_LIT>' % magic : <EOL> del sys . argv [ - <NUM_LIT:1> ] <EOL> del magic <EOL> import optparse <EOL> import os <EOL> import re <EOL> import sys <EOL> from trace import SetTrace <EOL> from git_config import init_ssh , close_ssh <EOL> from command import InteractiveCommand <EOL> from command import MirrorSafeCommand <EOL> from command import PagedCommand <EOL> from error import ManifestInvalidRevisionError <EOL> from error import NoSuchProjectError <EOL> from error import RepoChangedException <EOL> from pager import RunPager <EOL> from subcmds import all as all_commands <EOL> global_options = optparse . OptionParser ( <EOL> usage = "<STR_LIT>" <EOL> ) <EOL> global_options . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> global_options . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> global_options . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> global_options . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> class _Repo ( object ) : <EOL> def __init__ ( self , repodir ) : <EOL> self . repodir = repodir <EOL> self . commands = all_commands <EOL> all_commands [ '<STR_LIT>' ] = all_commands [ '<STR_LIT>' ] <EOL> def _Run ( self , argv ) : <EOL> name = None <EOL> glob = [ ] <EOL> for i in xrange ( <NUM_LIT:0> , len ( argv ) ) : <EOL> if not argv [ i ] . startswith ( '<STR_LIT:->' ) : <EOL> name = argv [ i ] <EOL> if i > <NUM_LIT:0> : <EOL> glob = argv [ : i ] <EOL> argv = argv [ i + <NUM_LIT:1> : ] <EOL> break <EOL> if not name : <EOL> glob = argv <EOL> name = '<STR_LIT>' <EOL> argv = [ ] <EOL> gopts , gargs = global_options . parse_args ( glob ) <EOL> if gopts . trace : <EOL> SetTrace ( ) <EOL> if gopts . show_version : <EOL> if name == '<STR_LIT>' : <EOL> name = '<STR_LIT:version>' <EOL> else : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> try : <EOL> cmd = self . commands [ name ] <EOL> except KeyError : <EOL> print >> sys . stderr , "<STR_LIT>" % name <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> cmd . repodir = self . repodir <EOL> if not isinstance ( cmd , MirrorSafeCommand ) and cmd . manifest . IsMirror : <EOL> print >> sys . stderr , "<STR_LIT>" % name <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> copts , cargs = cmd . OptionParser . parse_args ( argv ) <EOL> if not gopts . no_pager and not isinstance ( cmd , InteractiveCommand ) : <EOL> config = cmd . manifest . globalConfig <EOL> if gopts . pager : <EOL> use_pager = True <EOL> else : <EOL> use_pager = config . GetBoolean ( '<STR_LIT>' % name ) <EOL> if use_pager is None : <EOL> use_pager = cmd . WantPager ( copts ) <EOL> if use_pager : <EOL> RunPager ( config ) <EOL> try : <EOL> cmd . Execute ( copts , cargs ) <EOL> except ManifestInvalidRevisionError , e : <EOL> print >> sys . stderr , '<STR_LIT>' % str ( e ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> except NoSuchProjectError , e : <EOL> if e . name : <EOL> print >> sys . stderr , '<STR_LIT>' % e . name <EOL> else : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def _MyWrapperPath ( ) : <EOL> return os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> def _CurrentWrapperVersion ( ) : <EOL> VERSION = None <EOL> pat = re . compile ( r'<STR_LIT>' ) <EOL> fd = open ( _MyWrapperPath ( ) ) <EOL> for line in fd : <EOL> if pat . match ( line ) : <EOL> fd . close ( ) <EOL> exec line <EOL> return VERSION <EOL> raise NameError , '<STR_LIT>' <EOL> def _CheckWrapperVersion ( ver , repo_path ) : <EOL> if not repo_path : <EOL> repo_path = '<STR_LIT>' <EOL> if not ver : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> exp = _CurrentWrapperVersion ( ) <EOL> ver = tuple ( map ( lambda x : int ( x ) , ver . split ( '<STR_LIT:.>' ) ) ) <EOL> if len ( ver ) == <NUM_LIT:1> : <EOL> ver = ( <NUM_LIT:0> , ver [ <NUM_LIT:0> ] ) <EOL> if exp [ <NUM_LIT:0> ] > ver [ <NUM_LIT:0> ] or ver < ( <NUM_LIT:0> , <NUM_LIT:4> ) : <EOL> exp_str = '<STR_LIT:.>' . join ( map ( lambda x : str ( x ) , exp ) ) <EOL> print >> sys . stderr , """<STR_LIT>""" % ( exp_str , _MyWrapperPath ( ) , repo_path ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if exp > ver : <EOL> exp_str = '<STR_LIT:.>' . join ( map ( lambda x : str ( x ) , exp ) ) <EOL> print >> sys . stderr , """<STR_LIT>""" % ( exp_str , _MyWrapperPath ( ) , repo_path ) <EOL> def _CheckRepoDir ( dir ) : <EOL> if not dir : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def _PruneOptions ( argv , opt ) : <EOL> i = <NUM_LIT:0> <EOL> while i < len ( argv ) : <EOL> a = argv [ i ] <EOL> if a == '<STR_LIT>' : <EOL> break <EOL> if a . startswith ( '<STR_LIT>' ) : <EOL> eq = a . find ( '<STR_LIT:=>' ) <EOL> if eq > <NUM_LIT:0> : <EOL> a = a [ <NUM_LIT:0> : eq ] <EOL> if not opt . has_option ( a ) : <EOL> del argv [ i ] <EOL> continue <EOL> i += <NUM_LIT:1> <EOL> def _Main ( argv ) : <EOL> opt = optparse . OptionParser ( usage = "<STR_LIT>" ) <EOL> opt . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> opt . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> opt . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> _PruneOptions ( argv , opt ) <EOL> opt , argv = opt . parse_args ( argv ) <EOL> _CheckWrapperVersion ( opt . wrapper_version , opt . wrapper_path ) <EOL> _CheckRepoDir ( opt . repodir ) <EOL> repo = _Repo ( opt . repodir ) <EOL> try : <EOL> try : <EOL> init_ssh ( ) <EOL> repo . _Run ( argv ) <EOL> finally : <EOL> close_ssh ( ) <EOL> except KeyboardInterrupt : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> except RepoChangedException , rce : <EOL> argv = list ( sys . argv ) <EOL> argv . extend ( rce . extra_args ) <EOL> try : <EOL> os . execv ( __file__ , argv ) <EOL> except OSError , e : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> print >> sys . stderr , '<STR_LIT>' % e <EOL> sys . exit ( <NUM_LIT> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> _Main ( sys . argv [ <NUM_LIT:1> : ] ) </s>
