forked from wbond/package_control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PackagesManager.py
182 lines (150 loc) · 6.38 KB
/
PackagesManager.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
import sublime
import sys
import os
import shutil
st_version = 2 if sys.version_info < (3,) else 3
if st_version == 3:
from .package_control import text, sys_path
installed_dir, _ = __name__.split('.')
package_path = os.path.join(sys_path.installed_packages_path, 'PackagesManager.sublime-package')
pc_python_path = os.path.join(sys_path.packages_path, 'PackagesManager', 'PackagesManager.py')
has_packed = os.path.exists(package_path)
has_unpacked = os.path.exists(pc_python_path)
elif st_version == 2:
from package_control import text, sys_path
installed_dir = os.path.basename(os.getcwd())
# Ensure the user has installed PackagesManager properly
if installed_dir != 'PackagesManager':
message = text.format(
u'''
PackagesManager
This package appears to be installed incorrectly.
It should be installed as "PackagesManager", but seems to be installed
as "%s".
To fix the issue, please:
1. Open the "Preferences" menu
2. Select "Browse Packages\u2026"
''',
installed_dir,
strip=False
)
# If installed unpacked
if os.path.exists(os.path.join(sys_path.packages_path, installed_dir)):
message += text.format(
u'''
3. Rename the folder "%s" to "PackagesManager"
4. Restart Sublime Text
''',
installed_dir
)
# If installed as a .sublime-package file
else:
message += text.format(
u'''
3. Browse up a folder
4. Browse into the "Installed Packages/" folder
5. Rename "%s.sublime-package" to "PackagesManager.sublime-package"
6. Restart Sublime Text
''',
installed_dir
)
sublime.error_message(message)
elif st_version == 3 and has_packed and has_unpacked:
message = text.format(
u'''
PackagesManager
It appears you have PackagesManager installed as both a
.sublime-package file and a directory inside of the Packages folder.
To fix this issue, please:
1. Open the "Preferences" menu
2. Select "Browse Packages\u2026"
3. Delete the folder "PackagesManager"
4. Restart Sublime Text
'''
)
sublime.error_message(message)
# Normal execution will finish setting up the package
else:
if st_version == 3:
from .package_control.commands import * # noqa
from .package_control.package_cleanup import PackageCleanup
from .package_control.unicode import tempfile_unicode_patch
from .package_control.console_write import console_write
from .package_control.settings import pc_settings_filename
else:
from package_control.commands import * # noqa
from package_control.package_cleanup import PackageCleanup
from package_control.unicode import tempfile_unicode_patch
from package_control.console_write import console_write
from package_control.settings import pc_settings_filename
def plugin_loaded():
# Make sure the user's locale can handle non-ASCII. A whole bunch of
# work was done to try and make PackagesManager work even if the locale
# was poorly set, by manually encoding all file paths, but it ended up
# being a fool's errand since the package loading code built into
# Sublime Text is not written to work that way, and although packages
# could be installed, they could not be loaded properly.
try:
os.path.exists(os.path.join(sublime.packages_path(), u"fran\u2013ais"))
except (UnicodeEncodeError):
message = text.format(
u'''
PackagesManager
Your system's locale is set to a value that can not handle
non-ASCII characters. PackagesManager can not properly work
unless this is fixed.
On Linux, please reference your distribution's docs for
information on properly setting the LANG and LC_CTYPE
environmental variables. As a temporary work-around, you can
launch Sublime Text from the terminal with:
LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 sublime_text
'''
)
sublime.error_message(message)
return
# This handles fixing unicode issues with tempdirs on ST2 for Windows
tempfile_unicode_patch()
# Ensure we have a Cache dir we can use for temporary data
if not os.path.exists(sys_path.pc_cache_dir()):
os.makedirs(sys_path.pc_cache_dir(), exist_ok=True)
# Clean up the old HTTP cache dir
legacy_http_cache = os.path.join(sublime.packages_path(), u'User', u'Package Control.cache')
http_cache = os.path.join(sys_path.pc_cache_dir(), 'http_cache')
if os.path.exists(legacy_http_cache):
if not os.path.exists(http_cache):
console_write(
u'''
Moving HTTP cache data into "Cache/Package Control/http_cache/"
'''
)
shutil.move(legacy_http_cache, http_cache)
else:
console_write(
u'''
Removing old HTTP cache data"
'''
)
shutil.rmtree(legacy_http_cache)
# Clean up old CA bundle paths
legacy_ca_filenames = [
'Package Control.system-ca-bundle',
'Package Control.merged-ca-bundle',
'oscrypto-ca-bundle.crt'
]
for legacy_ca_filename in legacy_ca_filenames:
legacy_ca_path = os.path.join(sublime.packages_path(), 'User', legacy_ca_filename)
if os.path.exists(legacy_ca_path):
os.unlink(legacy_ca_path)
pc_settings = sublime.load_settings(pc_settings_filename())
if not pc_settings.get('bootstrapped'):
console_write(
u'''
Not running package cleanup since bootstrapping is not yet complete
'''
)
else:
# Start shortly after Sublime starts so package renames don't cause errors
# with keybindings, settings, etc disappearing in the middle of parsing
sublime.set_timeout(lambda: PackageCleanup().start(), 2000)
if st_version == 2:
plugin_loaded()