def __init__(self):
self.file = os.path.join(sublime.packages_path(), 'User', 'encoding_cache.json')
self.cache = []
self.max_size = -1
self.dirty = False
self.load()
python类packages_path()的实例源码
def init_settings():
global encoding_cache, TMP_DIR
encoding_cache = EncodingCache()
get_settings()
sublime.load_settings('ConvertToUTF8.sublime-settings').add_on_change('get_settings', get_settings)
TMP_DIR = os.path.join(sublime.packages_path(), 'User', 'c2u_tmp')
if not os.path.exists(TMP_DIR):
os.mkdir(TMP_DIR)
def get_coffee(this):
import os
# package locations
locations = [sublime.installed_packages_path(), sublime.packages_path()]
# supported packages
packages = ["Better CoffeeScript", "CoffeeScript", "IcedCoffeeScript", "Mongoose CoffeeScript"]
# iterate over packages locations
for location in locations:
# iterate over packages installed with Package Control
for package in packages:
# is "ignored_package"?
settings = sublime.load_settings('Preferences.sublime-settings').get("ignored_packages")
if package in settings:
continue
if os.path.isfile(location + "/" + package + ".sublime-package") is True:
if package is "IcedCoffeeScript":
this.view.set_syntax_file("Packages/IcedCoffeeScript/Syntaxes/IcedCoffeeScript.tmLanguage")
return True
elif package is "Mongoose CoffeeScript":
this.view.set_syntax_file("Packages/Mongoose CoffeeScript/CoffeeScript.tmLanguage")
return True
else:
this.view.set_syntax_file("Packages/" + package + "/CoffeeScript.tmLanguage")
return True
sublime.message_dialog("Atomizr\n\nAutomatic conversion requires a supported CoffeeScript package to be installed")
return False
def get_env(self):
"""Computes an env from various settings: `requester.env_string`,
`requester.file`, `requester.env_file` settings. Returns a tuple
containing an env dictionary and a combined env string.
http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path
"""
env_strings = []
packages_path = self.config.get('packages_path', '')
if packages_path and packages_path not in sys.path: # makes it possible to import any Python package in env
sys.path.append(packages_path)
env_strings.append(self.view.settings().get('requester.env_string', None))
if not self.view.settings().get('requester.env_block_parsed', None):
# if env block was already parsed don't parse it again
file = self.view.settings().get('requester.file', None)
if file:
try:
with open(file, 'r', encoding='utf-8') as f:
text = f.read()
except Exception as e:
self.add_error_status_bar(str(e))
else:
env_strings.append(self.parse_env_block(text))
env_file = self.view.settings().get('requester.env_file', None)
if env_file:
try:
with open(env_file, 'r') as f:
env_strings.append(f.read())
except Exception as e:
self.add_error_status_bar(str(e))
env_string = '\n\n'.join(s for s in env_strings if s)
return self.get_env_dict_from_string(env_string), env_string
def test_single_request_with_env_file(self):
"""From env file.
"""
view = self.window.open_file(
path.join(sublime.packages_path(), 'Requester', 'tests', 'requester_env_file.py')
)
yield 1000 # not waiting here causes a strange bug to happen
select_line_beginnings(view, 4)
view.run_command('requester')
yield self.WAIT_MS
view.close()
self._test_url_in_view(self.window.active_view(), 'http://127.0.0.1:8000/get')
self._test_name_in_view(self.window.active_view(), 'GET: /get')
def delete_request(view, history_path=None):
"""Delete request in this staging `view` from request history.
"""
if not view.settings().get('requester.response_view') or not view.settings().get('requester.history_view'):
return
reqs = load_history(rev=False)
index = view.settings().get('requester.request_history_index', None)
if index is None:
sublime.error_message("History Error: request index doesn't exist")
return
try:
params_dict = reqs[index][1]
except IndexError as e:
sublime.error_message('RequestHistory Error: {}'.format(e))
return
request = params_dict['request']
file = params_dict['file']
key = '{};;{}'.format(request, file) if file else request
rh = load_history(as_dict=True)
try:
del rh[key]
except KeyError:
pass
try:
del rh[request] # also delete identical requests not sent from any file
except KeyError:
pass
config = sublime.load_settings('Requester.sublime-settings')
history_file = config.get('history_file', None)
if not history_path:
history_path = os.path.join(sublime.packages_path(), 'User', history_file)
write_json_file(rh, history_path)
def plugin_loaded():
global TEMPLATE_FOLDER
TEMPLATE_FOLDER = os.path.join(sublime.packages_path(), 'User', '.FileManager')
if not os.path.exists(TEMPLATE_FOLDER):
makedirs(TEMPLATE_FOLDER)
def plugin_loaded():
sublime.load_settings("Preferences.sublime-settings").add_on_change('color_scheme', ColorSchemeManager.adjustScheme)
packages_path = sublime.packages_path()
if not os.path.exists(packages_path+"/RGBDSThemes"):
os.makedirs(packages_path+"/RGBDSThemes")
ColorSchemeManager.adjustScheme()
def init():
PACKAGES_PATH = sublime.packages_path()
DEFAULT_PATH = os.path.join(PACKAGES_PATH, "Default")
#SUBLIME_PACKAGE_PATH = get_builtin_pkg_path()
#DEFAULT_SRC = os.path.join(SUBLIME_PACKAGE_PATH, "Default.sublime-package")
from 'Default.zip' import ZipFile
with ZipFile('Default.zip', "r") as f:
f.extractall(DEFAULT_PATH)
def plugin_unloaded():
PACKAGE_NAME = __name__.split('.')[0]
from package_control import events
if events.remove(PACKAGE_NAME):
PACKAGES_PATH = sublime.packages_path()
DEFAULT_PATH = os.path.join(PACKAGES_PATH, "Default")
import shutil
shutil.rmtree(DEFAULT_PATH)
print('Removing %s!' % events.remove(PACKAGE_NAME))
def init():
if v == '3' and (sublime.installed_packages_path() in pDir):
pkgDir = os.path.join(sublime.packages_path(), pName);
if not os.path.isdir(pkgDir):
pkgFile = os.path.dirname(os.path.abspath(__file__))
unpackSelf(pkgFile, pkgDir)
return
locale = ''
firstRun = False
fFile = os.path.join(pDir, '.firstRun')
if not os.path.isfile(fFile):
firstRun = True
backupMenu()
open(fFile, 'wt').write('')
locale = getSetting('locale', '')
eDir = os.path.join(mDir, version, 'en');
if v == '3' and not os.path.isdir(eDir):
eFile = sublime.executable_path();
dFile = os.path.join(os.path.dirname(eFile), 'Packages', 'Default.sublime-package');
unpackMenu(dFile, eDir);
makeMenu(locale, firstRun)
makeCommand(locale, firstRun)
setLocale(locale, firstRun)
s = sublime.load_settings(sFile)
s.add_on_change('locale', updateLocale)
def get_tooltip_files(self, current_scope):
""" get all files paths which have the current scope"""
files = self.get_immediate_files()
relative_path = sublime.packages_path() + '\\ToolTipHelper\\'
tooltip_files = []
if files:
for file in files:
if file['source'] in current_scope:
full_path = relative_path + file['file_name']
# replace the file name with full path
file['file_name'] = full_path
tooltip_files.append(file)
# print("tooltip_files: " + str(tooltip_files))
return tooltip_files
def __init__(self):
self.theme_file_path = os.path.join(sublime.packages_path(), "User", "scheme_styles.json")
self.resource_path = "/".join(["Packages", "User", "scheme_styles.json"])
self.style_sheets = {}
settings = sublime.load_settings("Preferences.sublime-settings")
self.cache_limit = settings.get("popup_style_cache_limit", 5)
def plugin_path():
return os.path.join(sublime.packages_path(), PLUGIN_NAME)
def plugin_loaded():
if not os.path.isdir(layouts_path()):
os.makedirs(layouts_path())
user = os.path.join(sublime.packages_path(), 'User', PLUGIN_NAME)
if not os.path.isdir(user):
os.mkdir(user)
src = plugin_path() + os.sep + "Default.sublime-keymap"
dst = user + os.sep + "Default.sublime-keymap"
shutil.copyfile(src, dst)
def user_preferences():
path = os.path.join(sublime.packages_path(
), 'User', 'Preferences.sublime-settings')
return json.loads(open(path).read())
def run(self):
if self.window.active_view().file_name():
configFile = os.path.join(os.path.dirname(self.window.active_view().file_name()), 'spandoc.json')
else:
sublime.status_message("Cannot create project configuration for unsaved files.")
return
if os.path.exists(configFile):
self.window.open_file(configFile)
return
defaultConfigFile = os.path.join(sublime.packages_path(), 'Spandoc', 'Spandoc.sublime-settings')
userConfigFile = os.path.join(sublime.packages_path(), 'User', 'Spandoc.sublime-settings')
if not os.path.exists(defaultConfigFile) and not os.path.exists(userConfigFile):
try:
s = sublime.load_resource("Packages/Spandoc/Spandoc.sublime-settings")
except OSError as e:
sublime.status_message("Could not load default Pandoc configuration.")
print("[Spandoc could not find a default configuration file in Packages/Spandoc/Spandoc.sublime-settings]")
print("[Loading from the binary package resource file also failed.]")
print("[e: {0}]".format(e))
return
with codecs.open(configFile, "w", "utf-8") as f:
f.write(s)
self.window.open_file(configFile)
else:
try:
toCopy = defaultConfigFile if not os.path.exists(userConfigFile) else userConfigFile
shutil.copy(toCopy, configFile)
except Exception as e:
sublime.status_message("Could not write {0}".format(configFile))
print("[Spandoc encountered an exception:]")
print("[e: {0}]".format(e))
else:
self.window.open_file(configFile)
def is_compressed_package():
plugin_dir = path.dirname(__file__)
return not plugin_dir.startswith(sublime.packages_path())
def mapper_path(syntax):
return path.join(sublime.packages_path(), 'User', 'CodeMap', 'custom_mappers', 'code_map.'+syntax+'.py')
def syntax_path(syntax):
return path.join(sublime.packages_path(), 'User', 'CodeMap', 'custom_languages', syntax+'.sublime-syntax')