Advertisement
Guest User

Sublime SFTP.py edited

a guest
Jul 25th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.85 KB | None | 0 0
  1. import sublime
  2. import traceback
  3. import os
  4. import sys
  5. import time
  6. import imp
  7. import re
  8.  
  9. settings = sublime.load_settings('SFTP.sublime-settings')
  10.  
  11. if sublime.platform() == 'linux' and settings.get('linux_enable_ssl'):
  12.     print 'SFTP: enabling custom linux ssl module'
  13.     arch_lib_path = os.path.join(sublime.packages_path(), 'SFTP', 'lib',
  14.         'linux-' + sublime.arch())
  15.     for ssl_ver in ['0.9.8', '1.0.0', '10']:
  16.         lib_path = os.path.join(arch_lib_path, 'libssl-' + ssl_ver)
  17.         try:
  18.             m_info = imp.find_module('_ssl', [lib_path])
  19.             m = imp.load_module('_ssl', *m_info)
  20.             print 'SFTP: successfully loaded _ssl module for libssl.so.%s' % ssl_ver
  21.             break
  22.         except (ImportError) as (e):
  23.             print 'SFTP: _ssl module import error - ' + str(e)
  24.     if '_ssl' in sys.modules:
  25.         plat_lib_path = os.path.join(sublime.packages_path(), 'SFTP', 'lib',
  26.             'linux')
  27.         try:
  28.             m_info = imp.find_module('ssl', [plat_lib_path])
  29.             m = imp.load_module('ssl', *m_info)
  30.         except (ImportError) as (e):
  31.             print 'SFTP: ssl module import error - ' + str(e)
  32.  
  33. reloading = {
  34.     'happening': False,
  35.     'shown': False
  36. }
  37.  
  38. reload_mods = []
  39. for mod in sys.modules:
  40.     if (mod[0:5] == 'sftp.' or mod == 'sftp') and sys.modules[mod] != None:
  41.         reload_mods.append(mod)
  42.         reloading['happening'] = True
  43.  
  44. # Prevent popups during reload, saving the callbacks for re-adding later
  45. if reload_mods:
  46.     old_callbacks = {}
  47.     hook_match = re.search("<class '(\w+).ExcepthookChain'>", str(sys.excepthook))
  48.     if hook_match:
  49.         _temp = __import__(hook_match.group(1), globals(), locals(),
  50.             ['ExcepthookChain'], -1)
  51.         ExcepthookChain = _temp.ExcepthookChain
  52.         old_callbacks = ExcepthookChain.names
  53.     sys.excepthook = sys.__excepthook__
  54.  
  55. mods_load_order = [
  56.     'sftp',
  57.     'sftp.times',
  58.     'sftp.views',
  59.     'sftp.paths',
  60.     'sftp.debug',
  61.     'sftp.errors',
  62.     'sftp.threads',
  63.     'sftp.secure_input',
  64.     'sftp.proc',
  65.     'sftp.vcs',
  66.     'sftp.config',
  67.     'sftp.panel_printer',
  68.     'sftp.file_transfer',
  69.     'sftp.ftplib2',
  70.     'sftp.ftp_transport',
  71.     'sftp.ftps_transport',
  72.     'sftp.sftp_transport',
  73.     'sftp.commands',
  74.     'sftp.listeners'
  75. ]
  76.  
  77. for mod in mods_load_order:
  78.     if mod in reload_mods:
  79.         reload(sys.modules[mod])
  80.  
  81. from sftp.commands import (SftpShowPanelCommand, SftpCreateServerCommand,
  82.     SftpBrowseServerCommand, SftpLastServerCommand, SftpEditServerCommand,
  83.     SftpDeleteServerCommand, SftpBrowseCommand, SftpUploadFileCommand,
  84.     SftpMonitorFileCommand, SftpUploadOpenFilesCommand,
  85.     SftpDiffRemoteFileCommand, SftpRenameLocalAndRemotePathsCommand,
  86.     SftpDeleteRemotePathCommand, SftpDownloadFileCommand,
  87.     SftpUploadFolderCommand, SftpSyncUpCommand, SftpSyncDownCommand,
  88.     SftpSyncBothCommand, SftpDownloadFolderCommand, SftpVcsChangedFilesCommand,
  89.     SftpCancelUploadCommand, SftpEditConfigCommand, SftpCreateConfigCommand,
  90.     SftpCreateSubConfigCommand, SftpThread,
  91.     SftpDeleteLocalAndRemotePathsCommand, SftpSwitchConfigCommand,
  92.     SftpCreateAltConfigCommand)
  93. from sftp.listeners import (SftpCloseListener, SftpLoadListener,
  94.     SftpFocusListener, SftpAutoUploadListener, SftpAutoConnectListener)
  95.  
  96. import sftp.debug
  97. import sftp.paths
  98. import sftp.times
  99.  
  100. sftp.debug.set_debug(settings.get('debug', False))
  101.  
  102.  
  103. hook_match = re.search("<class '(\w+).ExcepthookChain'>", str(sys.excepthook))
  104.  
  105. if not hook_match:
  106.     class ExcepthookChain(object):
  107.         callbacks = []
  108.         names = {}
  109.  
  110.         @classmethod
  111.         def add(cls, name, callback):
  112.             if name == 'sys.excepthook':
  113.                 if name in cls.names:
  114.                     return
  115.                 cls.callbacks.append(callback)
  116.             else:
  117.                 if name in cls.names:
  118.                     cls.callbacks.remove(cls.names[name])
  119.                 cls.callbacks.insert(0, callback)
  120.             cls.names[name] = callback
  121.  
  122.         @classmethod
  123.         def hook(cls, type, value, tb):
  124.             for callback in cls.callbacks:
  125.                 callback(type, value, tb)
  126.  
  127.         @classmethod
  128.         def remove(cls, name):
  129.             if name not in cls.names:
  130.                 return
  131.             callback = cls.names[name]
  132.             del cls.names[name]
  133.             cls.callbacks.remove(callback)
  134. else:
  135.     _temp = __import__(hook_match.group(1), globals(), locals(),
  136.         ['ExcepthookChain'], -1)
  137.     ExcepthookChain = _temp.ExcepthookChain
  138.  
  139. if reload_mods and old_callbacks:
  140.     for name in old_callbacks:
  141.         ExcepthookChain.add(name, old_callbacks[name])
  142.  
  143. ExcepthookChain.add('sys.excepthook', sys.__excepthook__)
  144.  
  145. if sys.excepthook != ExcepthookChain.hook:
  146.     sys.excepthook = ExcepthookChain.hook
  147.  
  148.  
  149. def unload_handler():
  150.     SftpThread.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement