<s> from functools import partial <EOL> import sublime <EOL> from sublime_plugin import WindowCommand <EOL> from . util import StatusSpinner , noop <EOL> from . cmd import GitCmd <EOL> from . helpers import GitTagHelper , GitErrorHelper <EOL> TAG_FORCE = u'<STR_LIT>' <EOL> class GitAddTagCommand ( WindowCommand , GitTagHelper , GitErrorHelper , GitCmd ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , sign = False ) : <EOL> repo = self . get_repo ( ) <EOL> if not repo : <EOL> return <EOL> tags = self . get_tags ( repo , annotate = False ) <EOL> def on_done ( name ) : <EOL> name = name . strip ( ) <EOL> if not name : <EOL> return <EOL> if name in tags : <EOL> if sublime . ok_cancel_dialog ( TAG_FORCE % name , '<STR_LIT>' ) : <EOL> self . on_name ( repo , sign , name , force = True ) <EOL> else : <EOL> self . on_name ( repo , sign , name ) <EOL> self . window . show_input_panel ( '<STR_LIT>' , '<STR_LIT>' , on_done , noop , noop ) <EOL> def on_name ( self , repo , sign , name , force = False ) : <EOL> def on_done ( message ) : <EOL> message = message . strip ( ) <EOL> if not message : <EOL> if sign : <EOL> if sublime . ok_cancel_dialog ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . on_name ( repo , sign , name , force ) <EOL> return <EOL> else : <EOL> message = None <EOL> self . on_message ( repo , sign , name , force , message ) <EOL> self . window . show_input_panel ( '<STR_LIT>' , '<STR_LIT>' , on_done , noop , noop ) <EOL> def on_message ( self , repo , sign , name , force , message = None ) : <EOL> kind = None <EOL> if sign : <EOL> kind = '<STR_LIT>' <EOL> elif message : <EOL> kind = '<STR_LIT>' <EOL> cmd = [ '<STR_LIT>' , kind , '<STR_LIT>' if force else None ] <EOL> if message : <EOL> cmd += [ '<STR_LIT>' , '<STR_LIT:->' ] <EOL> cmd += [ name ] <EOL> exit , stdout , stderr = self . git ( cmd , cwd = repo , stdin = message ) <EOL> if exit == <NUM_LIT:0> : <EOL> if stdout : <EOL> panel = self . window . get_output_panel ( '<STR_LIT>' ) <EOL> panel . run_command ( '<STR_LIT>' , { '<STR_LIT:content>' : stdout } ) <EOL> self . window . run_command ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> else : <EOL> sublime . status_message ( "<STR_LIT>" % name ) <EOL> else : <EOL> sublime . error_message ( self . format_error_message ( stderr ) ) <EOL> class GitTagCommand ( WindowCommand , GitTagHelper , GitErrorHelper , GitCmd ) : <EOL> """<STR_LIT>""" <EOL> ADD_TAG = '<STR_LIT>' <EOL> SHOW = '<STR_LIT>' <EOL> CHECKOUT = '<STR_LIT>' <EOL> VERIFY = '<STR_LIT>' <EOL> DELETE = '<STR_LIT>' <EOL> TAG_ACTIONS = [ <EOL> [ SHOW , '<STR_LIT>' ] , <EOL> [ CHECKOUT , '<STR_LIT>' ] , <EOL> [ VERIFY , '<STR_LIT>' ] , <EOL> [ DELETE , '<STR_LIT>' ] , <EOL> ] <EOL> ACTION_CALLBACKS = { <EOL> SHOW : '<STR_LIT>' , <EOL> CHECKOUT : '<STR_LIT>' , <EOL> VERIFY : '<STR_LIT>' , <EOL> DELETE : '<STR_LIT>' , <EOL> } <EOL> def run ( self , repo = None ) : <EOL> repo = repo or self . get_repo ( ) <EOL> if not repo : <EOL> return <EOL> tags = self . get_tags ( repo ) <EOL> choices = self . format_quick_tags ( tags ) <EOL> choices . append ( [ self . ADD_TAG , '<STR_LIT>' ] ) <EOL> def on_done ( idx ) : <EOL> if idx != - <NUM_LIT:1> : <EOL> tag = choices [ idx ] [ <NUM_LIT:0> ] <EOL> if tag == self . ADD_TAG : <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> else : <EOL> sublime . set_timeout ( partial ( self . on_tag , repo , tag ) , <NUM_LIT:50> ) <EOL> self . window . show_quick_panel ( choices , on_done ) <EOL> def on_tag ( self , repo , tag ) : <EOL> choices = [ [ a , t . format ( tag = tag ) ] for a , t in self . TAG_ACTIONS ] <EOL> def on_done ( idx ) : <EOL> if idx != - <NUM_LIT:1> : <EOL> action = self . TAG_ACTIONS [ idx ] [ <NUM_LIT:0> ] <EOL> callback = self . ACTION_CALLBACKS . get ( action ) <EOL> func = getattr ( self , callback , None ) <EOL> if func : <EOL> func ( repo , tag ) <EOL> self . window . show_quick_panel ( choices , on_done ) <EOL> def reset ( self , repo ) : <EOL> def on_time ( ) : <EOL> self . window . run_command ( '<STR_LIT>' , { '<STR_LIT>' : repo } ) <EOL> sublime . set_timeout ( on_time , <NUM_LIT:50> ) <EOL> def verify_tag ( self , repo , tag ) : <EOL> self . panel = self . window . get_output_panel ( '<STR_LIT>' ) <EOL> self . panel_shown = False <EOL> thread = self . git_async ( [ '<STR_LIT>' , '<STR_LIT>' , tag ] , cwd = repo , on_data = self . on_data ) <EOL> runner = StatusSpinner ( thread , "<STR_LIT>" % tag ) <EOL> runner . start ( ) <EOL> self . reset ( repo ) <EOL> def show_tag ( self , repo , tag ) : <EOL> self . window . run_command ( '<STR_LIT>' , { '<STR_LIT>' : repo , '<STR_LIT>' : '<STR_LIT>' % tag } ) <EOL> def delete_tag ( self , repo , tag ) : <EOL> exit , stdout , stderr = self . git ( [ '<STR_LIT>' , '<STR_LIT>' , tag ] , cwd = repo ) <EOL> if exit == <NUM_LIT:0> : <EOL> self . reset ( repo ) <EOL> else : <EOL> sublime . error_message ( stderr ) <EOL> def checkout_tag ( self , repo , tag ) : <EOL> self . window . run_command ( '<STR_LIT>' , { '<STR_LIT>' : repo , '<STR_LIT>' : tag } ) <EOL> def on_data ( self , d ) : <EOL> if not self . panel_shown : <EOL> self . window . run_command ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . panel . run_command ( '<STR_LIT>' , { '<STR_LIT:content>' : d , '<STR_LIT>' : True } ) </s>
