Python sublime.find_resources() Examples
The following are 11
code examples of sublime.find_resources().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sublime
, or try the search function
.
Example #1
Source File: ShellExec.py From sublime-3-shell-exec with MIT License | 6 votes |
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
Example #2
Source File: file.py From GitSavvy with MIT License | 6 votes |
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)
Example #3
Source File: syntax.py From UnitTesting with MIT License | 5 votes |
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()
Example #4
Source File: syntax.py From UnitTesting with MIT License | 5 votes |
def syntax_testing(self, stream, package): try: syntaxes = sublime.find_resources("*.sublime-syntax") syntaxes = [s for s in syntaxes if s.startswith("Packages/%s/" % package)] if not syntaxes: raise RuntimeError("No sublime-syntax files found in %s!" % package) total_errors = 0 total_failed_syntaxes = 0 for syntax in syntaxes: results = sublime_api.incompatible_syntax_patterns(syntax) for location, _, message in results: stream.write("%s:%d:%d: %s\n" % (syntax, location[0] + 1, location[0] + location[1], message)) if results: total_errors += len(results) total_failed_syntaxes += 1 if total_errors: stream.write("FAILED: %d errors in %d of %d syntaxes\n" % ( total_errors, total_failed_syntaxes, len(syntaxes))) else: stream.write("Success: %d syntaxes passed\n" % (len(syntaxes),)) 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()
Example #5
Source File: theme_generator.py From GitSavvy with MIT License | 5 votes |
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])
Example #6
Source File: reload.py From GitSavvy with MIT License | 5 votes |
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 ]
Example #7
Source File: file.py From GitSavvy with MIT License | 5 votes |
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)
Example #8
Source File: scratch_buffer.py From SublimeScraps with MIT License | 5 votes |
def parse(self, langs, resource_spec): for syntax in sublime.find_resources(resource_spec): langs[_syntax_name(syntax)] = syntax
Example #9
Source File: theme.py From Terminus with MIT License | 5 votes |
def get_theme_files(self): for f in sublime.find_resources("*.json"): if f.startswith("Packages/Terminus/themes/"): yield f.replace("Packages/Terminus/themes/", "")
Example #10
Source File: reloader.py From AutomaticPackageReloader with MIT License | 4 votes |
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
Example #11
Source File: st_color_scheme_matcher.py From sublime-markdown-popups with MIT License | 4 votes |
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)