#NEWLINE# def run( self ) : #NEWLINE# #INDENT# packageDir = os . path . join ( sublime . packages_path ( ) , PACKAGE_NAME ) #NEWLINE# self . remoteFile = self . remoteFile . replace ( '\\' , '/' ) . replace ( '//' , '/' ) #NEWLINE# remote = ( ( ( ( self . username + '@' ) + self . host ) + ':' ) + self . remoteFile ) #NEWLINE# pw = [ ] #NEWLINE# ext = [ '-r' , '-C' , '-P' , str ( self . port ) , ( '"%s"' % self . localFile ) , ( '"%s"' % remote ) ] #NEWLINE# shell = True #NEWLINE# if ( OS == 'Windows' ) : #NEWLINE# #INDENT# scp = ( '"%s"' % os . path . join ( packageDir , 'pscp.exe' ) ) #NEWLINE# args = [ scp ] #NEWLINE# if self . password : #NEWLINE# #INDENT# pw = [ '-pw' , self . password ] #NEWLINE# #UNINDENT# args . extend ( pw ) #NEWLINE# shell = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# args = [ 'scp' ] #NEWLINE# #UNINDENT# args . extend ( ext ) #NEWLINE# run_cmd = ' ' . join ( args ) #NEWLINE# print ( ( ( PACKAGE_NAME + ': ' ) + run_cmd ) ) #NEWLINE# expect_cmd = None #NEWLINE# if ( ( OS != 'Windows' ) and self . password ) : #NEWLINE# #INDENT# expect_cmd = '\n            expect -c "\n            set timeout {timeout};\n            spawn {cmd};\n            expect *password* {{ send \\"{password}\\r\\" }};\n            expect "100%"\n            expect eof"\n            ' . format ( cmd = run_cmd , password = self . password , timeout = self . timeout ) #NEWLINE# #UNINDENT# self . i = 1 #NEWLINE# self . done = False #NEWLINE# self . success = False #NEWLINE# def show_loading( ) : #NEWLINE# #INDENT# if ( ( self . i % 2 ) == 0 ) : #NEWLINE# #INDENT# s = 0 #NEWLINE# e = 3 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s = 3 #NEWLINE# e = 0 #NEWLINE# #UNINDENT# if ( not self . done ) : #NEWLINE# #INDENT# sublime . status_message ( ( '%s [%s=%s]' % ( PACKAGE_NAME , ( ' ' * s ) , ( ' ' * e ) ) ) ) #NEWLINE# sublime . set_timeout ( show_loading , 500 ) #NEWLINE# self . i += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = ( 'Completed!' if self . success else 'Sync failed!' ) #NEWLINE# sublime . status_message ( ( '%s: %s' % ( PACKAGE_NAME , msg ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# show_loading ( ) #NEWLINE# def sync_folder( ) : #NEWLINE# #INDENT# self . localFile = os . path . dirname ( self . localFile ) #NEWLINE# self . remoteFile = os . path . dirname ( os . path . dirname ( self . remoteFile ) ) #NEWLINE# ScpCopier ( self . host , self . username , self . password , self . localFile , self . remoteFile , self . port ) . start ( ) #NEWLINE# #UNINDENT# def show_msg( msg ) : #NEWLINE# #INDENT# find_msg = msg . lower ( ) #NEWLINE# if ( find_msg . find ( 'No such file or directory' . lower ( ) ) != ( - 1 ) ) : #NEWLINE# #INDENT# if sublime . ok_cancel_dialog ( ( ( ( 'No such file or directory\n' + self . relPath ) + '\n' ) + '* Do you want to sync the parent folder?' ) ) : #NEWLINE# #INDENT# sync_folder ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( find_msg . find ( 'continue connecting' . lower ( ) ) != ( - 1 ) ) : #NEWLINE# #INDENT# msg = 'Please run this command once: \n' #NEWLINE# msg += ( run_cmd + '\n' ) #NEWLINE# msg += '*** Also, you can copy this command via "Console"(ctrl+` shortcut).' #NEWLINE# if ( not command . store_key ( shell = shell ) ) : #NEWLINE# #INDENT# self . success = False #NEWLINE# sublime . message_dialog ( msg ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( find_msg . find ( 'Host key verification failed' . lower ( ) ) != ( - 1 ) ) : #NEWLINE# #INDENT# msg = 'Please generate SSH public-key and run: \n' #NEWLINE# msg += ( ( ( ( ( ( 'ssh -p ' + self . port ) + ' ' ) + self . username ) + '@' ) + self . host ) + " 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub \n" ) #NEWLINE# sublime . message_dialog ( msg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( find_msg . find ( 'Permission denied (publickey,password)' . lower ( ) ) != ( - 1 ) ) : #NEWLINE# #INDENT# msg = 'Scp auth faild. Please check your sshd_config, and enable AuthorizedKeysFile!' #NEWLINE# sublime . message_dialog ( msg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( find_msg . find ( '100%' ) != ( - 1 ) ) : #NEWLINE# #INDENT# self . success = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( find_msg . find ( 's password:' ) != ( - 1 ) ) : #NEWLINE# #INDENT# msg = ( 'Please enlarge the ["config"]["timeout"] in %s settings (Default: 10)' % PACKAGE_NAME ) #NEWLINE# sublime . message_dialog ( msg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if msg : #NEWLINE# #INDENT# sublime . message_dialog ( msg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . success = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# if ( OS == 'Windows' ) : #NEWLINE# #INDENT# retcode = subprocess . call ( run_cmd ) #NEWLINE# if self . debug : #NEWLINE# #INDENT# print ( 'returncode:' , retcode ) #NEWLINE# #UNINDENT# if ( retcode != 0 ) : #NEWLINE# #INDENT# self . success = False #NEWLINE# msg = 'Please verify that your settings(username, password, host, port) is correct and try again' #NEWLINE# sublime . message_dialog ( msg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . success = True #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# command = Command ( run_cmd , debug = self . debug , expect_cmd = expect_cmd ) #NEWLINE# command . run ( timeout = self . timeout , shell = shell ) #NEWLINE# if self . debug : #NEWLINE# #INDENT# print ( 'msg:' , command . msg , 'returncode:' , command . process . returncode ) #NEWLINE# #UNINDENT# show_msg ( command . msg ) #NEWLINE# #UNINDENT# self . done = True #NEWLINE# #UNINDENT# except Exception as exception : #NEWLINE# #INDENT# sublime . error_message ( ( ( PACKAGE_NAME + ': ' ) + str ( exception ) ) )