我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用sublime.executable_path()。
def run(self, paths = []): import subprocess items = [] executable_path = sublime.executable_path() if sublime.platform() == 'osx': app_path = executable_path[:executable_path.rfind(".app/")+5] executable_path = app_path+"Contents/SharedSupport/bin/subl" items.append(executable_path) for item in SideBarSelection(paths).getSelectedItems(): items.append(item.forCwdSystemPath()) items.append(item.path()) subprocess.Popen(items, cwd=items[1])
def find_resource(resource_pattern, package=None): file_set = set() if package == None: for package in get_packages_list(): file_set.update(find_resource(resource_pattern, package)) ret_list = list(file_set) else: file_set.update(_find_directory_resource(os.path.join(sublime.packages_path(), package), resource_pattern)) if VERSION >= 3006: zip_location = os.path.join(sublime.installed_packages_path(), package + ".sublime-package") file_set.update(_find_zip_resource(zip_location, resource_pattern)) zip_location = os.path.join(os.path.dirname(sublime.executable_path()), "Packages", package + ".sublime-package") file_set.update(_find_zip_resource(zip_location, resource_pattern)) ret_list = map(lambda e: package + "/" + e, file_set) return sorted(ret_list)
def get_builtin_pkg_path(): base_path = os.path.dirname(sublime.executable_path()) ret = os.path.join(base_path, 'Packages') return ret
def get_subl_executable_path(): """Return the path to the subl command line binary.""" executable_path = sublime.executable_path() if sublime.platform() == 'osx': suffix = '.app/' app_path = executable_path[:executable_path.rfind(suffix) + len(suffix)] executable_path = app_path + 'Contents/SharedSupport/bin/subl' return executable_path # popen utils
def handle_thread(thread, msg=None, counter=0, direction=1, width=8): if thread.is_alive(): next = counter + direction if next > width: direction = -1 elif next < 0: direction = 1 bar = [' '] * (width + 1) bar[counter] = '=' counter += direction status('%s [%s]' % (msg, ''.join(bar))) sublime.set_timeout(lambda: handle_thread(thread, msg, counter, direction, width), 100) else: status(' ok ') # # Code lifted from https://github.com/randy3k/ProjectManager/blob/master/pm.py # def subl(args=[]): # # learnt from SideBarEnhancements # executable_path = sublime.executable_path() # print('executable_path: '+ executable_path) # if sublime.platform() == 'linux': # subprocess.Popen([executable_path] + [args]) # if sublime.platform() == 'osx': # app_path = executable_path[:executable_path.rfind(".app/") + 5] # executable_path = app_path + "Contents/SharedSupport/bin/subl" # subprocess.Popen([executable_path] + args) # if sublime.platform() == "windows": # def fix_focus(): # window = sublime.active_window() # view = window.active_view() # window.run_command('focus_neighboring_group') # window.focus_view(view) # sublime.set_timeout(fix_focus, 300) ########################################################################################## #Python Util ##########################################################################################
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 default_preferences(): packages = os.path.dirname(sublime.executable_path()) + os.sep + 'Packages' default_pack = os.path.join(packages, 'Default.sublime-package') prefs = 'Preferences.sublime-settings' with zipfile.ZipFile(default_pack) as zip_file: prefs = zip_file.read('Preferences.sublime-settings') prefs = prefs.decode('utf-8') prefs = prefs.replace("\r\n", "\n") p = re.compile(r'\s{0,4}//.*\n') prefs = p.sub('', prefs) return json.loads(prefs)
def _get_resource(package_name, resource, return_binary=False, encoding="utf-8"): packages_path = sublime.packages_path() content = None if VERSION > 3013: try: if return_binary: content = sublime.load_binary_resource("Packages/" + package_name + "/" + resource) else: content = sublime.load_resource("Packages/" + package_name + "/" + resource) except IOError: pass else: path = None if os.path.exists(os.path.join(packages_path, package_name, resource)): path = os.path.join(packages_path, package_name, resource) content = _get_directory_item_content(path, return_binary, encoding) if VERSION >= 3006: sublime_package = package_name + ".sublime-package" packages_path = sublime.installed_packages_path() if content is None: if os.path.exists(os.path.join(packages_path, sublime_package)): content = _get_zip_item_content(os.path.join(packages_path, sublime_package), resource, return_binary, encoding) packages_path = os.path.dirname(sublime.executable_path()) + os.sep + "Packages" if content is None: if os.path.exists(os.path.join(packages_path, sublime_package)): content = _get_zip_item_content(os.path.join(packages_path, sublime_package), resource, return_binary, encoding) return content
def list_package_files(package, ignore_patterns=[]): """ List files in the specified package. """ package_path = os.path.join(sublime.packages_path(), package, "") path = None file_set = set() file_list = [] if os.path.exists(package_path): for root, directories, filenames in os.walk(package_path): temp = root.replace(package_path, "") for filename in filenames: file_list.append(os.path.join(temp, filename)) file_set.update(file_list) if VERSION >= 3006: sublime_package = package + ".sublime-package" packages_path = sublime.installed_packages_path() if os.path.exists(os.path.join(packages_path, sublime_package)): file_set.update(_list_files_in_zip(packages_path, sublime_package)) packages_path = os.path.dirname(sublime.executable_path()) + os.sep + "Packages" if os.path.exists(os.path.join(packages_path, sublime_package)): file_set.update(_list_files_in_zip(packages_path, sublime_package)) file_list = [] for filename in file_set: if not _ignore_file(filename, ignore_patterns): file_list.append(_normalize_to_sublime_path(filename)) return sorted(file_list)
def get_package_and_resource_name(path): """ This method will return the package name and resource name from a path. Arguments: path Path to parse for package and resource name. """ package = None resource = None path = _normalize_to_sublime_path(path) if os.path.isabs(path): packages_path = _normalize_to_sublime_path(sublime.packages_path()) if path.startswith(packages_path): package, resource = _search_for_package_and_resource(path, packages_path) if int(sublime.version()) >= 3006: packages_path = _normalize_to_sublime_path(sublime.installed_packages_path()) if path.startswith(packages_path): package, resource = _search_for_package_and_resource(path, packages_path) packages_path = _normalize_to_sublime_path(os.path.dirname(sublime.executable_path()) + os.sep + "Packages") if path.startswith(packages_path): package, resource = _search_for_package_and_resource(path, packages_path) else: path = re.sub(r"^Packages/", "", path) split = re.split(r"/", path, 1) package = split[0] package = package.replace(".sublime-package", "") resource = split[1] return (package, resource)
def get_packages_list(ignore_packages=True, ignore_patterns=[]): """ Return a list of packages. """ package_set = set() package_set.update(_get_packages_from_directory(sublime.packages_path())) if int(sublime.version()) >= 3006: package_set.update(_get_packages_from_directory(sublime.installed_packages_path(), ".sublime-package")) executable_package_path = os.path.dirname(sublime.executable_path()) + os.sep + "Packages" package_set.update(_get_packages_from_directory(executable_package_path, ".sublime-package")) if ignore_packages: ignored_list = sublime.load_settings( "Preferences.sublime-settings").get("ignored_packages", []) else: ignored_list = [] for package in package_set: for pattern in ignore_patterns: if re.match(pattern, package): ignored_list.append(package) break for ignored in ignored_list: package_set.discard(ignored) return sorted(list(package_set))
def init(cls): exe_path = os.path.dirname(sublime.executable_path()) cls.shipped_packages_path = os.path.join(exe_path, "Packages")