-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathRESTer.py
61 lines (54 loc) · 2.1 KB
/
RESTer.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
"""
Sublime imports modules it finds in package roots, but will not look deeper.
This module loads the modules needed for the package and manages reloading
of these dependencies when this module is itself reloaded.
"""
import os
import sys
import sublime
EXPECTED_PACKAGE_DIR = "RESTer HTTP Client"
RELOADER_NAME = "rester.reloader"
if int(sublime.version()) > 3000:
ST_VERSION = 3
PACKAGE_DIR = __name__.split('.')[0]
else:
ST_VERSION = 2
PACKAGE_DIR = os.path.basename(os.getcwd())
# Ensure the package is installed in the correct directory.
# The menu commands will not work properly otherwise.
if PACKAGE_DIR != EXPECTED_PACKAGE_DIR:
m = u'RESTer appears to be installed incorrectly.\n\n' \
u'It should be installed as "%s", but is installed as "%s".\n\n'
message = m % (EXPECTED_PACKAGE_DIR, PACKAGE_DIR)
# If installed unpacked
if os.path.exists(os.path.join(sublime.packages_path(), PACKAGE_DIR)):
m = u'Please use the Preferences > Browse Packages... menu ' \
u'entry to open the "Packages/" folder and rename "%s" to "%s" '
message += m % (PACKAGE_DIR, EXPECTED_PACKAGE_DIR)
# If installed as a .sublime-package file
else:
m = u'Please use the Preferences > Browse Packages... menu ' \
u'entry to open the "Packages/" folder, then browse up a ' \
u'folder and into the "Installed Packages/" folder.\n\n' \
u'Inside of "Installed Packages/", rename ' \
u'"%s.sublime-package" to "%s.sublime-package" '
message += m % (PACKAGE_DIR, EXPECTED_PACKAGE_DIR)
message += u"and restart Sublime Text."
sublime.error_message(message)
# Reload modules.
reloader_name = RELOADER_NAME
if ST_VERSION == 3:
reloader_name = PACKAGE_DIR + "." + reloader_name
from imp import reload
if reloader_name in sys.modules:
reload(sys.modules[reloader_name])
# Initial loading.
try:
# Python 3
from .rester import reloader
from .rester.commands import *
from .rester.phantoms import *
except ValueError:
# Python 2
from rester import reloader
from rester.commands import *