python类installed_packages_path()的实例源码

config.py 文件源码 项目:CodeReader 作者: jasonrbr 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def init(fn=None, config={}):
        '''
        Will initialize the Config object with a given config, if
        given one. Otherwise it will default to just the default
        configuration file.
        Will try to load the defaultly named config file if it exists.
        Otherwise, it will merely have the default configurations.
        '''

        # load the file from memory or default

        Config.is_initialized = True

        if fn:
            Config.config_fn = os.path.join(sublime.installed_packages_path(),
                                            Config.package_dir, fn)
            # Config.config_fn = os.path.abspath(Config.config_fn)

        Config._load_config()

        # load param config file into our config
        for k in config:
            Config.config[k] = config[k]
        Config._save_config()
package_resources.py 文件源码 项目:ElectricImp-Sublime 作者: electricimp 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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)
editor_info.py 文件源码 项目:sublime-troubleshooting 作者: guillermooo 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def collect_package_data(self):
        block = DataBlock('Package data')

        _, packages, _ = next(os.walk(sublime.packages_path()))
        packages = list(packages)

        _, _, files = next(os.walk(sublime.installed_packages_path()))
        suffix = '.sublime-package'
        files = [f[:-len(suffix)] for f in files if f.endswith(suffix)]

        ignored_packages = sublime.load_settings('Preferences.sublime-settings').get('ignored_packages', [])

        block.items.append(DataItem('installed packages', json.dumps(files)))
        block.items.append(DataItem('packages', json.dumps(packages)))
        block.items.append(DataItem('ignored packages', json.dumps(ignored_packages)))
        if sublime.find_resources('Package Control.sublime-settings'):
            pc_packages = sublime.load_settings('Package Control.sublime-settings').get('installed_packages', [])
            block.items.append(DataItem('packages managed by Package Control', json.dumps(pc_packages)))

        self.elements.append(block)
packages.py 文件源码 项目:OverrideAudit 作者: OdatNurd 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __init__(self, name_list=None):
        self._list = dict()
        self._disabled = 0
        self._dependencies = 0

        # Maps lower cased package names to listed packages on case insensitive
        # systems.
        self._case_list = dict() if _wrap("ABC") == _wrap("abc") else None

        if name_list is not None:
            if isinstance(name_list, str):
                name_list = [name_list]

            if _wrap("Abc") == _wrap("abc"):
                name_list = [_wrap(name) for name in name_list]

        self._shipped = self.__find_pkgs(PackageInfo.shipped_packages_path, name_list, shipped=True)
        self._installed = self.__find_pkgs(sublime.installed_packages_path(), name_list)
        self._unpacked = self.__find_pkgs(sublime.packages_path(), name_list, packed=False)
helpers.py 文件源码 项目:sublime-atomizr 作者: idleberg 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
Localize.py 文件源码 项目:LocalizedMenu 作者: zam1024t 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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)
path.py 文件源码 项目:a-file-icon 作者: ihodev 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_package_archive():
    return os.path.join(sublime.installed_packages_path(),
                        settings.PACKAGE_ARCH)
package_resources.py 文件源码 项目:ElectricImp-Sublime 作者: electricimp 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
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
package_resources.py 文件源码 项目:ElectricImp-Sublime 作者: electricimp 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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)
package_resources.py 文件源码 项目:ElectricImp-Sublime 作者: electricimp 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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)
package_resources.py 文件源码 项目:ElectricImp-Sublime 作者: electricimp 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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))
packages.py 文件源码 项目:OverrideAudit 作者: OdatNurd 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __scan(self):
        if _wrap("Abc") == _wrap("abc"):
            self.verify_name = True

        pkg_filename = "%s.sublime-package" % self.name
        pkg_path = os.path.join(sublime.packages_path(), self.name)

        # Scan for the shipped package so we can collect the proper case on
        # case insensitive systems.
        self._add_package(_pkg_scan(self.shipped_packages_path, pkg_filename), True)
        self._add_package(_pkg_scan(sublime.installed_packages_path(), pkg_filename, True))
        self._add_path(pkg_path)
anaconda.py 文件源码 项目:sublimeTextConfig 作者: luoye-fe 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def monitor_plugins():
    """Monitor for any plugin that conflicts with anaconda
    """

    view = sublime.active_window().active_view()
    if not get_settings(view, 'auto_unload_conflictive_plugins', True):
        return

    plist = [
        'Jedi - Python autocompletion',  # breaks auto completion
        'SublimePythonIDE',  # interfere with autocompletion
        'SublimeCodeIntel'  # breaks everything, SCI is a mess
    ]
    hllist = [
        'MagicPython',  # breaks autocompletion on [dot]
        'Python 3'  # breeaks autocompletion on [dot]
    ]

    for plugin in plist:
        if plugin in sys.modules:
            [
                sublime_plugin.unload_module(m) for k, m in sys.modules.items()
                if plugin in k
            ]
            if plugin not in DISABLED_PLUGINS:
                DISABLED_PLUGINS.append(plugin)

    for highlighter in hllist:
        paths = os.listdir(sublime.packages_path()) + \
            os.listdir(sublime.installed_packages_path())

        for p in paths:
            if highlighter in p:
                fname = '{0}.sublime-settings'.format(highlighter)
                s = sublime.load_settings(fname)
                if all((s.has('auto_complete_triggers'), s.has('extensions'))):
                    break
                auto_complete = [
                    {
                        'characters': '.',
                        'selector': 'source.python - string - constant.numeric',  # noqa
                    }
                ]
                s.set('extensions', ['py'])
                s.set('auto_complete_triggers', auto_complete)
                sublime.save_settings(fname)
                break

    sublime.set_timeout_async(monitor_plugins, 500000)
packages.py 文件源码 项目:OverrideAudit 作者: OdatNurd 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def check_potential_override(filename, deep=False):
    """
    Given a filename path, check and see if this could conceivably be a
    reference to an override; i.e. that there is a shipped or installed
    package with the name given in the filename.

    When deep is False, this only checks that the file could potentially be
    an override. Set deep to True to actually look inside of the package
    itself to see if this really represents an override or not.

    The filename provided must be either absolute(and point to the Packages
    path) or relative (in which case it is assumed to point there).

    Returns None if not a potential override or a tuple of the package name
    and the override name (relative to the package).
    """
    if os.path.basename(filename) == "":
        return None

    if os.path.isabs(filename):
        if not filename.startswith(sublime.packages_path()):
            return None
        filename = os.path.relpath(filename, sublime.packages_path())

    # Get only the first path component, which will be a package name.
    parts = filename.split(os.path.sep)
    pkg_name = parts[0]
    pkg_file = pkg_name + ".sublime-package"

    shipped = os.path.join(PackageInfo.shipped_packages_path, pkg_file)
    installed = _pkg_scan(sublime.installed_packages_path(), pkg_file, True)

    if os.path.isfile(shipped) or installed is not None:
        # Always use Unix path separator even on windows; this is how the
        # sublime-package would represent the override path internally.
        override = "/".join(parts[1:])
        if not deep:
            return (pkg_name, override)

        try:
            with zipfile.ZipFile(installed or shipped) as zFile:
                info = find_zip_entry(zFile, override)
                return (pkg_name, info.filename)
        except:
            pass

    return None


###----------------------------------------------------------------------------


问题


面经


文章

微信
公众号

扫码关注公众号