<s> import sublime <EOL> import sublime_plugin <EOL> import os <EOL> import stat <EOL> import subprocess <EOL> import tempfile <EOL> import threading <EOL> import json <EOL> import sys <EOL> try : <EOL> from Queue import Queue , Empty <EOL> except ImportError : <EOL> from queue import Queue , Empty <EOL> global_folder = '<STR_LIT>' <EOL> class PerforceP4CONFIGHandler ( sublime_plugin . EventListener ) : <EOL> def on_activated ( self , view ) : <EOL> if view . file_name ( ) : <EOL> global global_folder <EOL> global_folder , filename = os . path . split ( view . file_name ( ) ) <EOL> perforceplugin_dir = os . getcwdu ( ) <EOL> command_prefix = "<STR_LIT>" <EOL> def PrepareCommand ( ) : <EOL> perforce_settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> p4Env = perforce_settings . get ( '<STR_LIT>' ) <EOL> global command_prefix <EOL> command_prefix = '<STR_LIT>' <EOL> if ( p4Env and p4Env != '<STR_LIT>' ) : <EOL> command_prefix = '<STR_LIT>' + p4Env + '<STR_LIT>' <EOL> elif ( sublime . platform ( ) == "<STR_LIT>" ) : <EOL> command_prefix = '<STR_LIT>' <EOL> def ConstructCommand ( in_command ) : <EOL> return command_prefix + in_command ; <EOL> def getPerforceConfigFromPreferences ( command ) : <EOL> perforce_settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> def addP4Var ( command , var ) : <EOL> p4var = perforce_settings . get ( var ) <EOL> if p4var : <EOL> if sublime . platform ( ) == "<STR_LIT>" : <EOL> return command + "<STR_LIT>" + var + "<STR_LIT:=>" + p4var + "<STR_LIT>" <EOL> return command + var + "<STR_LIT:=>" + p4var + "<STR_LIT:U+0020>" <EOL> return command <EOL> command = addP4Var ( command , "<STR_LIT>" ) <EOL> command = addP4Var ( command , "<STR_LIT>" ) <EOL> command = addP4Var ( command , "<STR_LIT>" ) <EOL> command = addP4Var ( command , "<STR_LIT>" ) <EOL> return command <EOL> def GetUserFromClientspec ( ) : <EOL> command = ConstructCommand ( '<STR_LIT>' ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( err ) : <EOL> WarnUser ( "<STR_LIT>" + err . strip ( ) ) <EOL> return - <NUM_LIT:1> <EOL> startindex = result . find ( "<STR_LIT>" ) <EOL> if ( startindex == - <NUM_LIT:1> ) : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> return - <NUM_LIT:1> <EOL> startindex += <NUM_LIT:11> <EOL> endindex = result . find ( "<STR_LIT:\n>" , startindex ) <EOL> if ( endindex == - <NUM_LIT:1> ) : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> return - <NUM_LIT:1> <EOL> return result [ startindex : endindex ] . strip ( ) ; <EOL> def GetClientRoot ( in_dir ) : <EOL> command = ConstructCommand ( '<STR_LIT>' ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( err ) : <EOL> WarnUser ( err . strip ( ) ) <EOL> return - <NUM_LIT:1> <EOL> startindex = result . find ( "<STR_LIT>" ) <EOL> if ( startindex == <NUM_LIT:0> ) : <EOL> return - <NUM_LIT:1> <EOL> startindex = result . find ( "<STR_LIT>" ) <EOL> if ( startindex == - <NUM_LIT:1> ) : <EOL> sublime . error_message ( "<STR_LIT>" ) ; <EOL> command = ConstructCommand ( '<STR_LIT>' ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> return - <NUM_LIT:1> <EOL> startindex += <NUM_LIT> <EOL> endindex = result . find ( "<STR_LIT:\n>" , startindex ) <EOL> if ( endindex == - <NUM_LIT:1> ) : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> return - <NUM_LIT:1> <EOL> convertedclientroot = result [ startindex : endindex ] . strip ( ) . replace ( '<STR_LIT:\\>' , os . sep ) . replace ( '<STR_LIT:/>' , os . sep ) <EOL> return convertedclientroot <EOL> def IsFolderUnderClientRoot ( in_folder ) : <EOL> clientroot = GetClientRoot ( in_folder ) <EOL> if ( clientroot == - <NUM_LIT:1> ) : <EOL> return <NUM_LIT:0> <EOL> clientroot = clientroot . lower ( ) <EOL> if ( clientroot == "<STR_LIT:null>" ) : <EOL> return <NUM_LIT:1> <EOL> convertedfolder = in_folder . lower ( ) . replace ( '<STR_LIT:\\>' , os . sep ) . replace ( '<STR_LIT:/>' , os . sep ) ; <EOL> clientrootindex = convertedfolder . find ( clientroot ) ; <EOL> if ( clientrootindex == - <NUM_LIT:1> ) : <EOL> return <NUM_LIT:0> <EOL> return <NUM_LIT:1> <EOL> def IsFileInDepot ( in_folder , in_filename ) : <EOL> isUnderClientRoot = IsFolderUnderClientRoot ( in_folder ) ; <EOL> if ( os . path . isfile ( os . path . join ( in_folder , in_filename ) ) ) : <EOL> if ( isUnderClientRoot ) : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:0> <EOL> else : <EOL> if ( isUnderClientRoot ) : <EOL> return - <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def IsFileOpenedOnClient ( in_filename ) : <EOL> command = ConstructCommand ( '<STR_LIT>' + in_filename + '<STR_LIT:">' ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( err ) : <EOL> return <NUM_LIT:0> <EOL> return <NUM_LIT:1> <EOL> def GetPendingChangelists ( ) : <EOL> currentuser = GetUserFromClientspec ( ) <EOL> if ( currentuser == - <NUM_LIT:1> ) : <EOL> return <NUM_LIT:0> , "<STR_LIT>" <EOL> command = ConstructCommand ( '<STR_LIT>' + currentuser ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( not err ) : <EOL> return <NUM_LIT:1> , result <EOL> return <NUM_LIT:0> , result <EOL> def AppendToChangelistDescription ( changelist , input ) : <EOL> command = ConstructCommand ( '<STR_LIT>' + changelist ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( err ) : <EOL> return <NUM_LIT:0> , err <EOL> lines = result . splitlines ( ) <EOL> descriptionindex = - <NUM_LIT:1> <EOL> for index , line in enumerate ( lines ) : <EOL> if ( line . strip ( ) == "<STR_LIT>" ) : <EOL> descriptionindex = index <EOL> break ; <EOL> filesindex = - <NUM_LIT:1> <EOL> for index , line in enumerate ( lines ) : <EOL> if ( line . strip ( ) == "<STR_LIT>" ) : <EOL> filesindex = index <EOL> break ; <EOL> if ( filesindex == - <NUM_LIT:1> ) : <EOL> endindex = index <EOL> else : <EOL> endindex = filesindex - <NUM_LIT:1> <EOL> perforce_settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> lines . insert ( endindex , "<STR_LIT:\t>" + input ) <EOL> temp_changelist_description_file = open ( os . path . join ( tempfile . gettempdir ( ) , "<STR_LIT>" ) , '<STR_LIT:w>' ) <EOL> try : <EOL> temp_changelist_description_file . write ( perforce_settings . get ( '<STR_LIT>' ) . join ( lines ) ) <EOL> finally : <EOL> temp_changelist_description_file . close ( ) <EOL> command = ConstructCommand ( '<STR_LIT>' + temp_changelist_description_file . name ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> os . unlink ( temp_changelist_description_file . name ) <EOL> if ( err ) : <EOL> return <NUM_LIT:0> , err <EOL> return <NUM_LIT:1> , result <EOL> def PerforceCommandOnFile ( in_command , in_folder , in_filename ) : <EOL> command = ConstructCommand ( '<STR_LIT>' + in_command + '<STR_LIT>' + in_filename + '<STR_LIT:">' ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( not err ) : <EOL> return <NUM_LIT:1> , result . strip ( ) <EOL> else : <EOL> return <NUM_LIT:0> , err . strip ( ) <EOL> def WarnUser ( message ) : <EOL> perforce_settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> if ( perforce_settings . get ( '<STR_LIT>' ) ) : <EOL> if ( perforce_settings . get ( '<STR_LIT>' ) ) : <EOL> sublime . status_message ( "<STR_LIT>" + message ) <EOL> else : <EOL> print "<STR_LIT>" + message <EOL> def LogResults ( success , message ) : <EOL> if ( success >= <NUM_LIT:0> ) : <EOL> print "<STR_LIT>" + message <EOL> else : <EOL> WarnUser ( message ) ; <EOL> def IsFileWritable ( in_filename ) : <EOL> if ( not in_filename ) : <EOL> return <NUM_LIT:0> <EOL> if ( not os . path . isfile ( in_filename ) ) : <EOL> return <NUM_LIT:1> <EOL> filestats = os . stat ( in_filename ) [ <NUM_LIT:0> ] ; <EOL> if ( filestats & stat . S_IWRITE ) : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def Checkout ( in_filename ) : <EOL> if ( IsFileWritable ( in_filename ) ) : <EOL> return - <NUM_LIT:1> , "<STR_LIT>" <EOL> folder_name , filename = os . path . split ( in_filename ) <EOL> isInDepot = IsFileInDepot ( folder_name , filename ) <EOL> if ( isInDepot != <NUM_LIT:1> ) : <EOL> return - <NUM_LIT:1> , "<STR_LIT>" <EOL> return PerforceCommandOnFile ( "<STR_LIT>" , folder_name , in_filename ) ; <EOL> class PerforceAutoCheckout ( sublime_plugin . EventListener ) : <EOL> def on_modified ( self , view ) : <EOL> if ( not view . file_name ( ) ) : <EOL> return <EOL> if ( IsFileWritable ( view . file_name ( ) ) ) : <EOL> return <EOL> perforce_settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> if ( not perforce_settings . get ( '<STR_LIT>' ) or not perforce_settings . get ( '<STR_LIT>' ) ) : <EOL> return <EOL> if ( view . is_dirty ( ) ) : <EOL> PrepareCommand ( ) ; <EOL> success , message = Checkout ( view . file_name ( ) ) <EOL> LogResults ( success , message ) ; <EOL> def on_pre_save ( self , view ) : <EOL> perforce_settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> if ( not perforce_settings . get ( '<STR_LIT>' ) or not perforce_settings . get ( '<STR_LIT>' ) ) : <EOL> return <EOL> if ( view . is_dirty ( ) ) : <EOL> PrepareCommand ( ) ; <EOL> success , message = Checkout ( view . file_name ( ) ) <EOL> LogResults ( success , message ) ; <EOL> class PerforceCheckoutCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> if ( self . view . file_name ( ) ) : <EOL> PrepareCommand ( ) ; <EOL> success , message = Checkout ( self . view . file_name ( ) ) <EOL> LogResults ( success , message ) <EOL> else : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> def Add ( in_folder , in_filename ) : <EOL> return PerforceCommandOnFile ( "<STR_LIT>" , in_folder , in_filename ) ; <EOL> class PerforceAutoAdd ( sublime_plugin . EventListener ) : <EOL> preSaveIsFileInDepot = <NUM_LIT:0> <EOL> def on_pre_save ( self , view ) : <EOL> if view . file_name ( ) and os . path . isfile ( view . file_name ( ) ) : <EOL> return <EOL> global global_folder <EOL> global_folder , filename = os . path . split ( view . file_name ( ) ) <EOL> perforce_settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> self . preSaveIsFileInDepot = <NUM_LIT:0> <EOL> if ( not perforce_settings . get ( '<STR_LIT>' ) ) : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> return <EOL> PrepareCommand ( ) ; <EOL> folder_name , filename = os . path . split ( view . file_name ( ) ) <EOL> if ( not IsFolderUnderClientRoot ( folder_name ) ) : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> return <EOL> self . preSaveIsFileInDepot = IsFileInDepot ( folder_name , filename ) <EOL> def on_post_save ( self , view ) : <EOL> if ( self . preSaveIsFileInDepot == - <NUM_LIT:1> ) : <EOL> PrepareCommand ( ) ; <EOL> folder_name , filename = os . path . split ( view . file_name ( ) ) <EOL> success , message = Add ( folder_name , filename ) <EOL> LogResults ( success , message ) <EOL> class PerforceAddCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> if ( self . view . file_name ( ) ) : <EOL> PrepareCommand ( ) ; <EOL> folder_name , filename = os . path . split ( self . view . file_name ( ) ) <EOL> if ( IsFileInDepot ( folder_name , filename ) ) : <EOL> success , message = Add ( folder_name , filename ) <EOL> else : <EOL> success = <NUM_LIT:0> <EOL> message = "<STR_LIT>" <EOL> LogResults ( success , message ) <EOL> else : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> def Rename ( in_filename , in_newname ) : <EOL> command = ConstructCommand ( '<STR_LIT>' + in_filename + '<STR_LIT>' + in_newname + '<STR_LIT:">' ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( err ) : <EOL> return <NUM_LIT:0> , err . strip ( ) <EOL> command = ConstructCommand ( '<STR_LIT>' + in_filename + '<STR_LIT>' + in_newname + '<STR_LIT:">' ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( not err ) : <EOL> return <NUM_LIT:1> , result . strip ( ) <EOL> else : <EOL> return <NUM_LIT:0> , err . strip ( ) <EOL> class PerforceRenameCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> self . window . show_input_panel ( '<STR_LIT>' , self . window . active_view ( ) . file_name ( ) , <EOL> self . on_done , self . on_change , self . on_cancel ) <EOL> def on_done ( self , input ) : <EOL> PrepareCommand ( ) ; <EOL> success , message = Rename ( self . window . active_view ( ) . file_name ( ) , input ) <EOL> if ( success ) : <EOL> self . window . run_command ( '<STR_LIT>' ) <EOL> self . window . open_file ( input ) <EOL> LogResults ( success , message ) <EOL> def on_change ( self , input ) : <EOL> pass <EOL> def on_cancel ( self ) : <EOL> pass <EOL> def Delete ( in_folder , in_filename ) : <EOL> success , message = PerforceCommandOnFile ( "<STR_LIT>" , in_folder , in_filename ) <EOL> if ( success ) : <EOL> if ( os . path . isfile ( os . path . join ( in_folder , in_filename ) ) ) : <EOL> success = <NUM_LIT:0> <EOL> return success , message <EOL> class PerforceDeleteCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> if ( self . window . active_view ( ) . file_name ( ) ) : <EOL> PrepareCommand ( ) ; <EOL> folder_name , filename = os . path . split ( self . window . active_view ( ) . file_name ( ) ) <EOL> if ( IsFileInDepot ( folder_name , filename ) ) : <EOL> success , message = Delete ( folder_name , filename ) <EOL> if ( success ) : <EOL> self . window . run_command ( '<STR_LIT>' ) ; <EOL> else : <EOL> success = <NUM_LIT:0> <EOL> message = "<STR_LIT>" <EOL> LogResults ( success , message ) <EOL> else : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> def Revert ( in_folder , in_filename ) : <EOL> return PerforceCommandOnFile ( "<STR_LIT>" , in_folder , in_filename ) ; <EOL> class PerforceRevertCommand ( sublime_plugin . TextCommand ) : <EOL> def run_ ( self , args ) : <EOL> if ( self . view . file_name ( ) ) : <EOL> PrepareCommand ( ) ; <EOL> folder_name , filename = os . path . split ( self . view . file_name ( ) ) <EOL> if ( IsFileInDepot ( folder_name , filename ) ) : <EOL> success , message = Revert ( folder_name , filename ) <EOL> if ( success ) : <EOL> self . view . run_command ( '<STR_LIT>' ) ; <EOL> else : <EOL> success = <NUM_LIT:0> <EOL> message = "<STR_LIT>" <EOL> LogResults ( success , message ) <EOL> else : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> def Diff ( in_folder , in_filename ) : <EOL> return PerforceCommandOnFile ( "<STR_LIT>" , in_folder , in_filename ) ; <EOL> class PerforceDiffCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> if ( self . view . file_name ( ) ) : <EOL> PrepareCommand ( ) ; <EOL> folder_name , filename = os . path . split ( self . view . file_name ( ) ) <EOL> if ( IsFileInDepot ( folder_name , filename ) ) : <EOL> success , message = Diff ( folder_name , filename ) <EOL> else : <EOL> success = <NUM_LIT:0> <EOL> message = "<STR_LIT>" <EOL> LogResults ( success , message ) <EOL> else : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> class GraphicalDiffThread ( threading . Thread ) : <EOL> def __init__ ( self , in_folder , in_filename , in_endlineseparator , in_command ) : <EOL> self . folder = in_folder <EOL> self . filename = in_filename <EOL> self . endlineseparator = in_endlineseparator <EOL> self . command = in_command <EOL> threading . Thread . __init__ ( self ) <EOL> def run ( self ) : <EOL> success , content = PerforceCommandOnFile ( "<STR_LIT>" , self . folder , self . filename ) <EOL> if ( not success ) : <EOL> return <NUM_LIT:0> , content <EOL> depotFileName = "<STR_LIT>" + self . filename <EOL> tmp_file = open ( os . path . join ( tempfile . gettempdir ( ) , depotFileName ) , '<STR_LIT:w>' ) <EOL> linebyline = content . splitlines ( ) ; <EOL> content = self . endlineseparator . join ( linebyline [ <NUM_LIT:1> : ] ) ; <EOL> try : <EOL> tmp_file . write ( content ) <EOL> finally : <EOL> tmp_file . close ( ) <EOL> diffCommand = self . command <EOL> diffCommand = diffCommand . replace ( '<STR_LIT>' , tmp_file . name ) <EOL> diffCommand = diffCommand . replace ( '<STR_LIT>' , depotFileName ) <EOL> diffCommand = diffCommand . replace ( '<STR_LIT>' , os . path . join ( self . folder , self . filename ) ) <EOL> diffCommand = diffCommand . replace ( '<STR_LIT>' , self . filename ) <EOL> command = ConstructCommand ( diffCommand ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> os . unlink ( tmp_file . name ) ; <EOL> def GraphicalDiffWithDepot ( self , in_folder , in_filename ) : <EOL> perforce_settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> diffcommand = perforce_settings . get ( '<STR_LIT>' ) <EOL> if not diffcommand : <EOL> diffcommand = perforce_settings . get ( '<STR_LIT>' ) <EOL> GraphicalDiffThread ( in_folder , in_filename , perforce_settings . get ( '<STR_LIT>' ) , diffcommand ) . start ( ) <EOL> return <NUM_LIT:1> , "<STR_LIT>" <EOL> class PerforceGraphicalDiffWithDepotCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit ) : <EOL> if ( self . view . file_name ( ) ) : <EOL> PrepareCommand ( ) ; <EOL> folder_name , filename = os . path . split ( self . view . file_name ( ) ) <EOL> if ( IsFileInDepot ( folder_name , filename ) ) : <EOL> success , message = GraphicalDiffWithDepot ( self , folder_name , filename ) <EOL> else : <EOL> success = <NUM_LIT:0> <EOL> message = "<STR_LIT>" <EOL> LogResults ( success , message ) <EOL> else : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> class PerforceSelectGraphicalDiffApplicationCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> diffapps = [ ] <EOL> if os . path . exists ( perforceplugin_dir + os . sep + '<STR_LIT>' ) : <EOL> f = open ( perforceplugin_dir + os . sep + '<STR_LIT>' ) <EOL> applications = json . load ( f ) <EOL> f . close ( ) <EOL> for entry in applications . get ( '<STR_LIT>' ) : <EOL> formattedentry = [ ] <EOL> formattedentry . append ( entry . get ( '<STR_LIT:name>' ) ) <EOL> formattedentry . append ( entry . get ( '<STR_LIT>' ) ) <EOL> diffapps . append ( formattedentry ) <EOL> self . window . show_quick_panel ( diffapps , self . on_done ) <EOL> def on_done ( self , picked ) : <EOL> if picked == - <NUM_LIT:1> : <EOL> return <EOL> f = open ( perforceplugin_dir + os . sep + '<STR_LIT>' ) <EOL> applications = json . load ( f ) <EOL> entry = applications . get ( '<STR_LIT>' ) [ picked ] <EOL> f . close ( ) <EOL> sublime . status_message ( __name__ + '<STR_LIT>' + entry [ '<STR_LIT>' ] + "<STR_LIT>" ) <EOL> settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> settings . set ( '<STR_LIT>' , entry [ '<STR_LIT:name>' ] ) <EOL> settings . set ( '<STR_LIT>' , entry [ '<STR_LIT>' ] ) <EOL> sublime . save_settings ( '<STR_LIT>' ) <EOL> class ListCheckedOutFilesThread ( threading . Thread ) : <EOL> def __init__ ( self , window ) : <EOL> self . window = window <EOL> threading . Thread . __init__ ( self ) <EOL> def ConvertFileNameToFileOnDisk ( self , in_filename ) : <EOL> clientroot = GetClientRoot ( os . path . dirname ( in_filename ) ) <EOL> if ( clientroot == - <NUM_LIT:1> ) : <EOL> return <NUM_LIT:0> <EOL> if ( clientroot == "<STR_LIT:null>" ) : <EOL> return in_filename <EOL> filename = clientroot + os . sep + in_filename . replace ( '<STR_LIT:\\>' , os . sep ) . replace ( '<STR_LIT:/>' , os . sep ) <EOL> return filename <EOL> def MakeFileListFromChangelist ( self , in_changelistline ) : <EOL> files_list = [ ] <EOL> currentuser = GetUserFromClientspec ( ) <EOL> command = ConstructCommand ( '<STR_LIT>' + in_changelistline [ <NUM_LIT:1> ] + '<STR_LIT>' + currentuser ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( not err ) : <EOL> lines = result . splitlines ( ) <EOL> for line in lines : <EOL> poundindex = line . rfind ( '<STR_LIT:#>' ) <EOL> cleanedfile = line [ <NUM_LIT:0> : poundindex ] <EOL> cleanedfile = '<STR_LIT:/>' . join ( cleanedfile . split ( '<STR_LIT:/>' ) [ <NUM_LIT:3> : ] ) <EOL> file_entry = [ cleanedfile [ cleanedfile . rfind ( '<STR_LIT:/>' ) + <NUM_LIT:1> : ] ] <EOL> file_entry . append ( "<STR_LIT>" + in_changelistline [ <NUM_LIT:1> ] ) <EOL> file_entry . append ( '<STR_LIT:U+0020>' . join ( in_changelistline [ <NUM_LIT:7> : ] ) ) ; <EOL> localfile = self . ConvertFileNameToFileOnDisk ( cleanedfile ) <EOL> if ( localfile != <NUM_LIT:0> ) : <EOL> file_entry . append ( localfile ) <EOL> files_list . append ( file_entry ) <EOL> return files_list <EOL> def MakeCheckedOutFileList ( self ) : <EOL> files_list = self . MakeFileListFromChangelist ( [ '<STR_LIT>' , '<STR_LIT:default>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ; <EOL> currentuser = GetUserFromClientspec ( ) <EOL> if ( currentuser == - <NUM_LIT:1> ) : <EOL> return files_list <EOL> command = ConstructCommand ( '<STR_LIT>' + currentuser ) ; <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( not err ) : <EOL> changelists = result . splitlines ( ) <EOL> for changelistline in changelists : <EOL> changelistlinesplit = changelistline . split ( '<STR_LIT:U+0020>' ) <EOL> files_list . extend ( self . MakeFileListFromChangelist ( changelistlinesplit ) ) <EOL> return files_list <EOL> def run ( self ) : <EOL> self . files_list = self . MakeCheckedOutFileList ( ) <EOL> def show_quick_panel ( ) : <EOL> if not self . files_list : <EOL> sublime . error_message ( __name__ + '<STR_LIT>' ) <EOL> return <EOL> self . window . show_quick_panel ( self . files_list , self . on_done ) <EOL> sublime . set_timeout ( show_quick_panel , <NUM_LIT:10> ) <EOL> def on_done ( self , picked ) : <EOL> if picked == - <NUM_LIT:1> : <EOL> return <EOL> file_name = self . files_list [ picked ] [ <NUM_LIT:3> ] <EOL> def open_file ( ) : <EOL> self . window . open_file ( file_name ) <EOL> sublime . set_timeout ( open_file , <NUM_LIT:10> ) <EOL> class PerforceListCheckedOutFilesCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> PrepareCommand ( ) ; <EOL> ListCheckedOutFilesThread ( self . window ) . start ( ) <EOL> def CreateChangelist ( description ) : <EOL> command = ConstructCommand ( '<STR_LIT>' ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( err ) : <EOL> return <NUM_LIT:0> , err <EOL> desclabel = '<STR_LIT>' + os . linesep <EOL> descindex = result . find ( desclabel ) + len ( desclabel ) <EOL> descend = result . find ( os . linesep * <NUM_LIT:2> , descindex ) <EOL> result = result [ <NUM_LIT:0> : descindex ] + '<STR_LIT:\t>' + description + result [ descend : ] <EOL> filesindex = result . rfind ( "<STR_LIT>" ) <EOL> if ( filesindex > <NUM_LIT> ) : <EOL> result = result [ <NUM_LIT:0> : filesindex ] ; <EOL> temp_changelist_description_file = open ( os . path . join ( tempfile . gettempdir ( ) , "<STR_LIT>" ) , '<STR_LIT:w>' ) <EOL> try : <EOL> temp_changelist_description_file . write ( result ) <EOL> finally : <EOL> temp_changelist_description_file . close ( ) <EOL> command = ConstructCommand ( '<STR_LIT>' + temp_changelist_description_file . name ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> os . unlink ( temp_changelist_description_file . name ) <EOL> if ( err ) : <EOL> return <NUM_LIT:0> , err <EOL> return <NUM_LIT:1> , result <EOL> class PerforceCreateChangelistCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> self . window . show_input_panel ( '<STR_LIT>' , '<STR_LIT>' , <EOL> self . on_done , self . on_change , self . on_cancel ) <EOL> def on_done ( self , input ) : <EOL> PrepareCommand ( ) ; <EOL> success , message = CreateChangelist ( input ) <EOL> LogResults ( success , message ) <EOL> def on_change ( self , input ) : <EOL> pass <EOL> def on_cancel ( self ) : <EOL> pass <EOL> def MoveFileToChangelist ( in_filename , in_changelist ) : <EOL> folder_name , filename = os . path . split ( in_filename ) <EOL> in_command = '<STR_LIT>' <EOL> if ( not IsFileOpenedOnClient ( in_filename ) ) : <EOL> in_command = '<STR_LIT>' <EOL> command = ConstructCommand ( '<STR_LIT>' + in_command + '<STR_LIT>' + in_changelist + '<STR_LIT>' + filename + '<STR_LIT:">' ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( err ) : <EOL> return <NUM_LIT:0> , err <EOL> return <NUM_LIT:1> , result <EOL> class ListChangelistsAndMoveFileThread ( threading . Thread ) : <EOL> def __init__ ( self , window ) : <EOL> self . window = window <EOL> self . view = window . active_view ( ) <EOL> threading . Thread . __init__ ( self ) <EOL> def MakeChangelistsList ( self ) : <EOL> success , rawchangelists = GetPendingChangelists ( ) ; <EOL> resultchangelists = [ '<STR_LIT>' , '<STR_LIT>' ] ; <EOL> if ( success ) : <EOL> changelists = rawchangelists . splitlines ( ) <EOL> for changelistline in changelists : <EOL> changelistlinesplit = changelistline . split ( '<STR_LIT:U+0020>' ) <EOL> resultchangelists . insert ( <NUM_LIT:2> , "<STR_LIT>" + changelistlinesplit [ <NUM_LIT:1> ] + "<STR_LIT>" + '<STR_LIT:U+0020>' . join ( changelistlinesplit [ <NUM_LIT:7> : ] ) ) <EOL> return resultchangelists <EOL> def run ( self ) : <EOL> self . changelists_list = self . MakeChangelistsList ( ) <EOL> def show_quick_panel ( ) : <EOL> if not self . changelists_list : <EOL> sublime . error_message ( __name__ + '<STR_LIT>' ) <EOL> return <EOL> self . window . show_quick_panel ( self . changelists_list , self . on_done ) <EOL> sublime . set_timeout ( show_quick_panel , <NUM_LIT:10> ) <EOL> def on_done ( self , picked ) : <EOL> if picked == - <NUM_LIT:1> : <EOL> return <EOL> changelistlist = self . changelists_list [ picked ] . split ( '<STR_LIT:U+0020>' ) <EOL> def move_file ( ) : <EOL> changelist = '<STR_LIT>' <EOL> if ( len ( changelistlist ) > <NUM_LIT:1> ) : <EOL> changelist = changelistlist [ <NUM_LIT:1> ] <EOL> else : <EOL> changelist = changelistlist [ <NUM_LIT:0> ] <EOL> if ( changelist == '<STR_LIT>' ) : <EOL> self . window . show_input_panel ( '<STR_LIT>' , '<STR_LIT>' , self . on_description_done , self . on_description_change , self . on_description_cancel ) <EOL> else : <EOL> success , message = MoveFileToChangelist ( self . view . file_name ( ) , changelist . lower ( ) ) <EOL> LogResults ( success , message ) ; <EOL> sublime . set_timeout ( move_file , <NUM_LIT:10> ) <EOL> def on_description_done ( self , input ) : <EOL> success , message = CreateChangelist ( input ) <EOL> if ( success == <NUM_LIT:1> ) : <EOL> changelist = message . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:1> ] <EOL> success , message = MoveFileToChangelist ( self . view . file_name ( ) , changelist ) <EOL> LogResults ( success , message ) <EOL> def on_description_change ( self , input ) : <EOL> pass <EOL> def on_description_cancel ( self ) : <EOL> pass <EOL> class PerforceMoveCurrentFileToChangelistCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> PrepareCommand ( ) ; <EOL> folder_name , filename = os . path . split ( self . window . active_view ( ) . file_name ( ) ) <EOL> isInDepot = IsFileInDepot ( folder_name , filename ) <EOL> if ( isInDepot != <NUM_LIT:1> ) : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> return <NUM_LIT:0> <EOL> ListChangelistsAndMoveFileThread ( self . window ) . start ( ) <EOL> class AddLineToChangelistDescriptionThread ( threading . Thread ) : <EOL> def __init__ ( self , window ) : <EOL> self . window = window <EOL> self . view = window . active_view ( ) <EOL> threading . Thread . __init__ ( self ) <EOL> def MakeChangelistsList ( self ) : <EOL> success , rawchangelists = GetPendingChangelists ( ) ; <EOL> resultchangelists = [ ] ; <EOL> if ( success ) : <EOL> changelists = rawchangelists . splitlines ( ) <EOL> for changelistline in changelists : <EOL> changelistlinesplit = changelistline . split ( '<STR_LIT:U+0020>' ) <EOL> changelist_entry = [ "<STR_LIT>" + changelistlinesplit [ <NUM_LIT:1> ] ] <EOL> changelist_entry . append ( '<STR_LIT:U+0020>' . join ( changelistlinesplit [ <NUM_LIT:7> : ] ) ) ; <EOL> resultchangelists . insert ( <NUM_LIT:0> , changelist_entry ) <EOL> return resultchangelists <EOL> def run ( self ) : <EOL> self . changelists_list = self . MakeChangelistsList ( ) <EOL> def show_quick_panel ( ) : <EOL> if not self . changelists_list : <EOL> sublime . error_message ( __name__ + '<STR_LIT>' ) <EOL> return <EOL> self . window . show_quick_panel ( self . changelists_list , self . on_done ) <EOL> sublime . set_timeout ( show_quick_panel , <NUM_LIT:10> ) <EOL> def on_done ( self , picked ) : <EOL> if picked == - <NUM_LIT:1> : <EOL> return <EOL> changelistlist = self . changelists_list [ picked ] [ <NUM_LIT:0> ] . split ( '<STR_LIT:U+0020>' ) <EOL> def get_description_line ( ) : <EOL> self . changelist = changelistlist [ <NUM_LIT:1> ] <EOL> self . window . show_input_panel ( '<STR_LIT>' , '<STR_LIT>' , self . on_description_done , self . on_description_change , self . on_description_cancel ) <EOL> sublime . set_timeout ( get_description_line , <NUM_LIT:10> ) <EOL> def on_description_done ( self , input ) : <EOL> success , message = AppendToChangelistDescription ( self . changelist , input ) <EOL> LogResults ( success , message ) <EOL> def on_description_change ( self , input ) : <EOL> pass <EOL> def on_description_cancel ( self ) : <EOL> pass <EOL> class PerforceAddLineToChangelistDescriptionCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> PrepareCommand ( ) ; <EOL> AddLineToChangelistDescriptionThread ( self . window ) . start ( ) <EOL> class SubmitThread ( threading . Thread ) : <EOL> def __init__ ( self , window ) : <EOL> self . window = window <EOL> self . view = window . active_view ( ) <EOL> threading . Thread . __init__ ( self ) <EOL> def MakeChangelistsList ( self ) : <EOL> success , rawchangelists = GetPendingChangelists ( ) ; <EOL> resultchangelists = [ '<STR_LIT>' ] ; <EOL> currentuser = GetUserFromClientspec ( ) ; <EOL> command = ConstructCommand ( '<STR_LIT>' + currentuser ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if err : <EOL> resultchangelists . pop ( ) <EOL> if success : <EOL> changelists = rawchangelists . splitlines ( ) <EOL> for changelistline in changelists : <EOL> changelistlinesplit = changelistline . split ( '<STR_LIT:U+0020>' ) <EOL> resultchangelists . insert ( <NUM_LIT:1> , "<STR_LIT>" + changelistlinesplit [ <NUM_LIT:1> ] + "<STR_LIT>" + '<STR_LIT:U+0020>' . join ( changelistlinesplit [ <NUM_LIT:7> : ] ) ) <EOL> return resultchangelists <EOL> def run ( self ) : <EOL> self . changelists_list = self . MakeChangelistsList ( ) <EOL> def show_quick_panel ( ) : <EOL> if not self . changelists_list : <EOL> sublime . error_message ( __name__ + '<STR_LIT>' ) <EOL> return <EOL> self . window . show_quick_panel ( self . changelists_list , self . on_done ) <EOL> sublime . set_timeout ( show_quick_panel , <NUM_LIT:10> ) <EOL> def on_done ( self , picked ) : <EOL> if picked == - <NUM_LIT:1> : <EOL> return <EOL> changelist = self . changelists_list [ picked ] <EOL> changelistsections = changelist . split ( '<STR_LIT:U+0020>' ) <EOL> command = '<STR_LIT>' <EOL> if changelistsections [ <NUM_LIT:0> ] != '<STR_LIT>' : <EOL> command = ConstructCommand ( '<STR_LIT>' + changelistsections [ <NUM_LIT:1> ] ) ; <EOL> else : <EOL> command = ConstructCommand ( '<STR_LIT>' ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> def on_description_change ( self , input ) : <EOL> pass <EOL> def on_description_cancel ( self ) : <EOL> pass <EOL> class PerforceSubmitCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> PrepareCommand ( ) ; <EOL> SubmitThread ( self . window ) . start ( ) <EOL> class PerforceLogoutCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> PrepareCommand ( ) ; <EOL> try : <EOL> command = ConstructCommand ( "<STR_LIT>" ) <EOL> p = subprocess . Popen ( command , stdin = subprocess . PIPE , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> p . communicate ( ) <EOL> except ValueError : <EOL> pass <EOL> class PerforceLoginCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> self . window . show_input_panel ( "<STR_LIT>" , "<STR_LIT>" , self . on_done , None , None ) <EOL> def on_done ( self , password ) : <EOL> try : <EOL> PrepareCommand ( ) ; <EOL> command = ConstructCommand ( "<STR_LIT>" ) <EOL> p = subprocess . Popen ( command , stdin = subprocess . PIPE , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> p . communicate ( ) <EOL> command = ConstructCommand ( "<STR_LIT>" + password ) <EOL> p = subprocess . Popen ( command , stdin = subprocess . PIPE , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> p . communicate ( ) <EOL> except ValueError : <EOL> pass <EOL> class PerforceUnshelveClCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> try : <EOL> PrepareCommand ( ) ; <EOL> ShelveClCommand ( self . window , False ) . start ( ) <EOL> except : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> return - <NUM_LIT:1> <EOL> class PerforceShelveClCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> try : <EOL> PrepareCommand ( ) ; <EOL> ShelveClCommand ( self . window , True ) . start ( ) <EOL> except : <EOL> WarnUser ( "<STR_LIT>" ) <EOL> return - <NUM_LIT:1> <EOL> class ShelveClCommand ( threading . Thread ) : <EOL> def __init__ ( self , window , shelve = True ) : <EOL> self . shelve = shelve <EOL> self . window = window <EOL> threading . Thread . __init__ ( self ) <EOL> def run ( self ) : <EOL> self . changelists_list = self . MakeChangelistsList ( ) <EOL> def show_quick_panel ( ) : <EOL> if not self . changelists_list : <EOL> sublime . error_message ( __name__ + '<STR_LIT>' ) <EOL> return <EOL> self . window . show_quick_panel ( self . changelists_list , self . on_done ) <EOL> sublime . set_timeout ( show_quick_panel , <NUM_LIT:10> ) <EOL> def on_done ( self , picked ) : <EOL> if picked == - <NUM_LIT:1> : <EOL> return <EOL> changelistlist = self . changelists_list [ picked ] . split ( '<STR_LIT:U+0020>' ) <EOL> changelist = '<STR_LIT>' <EOL> if ( len ( changelistlist ) > <NUM_LIT:1> ) : <EOL> changelist = changelistlist [ <NUM_LIT:1> ] <EOL> else : <EOL> changelist = changelistlist [ <NUM_LIT:0> ] <EOL> if self . shelve : <EOL> cmdString = "<STR_LIT>" + changelist <EOL> else : <EOL> cmdString = "<STR_LIT>" + changelist + "<STR_LIT>" <EOL> command = ConstructCommand ( "<STR_LIT>" + cmdString ) <EOL> p = subprocess . Popen ( command , stdout = subprocess . PIPE , stderr = subprocess . PIPE , cwd = global_folder , shell = True ) <EOL> result , err = p . communicate ( ) <EOL> if ( err ) : <EOL> WarnUser ( "<STR_LIT>" + err . strip ( ) ) <EOL> return - <NUM_LIT:1> <EOL> def MakeChangelistsList ( self ) : <EOL> success , rawchangelists = GetPendingChangelists ( ) ; <EOL> resultchangelists = [ ] <EOL> if ( success ) : <EOL> changelists = rawchangelists . splitlines ( ) <EOL> for changelistline in changelists : <EOL> changelistlinesplit = changelistline . split ( '<STR_LIT:U+0020>' ) <EOL> resultchangelists . insert ( <NUM_LIT:0> , "<STR_LIT>" + changelistlinesplit [ <NUM_LIT:1> ] + "<STR_LIT>" + '<STR_LIT:U+0020>' . join ( changelistlinesplit [ <NUM_LIT:7> : ] ) ) <EOL> return resultchangelists </s>
