<s> import os <EOL> import sys <EOL> from color import Coloring <EOL> from command import InteractiveCommand , MirrorSafeCommand <EOL> from error import ManifestParseError <EOL> from project import SyncBuffer <EOL> from git_command import git_require , MIN_GIT_VERSION <EOL> from manifest_submodule import SubmoduleManifest <EOL> from manifest_xml import XmlManifest <EOL> from subcmds . sync import _ReloadManifest <EOL> class Init ( InteractiveCommand , MirrorSafeCommand ) : <EOL> common = True <EOL> helpSummary = "<STR_LIT>" <EOL> helpUsage = """<STR_LIT>""" <EOL> helpDescription = """<STR_LIT>""" <EOL> def _Options ( self , p ) : <EOL> g = p . add_option_group ( '<STR_LIT>' ) <EOL> g . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> g = p . add_option_group ( '<STR_LIT>' ) <EOL> g . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> g . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> g . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = "<STR_LIT>" , <EOL> metavar = '<STR_LIT>' ) <EOL> if isinstance ( self . manifest , XmlManifest ) or not self . manifest . manifestProject . Exists : <EOL> g . add_option ( '<STR_LIT>' , '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> g . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> g . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> g = p . add_option_group ( '<STR_LIT>' ) <EOL> g . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> g . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , metavar = '<STR_LIT>' ) <EOL> g . add_option ( '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> def _ApplyOptions ( self , opt , is_new ) : <EOL> m = self . manifest . manifestProject <EOL> if is_new : <EOL> if opt . manifest_origin : <EOL> m . remote . name = opt . manifest_origin <EOL> if opt . manifest_branch : <EOL> m . revisionExpr = opt . manifest_branch <EOL> else : <EOL> m . revisionExpr = '<STR_LIT>' <EOL> else : <EOL> if opt . manifest_origin : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if opt . manifest_branch : <EOL> m . revisionExpr = opt . manifest_branch <EOL> else : <EOL> m . PreSync ( ) <EOL> def _SyncManifest ( self , opt ) : <EOL> m = self . manifest . manifestProject <EOL> is_new = not m . Exists <EOL> if is_new : <EOL> if not opt . manifest_url : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if not opt . quiet : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> print >> sys . stderr , '<STR_LIT>' % opt . manifest_url <EOL> m . _InitGitDir ( ) <EOL> self . _ApplyOptions ( opt , is_new ) <EOL> if opt . manifest_url : <EOL> r = m . GetRemote ( m . remote . name ) <EOL> r . url = opt . manifest_url <EOL> r . ResetFetch ( ) <EOL> r . Save ( ) <EOL> if opt . reference : <EOL> m . config . SetString ( '<STR_LIT>' , opt . reference ) <EOL> if opt . mirror : <EOL> if is_new : <EOL> m . config . SetString ( '<STR_LIT>' , '<STR_LIT:true>' ) <EOL> m . config . ClearCache ( ) <EOL> else : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if not m . Sync_NetworkHalf ( ) : <EOL> r = m . GetRemote ( m . remote . name ) <EOL> print >> sys . stderr , '<STR_LIT>' % r . url <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if is_new and SubmoduleManifest . IsBare ( m ) : <EOL> new = self . GetManifest ( reparse = True , type = SubmoduleManifest ) <EOL> if m . gitdir != new . manifestProject . gitdir : <EOL> os . rename ( m . gitdir , new . manifestProject . gitdir ) <EOL> new = self . GetManifest ( reparse = True , type = SubmoduleManifest ) <EOL> m = new . manifestProject <EOL> self . _ApplyOptions ( opt , is_new ) <EOL> if not is_new : <EOL> self . manifest . projects <EOL> syncbuf = SyncBuffer ( m . config ) <EOL> m . Sync_LocalHalf ( syncbuf ) <EOL> syncbuf . Finish ( ) <EOL> if isinstance ( self . manifest , XmlManifest ) : <EOL> self . _LinkManifest ( opt . manifest_name ) <EOL> _ReloadManifest ( self ) <EOL> self . _ApplyOptions ( opt , is_new ) <EOL> if not self . manifest . InitBranch ( ) : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def _LinkManifest ( self , name ) : <EOL> if not name : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> try : <EOL> self . manifest . Link ( name ) <EOL> except ManifestParseError , e : <EOL> print >> sys . stderr , "<STR_LIT>" % name <EOL> print >> sys . stderr , '<STR_LIT>' % str ( e ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def _Prompt ( self , prompt , value ) : <EOL> mp = self . manifest . manifestProject <EOL> sys . stdout . write ( '<STR_LIT>' % ( prompt , value ) ) <EOL> a = sys . stdin . readline ( ) . strip ( ) <EOL> if a == '<STR_LIT>' : <EOL> return value <EOL> return a <EOL> def _ConfigureUser ( self ) : <EOL> mp = self . manifest . manifestProject <EOL> while True : <EOL> print '<STR_LIT>' <EOL> name = self . _Prompt ( '<STR_LIT>' , mp . UserName ) <EOL> email = self . _Prompt ( '<STR_LIT>' , mp . UserEmail ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' % ( name , email ) <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> a = sys . stdin . readline ( ) . strip ( ) <EOL> if a in ( '<STR_LIT:yes>' , '<STR_LIT:y>' , '<STR_LIT:t>' , '<STR_LIT:true>' ) : <EOL> break <EOL> if name != mp . UserName : <EOL> mp . config . SetString ( '<STR_LIT>' , name ) <EOL> if email != mp . UserEmail : <EOL> mp . config . SetString ( '<STR_LIT>' , email ) <EOL> def _HasColorSet ( self , gc ) : <EOL> for n in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:status>' ] : <EOL> if gc . Has ( '<STR_LIT>' % n ) : <EOL> return True <EOL> return False <EOL> def _ConfigureColor ( self ) : <EOL> gc = self . manifest . globalConfig <EOL> if self . _HasColorSet ( gc ) : <EOL> return <EOL> class _Test ( Coloring ) : <EOL> def __init__ ( self ) : <EOL> Coloring . __init__ ( self , gc , '<STR_LIT>' ) <EOL> self . _on = True <EOL> out = _Test ( ) <EOL> print '<STR_LIT>' <EOL> print "<STR_LIT>" <EOL> for c in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> out . write ( '<STR_LIT:U+0020>' ) <EOL> out . printer ( fg = c ) ( '<STR_LIT>' , c ) <EOL> out . write ( '<STR_LIT:U+0020>' ) <EOL> out . printer ( fg = '<STR_LIT>' , bg = '<STR_LIT>' ) ( '<STR_LIT>' % '<STR_LIT>' ) <EOL> out . nl ( ) <EOL> for c in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> out . write ( '<STR_LIT:U+0020>' ) <EOL> out . printer ( fg = '<STR_LIT>' , attr = c ) ( '<STR_LIT>' , c ) <EOL> out . nl ( ) <EOL> sys . stdout . write ( '<STR_LIT>' ) <EOL> a = sys . stdin . readline ( ) . strip ( ) . lower ( ) <EOL> if a in ( '<STR_LIT:y>' , '<STR_LIT:yes>' , '<STR_LIT:t>' , '<STR_LIT:true>' , '<STR_LIT>' ) : <EOL> gc . SetString ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def Execute ( self , opt , args ) : <EOL> git_require ( MIN_GIT_VERSION , fail = True ) <EOL> self . _SyncManifest ( opt ) <EOL> if os . isatty ( <NUM_LIT:0> ) and os . isatty ( <NUM_LIT:1> ) and not self . manifest . IsMirror : <EOL> self . _ConfigureUser ( ) <EOL> self . _ConfigureColor ( ) <EOL> if self . manifest . IsMirror : <EOL> type = '<STR_LIT>' <EOL> else : <EOL> type = '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' % ( type , self . manifest . topdir ) </s>
