forked from wbond/package_control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.py
187 lines (150 loc) · 7.22 KB
/
bootstrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import sys
import threading
import os
from textwrap import dedent
import sublime
# Clean up the installed and pristine packages for Package Control 2 to
# prevent a downgrade from happening via Sublime Text
if sys.version_info < (3,):
sublime_dir = os.path.dirname(sublime.packages_path())
pristine_dir = os.path.join(sublime_dir, 'Pristine Packages')
installed_dir = os.path.join(sublime_dir, 'Installed Packages')
pristine_file = os.path.join(pristine_dir, 'Package Control.sublime-package')
installed_file = os.path.join(installed_dir, 'Package Control.sublime-package')
if os.path.exists(pristine_file):
os.remove(pristine_file)
if os.path.exists(installed_file):
os.remove(installed_file)
# Make sure we have recent code in memory
reloader_name = 'package_control.reloader'
if sys.version_info >= (3,):
reloader_name = 'Package Control.' + reloader_name
from imp import reload
if reloader_name in sys.modules:
reload(sys.modules[reloader_name])
if sys.version_info < (3,):
from package_control.bootstrap import bootstrap_dependency
from package_control.package_manager import PackageManager
from package_control import loader, text
from package_control.settings import pc_settings_filename, load_list_setting, save_list_setting
import package_control
else:
from .package_control.bootstrap import bootstrap_dependency
from .package_control.package_manager import PackageManager
from .package_control import loader, text
from .package_control.settings import pc_settings_filename, load_list_setting, save_list_setting
from . import package_control
def plugin_loaded():
manager = PackageManager()
settings = manager.settings.copy()
if not loader.exists('package_control'):
base_loader_code = """
import sys
import os
from os.path import dirname
# This file adds the package_control subdirectory of Package Control
# to first in the sys.path so that all other packages may rely on
# PC for utility functions, such as event helpers, adding things to
# sys.path, downloading files from the internet, etc
if sys.version_info >= (3,):
def decode(path):
return path
def encode(path):
return path
loader_dir = dirname(__file__)
else:
def decode(path):
if not isinstance(path, unicode):
path = path.decode(sys.getfilesystemencoding())
return path
def encode(path):
if isinstance(path, unicode):
path = path.encode(sys.getfilesystemencoding())
return path
loader_dir = decode(os.getcwd())
st_dir = dirname(dirname(loader_dir))
found = False
if sys.version_info >= (3,):
installed_packages_dir = os.path.join(st_dir, u'Installed Packages')
pc_package_path = os.path.join(installed_packages_dir, u'Package Control.sublime-package')
if os.path.exists(encode(pc_package_path)):
found = True
if not found:
packages_dir = os.path.join(st_dir, u'Packages')
pc_package_path = os.path.join(packages_dir, u'Package Control')
if os.path.exists(encode(pc_package_path)):
found = True
if found:
if os.name == 'nt':
from ctypes import windll, create_unicode_buffer
buf = create_unicode_buffer(512)
if windll.kernel32.GetShortPathNameW(pc_package_path, buf, len(buf)):
pc_package_path = buf.value
sys.path.insert(0, encode(pc_package_path))
import package_control
# We remove the import path right away so as not to screw up
# Sublime Text and its import machinery
sys.path.remove(encode(pc_package_path))
else:
print(u'Package Control: Error finding main directory from loader')
"""
base_loader_code = dedent(base_loader_code).lstrip()
loader.add('00', 'package_control', base_loader_code)
# SSL support fo Linux
if sublime.platform() == 'linux':
linux_ssl_url = u'http://packagecontrol.io/ssl/1.0.1/ssl-linux.sublime-package'
linux_ssl_hash = u'862d061cbe666777cd1e9cd1cbc7c82f48ad8897dbb68332975f3edf5ce0f38d'
linux_ssl_priority = u'01'
linux_ssl_version = '1.0.1'
def linux_ssl_show_restart():
sublime.message_dialog(text.format(
u'''
Package Control
Package Control just installed or upgraded the missing Python
_ssl module for Linux since Sublime Text does not include it.
Please restart Sublime Text to make SSL available to all
packages.
'''
))
linux_ssl_args = (settings, linux_ssl_url, linux_ssl_hash,
linux_ssl_priority, linux_ssl_version, linux_ssl_show_restart)
threading.Thread(target=bootstrap_dependency, args=linux_ssl_args).start()
# SSL support for SHA-2 certificates with ST2 on Windows
if sublime.platform() == 'windows' and sys.version_info < (3,):
win_ssl_url = u'http://packagecontrol.io/ssl/1.0.0/ssl-windows.sublime-package'
win_ssl_hash = u'3c28982eb400039cfffe53d38510556adead39ba7321f2d15a6770d3ebc75030'
win_ssl_priority = u'01'
win_ssl_version = u'1.0.0'
def win_ssl_show_restart():
sublime.message_dialog(text.format(
u'''
Package Control
Package Control just upgraded the Python _ssl module for ST2 on
Windows because the bundled one does not include support for
modern SSL certificates.
Please restart Sublime Text to complete the upgrade.
'''
))
win_ssl_args = (settings, win_ssl_url, win_ssl_hash, win_ssl_priority,
win_ssl_version, win_ssl_show_restart)
threading.Thread(target=bootstrap_dependency, args=win_ssl_args).start()
pc_settings = sublime.load_settings(pc_settings_filename())
# Make sure we are track Package Control itself
installed_packages = load_list_setting(pc_settings, 'installed_packages')
if 'Package Control' not in installed_packages:
params = {
'package': 'Package Control',
'operation': 'install',
'version': package_control.__version__
}
manager.record_usage(params)
installed_packages.append('Package Control')
save_list_setting(pc_settings, pc_settings_filename(), 'installed_packages', installed_packages)
# We no longer use the installed_dependencies setting because it is not
# necessary and created issues with settings shared across operating systems
if pc_settings.get('installed_dependencies'):
pc_settings.erase('installed_dependencies')
sublime.save_settings(pc_settings_filename())
# ST2 compat
if sys.version_info < (3,):
plugin_loaded()