本文整理汇总了Python中sublime.packages_path方法的典型用法代码示例。如果您正苦于以下问题:Python sublime.packages_path方法的具体用法?Python sublime.packages_path怎么用?Python sublime.packages_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sublime
的用法示例。
在下文中一共展示了sublime.packages_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: package_of
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def package_of(path):
spp = sublime.packages_path()
spp_real = realpath(spp)
for p in {path, realpath(path)}:
for sp in {spp, spp_real}:
if p.startswith(sp + os.sep):
return p[len(sp):].split(os.sep)[1]
if not sys.platform.startswith("win"):
# we try to follow symlink if the real file is not located in spp
for d in os.listdir(spp):
subdir = os.path.join(spp, d)
subdir_real = realpath(subdir)
if not (os.path.islink(subdir) and os.path.isdir(subdir)):
continue
for sd in {subdir, subdir_real}:
for p in {path, realpath(path)}:
if p.startswith(sd + os.sep):
return d
return None
示例2: fix_scheme_in_settings
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def fix_scheme_in_settings(settings_file,current_scheme, new_scheme, regenerate=False):
"""Change the color scheme in the given Settings to a background-corrected one"""
from os.path import join, normpath, isfile
settings = load_settings(settings_file)
settings_scheme = settings.get("color_scheme")
if current_scheme == settings_scheme:
new_scheme_path = join(packages_path(), normpath(new_scheme[len("Packages/"):]))
if isfile(new_scheme_path) and not regenerate:
settings.set("color_scheme", new_scheme)
else:
generate_scheme_fix(current_scheme, new_scheme_path)
settings.set("color_scheme", new_scheme)
save_settings(settings_file)
return True
return False
示例3: generate_scheme_fix
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def generate_scheme_fix(old_scheme, new_scheme_path):
"""Appends background-correction XML to a color scheme file"""
from os.path import join
from re import sub
UUID_REGEX = '[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}'
with open(join(packages_path(),current_directory(),'background_fix.xml')) as f:
xml = f.read()
scheme_data = load_resource(old_scheme) # only valid for ST3 API!
insertion_point = scheme_data.rfind("</array>")
new_scheme_data = scheme_data[:insertion_point] + xml + scheme_data[insertion_point:]
def uuid_gen(args):
from uuid import uuid4
return str(uuid4())
new_scheme_data = sub(UUID_REGEX, uuid_gen, new_scheme_data)
with open(new_scheme_path, "wb") as f:
f.write(new_scheme_data.encode("utf-8"))
示例4: load_stream
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def load_stream(self, package, settings):
output = settings["output"]
if not output or output == "<panel>":
output_panel = OutputPanel(
'UnitTesting', file_regex=r'File "([^"]*)", line (\d+)')
output_panel.show()
stream = output_panel
else:
if not os.path.isabs(output):
if sublime.platform() == "windows":
output = output.replace("/", "\\")
output = os.path.join(sublime.packages_path(), package, output)
if os.path.exists(output):
os.remove(output)
stream = open(output, "w")
return stream
示例5: unified_mode
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def unified_mode():
source = UNIFIED_SETTINGS['source']
target = os.path.join(sublime.packages_path(), UNIFIED_SETTINGS['target'])
package = os.path.join(sublime.installed_packages_path(),
UNIFIED_SETTINGS['package'])
is_unified = get_settings().get('theme_unified', False)
main = os.path.join(sublime.packages_path(), PARENT, source)
if is_unified:
if not os.path.exists(target):
os.mkdir(target)
if os.path.exists(main):
copy_dir(main, target)
else:
extract_dir(package, source, target)
elif os.path.exists(target):
shutil.rmtree(target)
示例6: fetch_files
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def fetch_files(files, to=''):
if not path.exists(to, folder=True):
os.mkdir(to)
rq = Queue(maxsize=0)
user_path = path.join(sublime.packages_path(), 'User')
items = files.items()
for k, file in items:
decoded_name = path.decode(k)
name = path.join(user_path, decoded_name)
if should_exclude(name) and not should_include(name):
continue
rq.put((file['raw_url'], path.join(to, k)))
threads = min(10, len(items))
for i in range(threads):
worker = threading.Thread(target=download_file, args=(rq,))
worker.setDaemon(True)
worker.start()
time.sleep(0.1)
rq.join()
示例7: move_files
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def move_files(origin):
user_path = path.join(sublime.packages_path(), 'User')
for f in os.listdir(origin):
# set preferences and package control files to the final of the list
if fnmatch(f, '*Preferences.sublime-settings') or fnmatch(f, '*Package%20Control.sublime-settings'):
continue
name = path.join(user_path, path.decode(f))
directory = os.path.dirname(name)
if not path.exists(directory, True):
os.makedirs(directory)
shutil.move(path.join(origin, f), name)
pending_files = ['Preferences.sublime-settings', 'Package%20Control.sublime-settings']
for f in pending_files:
if not path.exists(path.join(origin, f)):
continue
shutil.move(path.join(origin, f), path.join(user_path, path.decode(f)))
示例8: load_history
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def load_history(rev=True, as_dict=False):
"""Returns list of past requests. Raises exception if history file doesn't
exist.
"""
history_file = sublime.load_settings('Requester.sublime-settings').get('history_file', None)
if not history_file:
raise KeyError
history_path = os.path.join(sublime.packages_path(), 'User', history_file)
with open(history_path, 'r') as f:
rh = json.loads(f.read() or '{}', object_pairs_hook=OrderedDict)
if as_dict:
return rh
requests = list(rh.items())
if rev:
requests.reverse()
return requests
示例9: move_requester_file
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def move_requester_file(view, old_path, new_path):
if os.path.exists(new_path):
sublime.error_message('Move Requester File Error: `{}` already exists'.format(new_path))
return
try:
os.rename(old_path, new_path)
except Exception:
sublime.error_message("Move Requester File Error: you couldn't move file to `{}`\n\n\
Remember to create the destination folder first".format(new_path))
return
window = view.window()
window.run_command('close_file')
window.open_file(new_path)
rh = load_history(as_dict=True)
for k, v in rh.items():
if v.get('file') == old_path:
v['file'] = new_path
config = sublime.load_settings('Requester.sublime-settings')
history_file = config.get('history_file', None)
write_json_file(rh, os.path.join(sublime.packages_path(), 'User', history_file))
示例10: on_activated_async
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def on_activated_async(self, view):
if view.settings().get('is_widget'):
return
if hasattr(self, "timer") and self.timer:
self.timer.cancel()
if not ride_settings.get("r_ide_menu", False):
return
def set_main_menu():
menu_path = os.path.join(
sublime.packages_path(), 'User', 'R-IDE', 'Main.sublime-menu')
if selector_is_active(view=view):
if not os.path.exists(menu_path):
generate_menu(menu_path)
else:
if os.path.exists(menu_path):
os.remove(menu_path)
self.timer = threading.Timer(0.5, set_main_menu)
self.timer.start()
示例11: get_template
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def get_template(created_file):
"""Return the right template for the create file"""
global TEMPLATE_FOLDER
if TEMPLATE_FOLDER is None:
TEMPLATE_FOLDER = os.path.join(sublime.packages_path(), "User", ".FileManager")
makedirs(TEMPLATE_FOLDER, exist_ok=True)
template_files = os.listdir(TEMPLATE_FOLDER)
for item in template_files:
if (
os.path.splitext(item)[0] == "template"
and os.path.splitext(item)[1] == os.path.splitext(created_file)[1]
):
return file_get_content(os.path.join(TEMPLATE_FOLDER, item))
return ""
示例12: xdotool
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def xdotool(*args):
xdotool_path = shutil.which("xdotool")
if not xdotool_path:
xdotool_install_path = os.path.join(sublime.packages_path(), "User", "SendCode", "xdotool")
if os.path.isfile(xdotool_install_path):
xdotool_path = xdotool_install_path
else:
global prompt_installing_xdotool
if not prompt_installing_xdotool:
sublime.active_window().run_command(
"send_code_install_xdotool", {"path": xdotool_install_path})
prompt_installing_xdotool = True
if not xdotool_path:
raise FileNotFoundError("xdotool cannot be found")
return subprocess.check_output([xdotool_path] + list(args))
示例13: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def run(self, src=None, dest=None):
if src is None:
src = os.path.join(sublime.packages_path(), SRC_DIR)
if dest is None:
dest = os.path.join(sublime.packages_path(), DEST_DIR)
output = sublime_lib.OutputPanel.create(self.window, "YAMLMacros")
output.show()
def run():
for file_name in FILES:
target_name, _ = os.path.splitext(file_name)
file_path, file_txt = get_file_txt(src, file_name)
yamlmacros.build(
source_text=file_txt,
destination_path=os.path.join(dest, target_name),
arguments={"file_path": file_path},
error_stream=output,
)
threading.Thread(target=run).start()
示例14: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def run(self, edit):
COMMANDS_HELP = sublime.load_resource('Packages/FileBrowser/shortcuts.md') if ST3 else ''
if not COMMANDS_HELP:
dest = dirname(__file__)
shortcuts = join(dest if dest != '.' else join(sublime.packages_path(), 'FileBrowser'), "shortcuts.md")
COMMANDS_HELP = open(shortcuts, "r").read()
self.view.erase(edit, Region(0, self.view.size()))
self.view.insert(edit, 0, COMMANDS_HELP)
self.view.sel().clear()
self.view.set_read_only(True)
# OTHER #############################################################
示例15: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import packages_path [as 别名]
def run(self):
SETTING_PATH = os.path.join(sublime.packages_path(), "User", SFDX_SETTINGS)
if not os.path.exists(SETTING_PATH):
s = sublime.load_settings(SFDX_SETTINGS)
tasks = s.get("tasks")
custom_env = s.get("custom_env")
s.set("tasks", tasks)
s.set("custom_env", custom_env)
sublime.save_settings(SFDX_SETTINGS)
self.window.run_command("open_file", {
"file": SETTING_PATH
})