<s> from deployer . exceptions import ExecCommandFailed <EOL> from deployer . node import Node , ParallelNode , ParallelNodeBase , dont_isolate_yet , required_property <EOL> from deployer . utils import esc1 <EOL> from deployer . node . decorators import suppress_action_result <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class GitBase ( ParallelNodeBase ) : <EOL> _default_commands = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT:status>' , <EOL> '<STR_LIT:version>' : '<STR_LIT:version>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> _ignore_exit_status = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __new__ ( cls , name , bases , attrs ) : <EOL> commands = attrs . get ( '<STR_LIT>' , { } ) <EOL> for cmd_name , command in cls . _default_commands . items ( ) + commands . items ( ) : <EOL> attrs [ cmd_name ] = cls . _create_git_command ( command , <EOL> ignore_exit_status = command in cls . _ignore_exit_status ) <EOL> return ParallelNodeBase . __new__ ( cls , name , bases , attrs ) <EOL> @ staticmethod <EOL> def _create_git_command ( command , ignore_exit_status = False ) : <EOL> @ suppress_action_result <EOL> def run ( self ) : <EOL> with self . host . cd ( self . repository_location ) : <EOL> return self . host . run ( '<STR_LIT>' % command , ignore_exit_status = ignore_exit_status ) <EOL> return run <EOL> class Git ( ParallelNode ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = GitBase <EOL> repository = required_property ( ) <EOL> repository_location = required_property ( ) <EOL> default_revision = '<STR_LIT>' <EOL> commands = { } <EOL> @ dont_isolate_yet <EOL> def checkout ( self , commit = None ) : <EOL> if not commit : <EOL> commit = self . console . input ( '<STR_LIT>' , default = self . default_revision ) <EOL> if not commit : raise Exception ( '<STR_LIT>' ) <EOL> self . _checkout ( commit ) <EOL> def _before_checkout_hook ( self , commit ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _checkout ( self , commit ) : <EOL> """<STR_LIT>""" <EOL> host = self . host <EOL> existed = host . exists ( self . repository_location ) <EOL> if not existed : <EOL> host . run ( '<STR_LIT>' % ( self . repository , self . repository_location ) ) <EOL> with host . cd ( self . repository_location ) : <EOL> host . run ( '<STR_LIT>' ) <EOL> self . _before_checkout_hook ( commit ) <EOL> if existed : <EOL> host . run ( '<STR_LIT>' ) <EOL> try : <EOL> host . run ( "<STR_LIT>" % esc1 ( commit ) ) <EOL> host . run ( "<STR_LIT>" ) <EOL> finally : <EOL> try : <EOL> if existed : <EOL> host . run ( '<STR_LIT>' , interactive = False ) <EOL> except ExecCommandFailed , e : <EOL> result = e . result <EOL> if result . strip ( ) not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> print result <EOL> if not self . console . confirm ( '<STR_LIT>' , default = True ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> class GitOverview ( Node ) : <EOL> """<STR_LIT>""" <EOL> def show ( self ) : <EOL> from deployer . inspection import filters , Inspector <EOL> def iterate ( ) : <EOL> iterator = Inspector ( Inspector ( self ) . get_root ( ) ) . walk ( filters . IsInstance ( Git ) & filters . PublicOnly ) <EOL> for node in iterator : <EOL> full_path = '<STR_LIT:.>' . join ( Inspector ( node ) . get_path ( ) ) <EOL> checkout = str ( node . show_oneline ( ) ) . strip ( ) <EOL> yield '<STR_LIT>' % ( full_path , checkout ) <EOL> self . console . lesspipe ( iterate ( ) ) <EOL> __call__ = show </s>
