Skip to content

Commit

Permalink
Finish crapy work
Browse files Browse the repository at this point in the history
  • Loading branch information
toxinu committed Nov 2, 2014
1 parent 478043d commit 9bdb5c6
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 84 deletions.
Empty file added .no-sublime-package
Empty file.
100 changes: 28 additions & 72 deletions Sublimall.py
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
import os
import sys
import hashlib
import imp
import sublime
from imp import reload
from os.path import expanduser

st_version = 2
if int(sublime.version()) > 3000:
Expand All @@ -14,9 +13,35 @@
msg = "Sublimall is only available for SublimeText 3.\n Sorry about that."
sublime.error_message(msg)

if sublime.platform() == 'linux':
so_name = '_ssl.cpython-33m.so'
arch_lib_path = os.path.join(
os.path.dirname(__file__),
'lib',
'st%d_linux_%s' % (st_version, sublime.arch()))

print('[Sublimall] enabling custom linux ssl module')
for ssl_ver in ['1.0.0', '10', '0.9.8']:
lib_path = os.path.join(arch_lib_path, 'libssl-' + ssl_ver)
sys.path.append(lib_path)
try:
import _ssl
print(
'[Sublimall] successfully loaded _ssl '
'module for libssl.so.%s' % ssl_ver)
import http.client
imp.reload(http.client)
break
except (ImportError) as e:
print('[Sublimall] _ssl module import error - ' + str(e))
if '_ssl' in sys.modules:
try:
import ssl
except (ImportError) as e:
print('[Sublimall] ssl module import error - ' + str(e))

reloader_name = 'Sublimall.sublimall.reloader'
if reloader_name in sys.modules:
print('******')
reload(sys.modules[reloader_name])


Expand All @@ -30,74 +55,5 @@ def plugin_loaded():
"Please install it and specify its path in the settings file.")
sublime.error_message(msg)

arch_lib_path = None
if sublime.platform() == 'linux':

so_name = '_ssl.cpython-33m.so'
arch_lib_path = os.path.join(
'Packages',
'Sublimall',
'lib',
'st%d_linux_%s' % (st_version, sublime.arch()))

lib_dir_tmp = os.path.join(
expanduser("~"),
'.sublimall',
'lib',
'st%d_linux_%s' % (st_version, sublime.arch()))
# If lib directory doesn't exist create it
if not os.path.exists(lib_dir_tmp):
os.makedirs(lib_dir_tmp)

print('[Sublimall] enabling custom linux ssl module')
for ssl_ver in ['1.0.0', '10', '0.9.8']:
lib_path = os.path.join(arch_lib_path, 'libssl-' + ssl_ver)
lib_path_tmp = os.path.join(lib_dir_tmp, 'libssl-' + ssl_ver)
must_copy = False

# If ssl specific version directory doesn't exist create it
if not os.path.exists(lib_path_tmp):
must_copy = True
os.makedirs(lib_path_tmp)

if not os.path.exists(
os.path.join(lib_path_tmp, so_name)):
must_copy = True
else:
m = hashlib.md5()
m.update(
sublime.load_binary_resource(
os.path.join(lib_path, so_name)))
source_digest = m.hexdigest()
m.update(open(os.path.join(lib_path_tmp, so_name), 'rb').read())
dest_digest = m.hexdigest()
if source_digest != dest_digest:
must_copy = True

if must_copy:
with open(os.path.join(lib_path_tmp, so_name), 'wb') as f:
f.write(sublime.load_binary_resource(
os.path.join(lib_path, so_name)))

sys.path.append(lib_path_tmp)
try:
import _ssl
sys.modules['ssl'] = sys.modules['_ssl']
print(
'[Sublimall] successfully loaded _ssl '
'module for libssl.so.%s' % ssl_ver)
break
except (ImportError) as e:
print('[Sublimall] _ssl module import error - ' + str(e))
if '_ssl' in sys.modules:
try:
import ssl
except (ImportError) as e:
print('[Sublimall] ssl module import error - ' + str(e))

# SSL Monkey patch for Linux
import http.client
reload(http.client)

from .sublimall import reloader
from .sublimall.commands import *
4 changes: 0 additions & 4 deletions create_package.sh

This file was deleted.

3 changes: 0 additions & 3 deletions install_package.sh

This file was deleted.

3 changes: 2 additions & 1 deletion sublimall/commands/retrieve_command.py
Expand Up @@ -171,7 +171,8 @@ def retrieve_from_server(self):
pass
show_report(
'Unhandled Http error while '
'downloading (%s).\n\n%s' % (r.status_code, r.content))
'downloading (%s).\n\n%s' % (r.status_code, r.content),
exception=False)
self.set_timed_message(msg, clear=True, time=10)
logger.error("HTTP [%s] %s" % (r.status_code, r.content))

Expand Down
2 changes: 1 addition & 1 deletion sublimall/commands/upload_command.py
Expand Up @@ -208,7 +208,7 @@ def send_to_api(self):
except:
pass
show_report('Unhandled Http error while uploading (%s).\n\n%s' % (
r.status_code, r.content))
r.status_code, r.content), exception=False)
self.set_timed_message(msg, clear=True, time=10)
logger.error('HTTP [%s] %s' % (r.status_code, r.content))

Expand Down
4 changes: 1 addition & 3 deletions sublimall/requests/packages/urllib3/connectionpool.py
Expand Up @@ -30,14 +30,12 @@
class BaseSSLError(BaseException):
pass

ssl = None

try: # Python 3
from http.client import HTTPSConnection
except ImportError:
from httplib import HTTPSConnection

import _ssl as ssl
import ssl
BaseSSLError = ssl.SSLError

except (ImportError, AttributeError): # Platform-specific: No SSL.
Expand Down

0 comments on commit 9bdb5c6

Please sign in to comment.