本文整理汇总了Python中sublime.find_resources方法的典型用法代码示例。如果您正苦于以下问题:Python sublime.find_resources方法的具体用法?Python sublime.find_resources怎么用?Python sublime.find_resources使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sublime
的用法示例。
在下文中一共展示了sublime.find_resources方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_output_file
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import find_resources [as 别名]
def new_output_file(args, pure_command):
if ShellExec.get_setting('debug', args):
print('open new empty file: ' + pure_command)
output_file = sublime.active_window().new_file()
output_file.set_name(pure_command[0:60])
output_file.set_scratch(True)
if ShellExec.get_setting('output_syntax', args):
if ShellExec.get_setting('debug', args):
print('set output syntax: ' + ShellExec.get_setting('output_syntax', args))
if sublime.find_resources(ShellExec.get_setting('output_syntax', args) + '.tmLanguage'):
output_file.set_syntax_file(sublime.find_resources(ShellExec.get_setting('output_syntax', args) + '.tmLanguage')[0])
if ShellExec.get_setting('output_word_wrap', args):
output_file.settings().set('word_wrap', True)
else:
output_file.settings().set('word_wrap', False)
return output_file
示例2: handle_tm_language_files
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import find_resources [as 别名]
def handle_tm_language_files():
# type: () -> None
syntax_files = sublime.find_resources("*.tmLanguage")
for syntax_file in syntax_files:
try:
resource = sublime.load_binary_resource(syntax_file)
except Exception:
print("GitSavvy: could not load {}".format(syntax_file))
continue
try:
extensions = plistlib.readPlistFromBytes(resource).get("fileTypes", [])
except Exception:
print("GitSavvy: could not parse {}".format(syntax_file))
continue
for extension in extensions:
syntax_file_map[extension].append(syntax_file)
示例3: syntax_testing
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import find_resources [as 别名]
def syntax_testing(self, stream, package):
total_assertions = 0
failed_assertions = 0
try:
tests = sublime.find_resources("syntax_test*")
tests = [t for t in tests if t.startswith("Packages/%s/" % package)]
if not tests:
raise RuntimeError("No syntax_test files are found in %s!" % package)
for t in tests:
assertions, test_output_lines = sublime_api.run_syntax_test(t)
total_assertions += assertions
if len(test_output_lines) > 0:
failed_assertions += len(test_output_lines)
for line in test_output_lines:
stream.write(line + "\n")
if failed_assertions > 0:
stream.write("FAILED: %d of %d assertions in %d files failed\n" %
(failed_assertions, total_assertions, len(tests)))
else:
stream.write("Success: %d assertions in %s files passed\n" %
(total_assertions, len(tests)))
stream.write("OK\n")
except Exception as e:
if not stream.closed:
stream.write("ERROR: %s\n" % e)
stream.write("\n")
stream.write(DONE_MESSAGE)
stream.close()
示例4: __init__
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import find_resources [as 别名]
def __init__(self, original_color_scheme):
self._dirty = False
try:
self.color_scheme_string = sublime.load_resource(original_color_scheme)
except IOError:
# then use sublime.find_resources
paths = sublime.find_resources(original_color_scheme)
if not paths:
raise IOError("{} cannot be found".format(original_color_scheme))
for path in paths:
if path.startswith("Packages/User/"):
# load user specfic theme first
self.color_scheme_string = sublime.load_resource(path)
break
self.color_scheme_string = sublime.load_resource(paths[0])
示例5: package_plugins
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import find_resources [as 别名]
def package_plugins(pkg_name):
return [
pkg_name + '.' + posixpath.basename(posixpath.splitext(path)[0])
for path in sublime.find_resources("*.py")
if posixpath.dirname(path) == 'Packages/' + pkg_name
]
示例6: handle_sublime_syntax_files
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import find_resources [as 别名]
def handle_sublime_syntax_files():
# type: () -> None
syntax_files = sublime.find_resources("*.sublime-syntax")
for syntax_file in syntax_files:
try:
resource = sublime.load_resource(syntax_file)
except Exception:
print("GitSavvy: could not load {}".format(syntax_file))
continue
for extension in try_parse_for_file_extensions(resource) or []:
syntax_file_map[extension].append(syntax_file)
示例7: parse
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import find_resources [as 别名]
def parse(self, langs, resource_spec):
for syntax in sublime.find_resources(resource_spec):
langs[_syntax_name(syntax)] = syntax
示例8: get_theme_files
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import find_resources [as 别名]
def get_theme_files(self):
for f in sublime.find_resources("*.json"):
if f.startswith("Packages/Terminus/themes/"):
yield f.replace("Packages/Terminus/themes/", "")
示例9: get_package_modules
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import find_resources [as 别名]
def get_package_modules(package_names):
package_names = set(package_names)
package_path_bases = [
p
for pkg_name in package_names
for p in (
os.path.join(
sublime.installed_packages_path(),
pkg_name + '.sublime-package'
),
os.path.join(sublime.packages_path(), pkg_name),
)
]
def module_paths(module):
try:
yield module.__file__
except AttributeError:
pass
try:
yield from module.__path__
except AttributeError:
pass
for module in sys.modules.values():
try:
base, path = next(
(base, path)
for path in module_paths(module)
for base in package_path_bases
if path and (path == base or path.startswith(base + os.sep))
)
except StopIteration:
continue
else:
is_plugin = (os.path.dirname(path) == base)
yield module.__name__, is_plugin
# get all the top level plugins in case they were removed from sys.modules
for path in sublime.find_resources("*.py"):
for pkg_name in package_names:
if posixpath.dirname(path) == 'Packages/'+pkg_name:
yield pkg_name + '.' + posixpath.basename(posixpath.splitext(path)[0]), True
示例10: merge_overrides
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import find_resources [as 别名]
def merge_overrides(self):
"""Merge override schemes."""
package_overrides = []
user_overrides = []
if self.scheme_file.endswith('.hidden-color-scheme'):
pattern = '%s.hidden-color-scheme'
else:
pattern = '%s.sublime-color-scheme'
for override in sublime.find_resources(pattern % path.splitext(self.scheme_file)[0]):
if override.startswith('Packages/User/'):
user_overrides.append(override)
else:
package_overrides.append(override)
for override in (package_overrides + user_overrides):
try:
ojson = sublime.decode_value(sublime.load_resource(override))
except IOError:
# Fallback if file was created manually and not yet found in resources
# Though it is unlikely this would ever get executed as `find_resources`
# probably wouldn't have seen it either.
with codecs.open(packages_path(override), 'r', encoding='utf-8') as f:
ojson = sublime.decode_value(sanitize_json(f.read()))
for k, v in ojson.get('variables', {}).items():
self.scheme_obj['variables'][k] = v
for k, v in ojson.get(GLOBAL_OPTIONS, {}).items():
self.scheme_obj[GLOBAL_OPTIONS][k] = v
for item in ojson.get('rules', []):
self.scheme_obj['rules'].append(item)
self.overrides.append(override)
# Rare case of being given a file but sublime hasn't indexed the files and can't find it
if (
not self.overrides and
self.color_scheme.endswith(('.sublime-color-scheme', '.hidden-color-scheme')) and
self.color_scheme.startswith('Packages/')
):
with codecs.open(packages_path(self.color_scheme), 'r', encoding='utf-8') as f:
ojson = sublime.decode_value(sanitize_json(f.read()))
for k, v in ojson.get('variables', {}).items():
self.scheme_obj['variables'][k] = v
for k, v in ojson.get(GLOBAL_OPTIONS, {}).items():
self.scheme_obj[GLOBAL_OPTIONS][k] = v
for item in ojson.get('rules', []):
self.scheme_obj['rules'].append(item)
self.overrides.append(self.color_scheme)