Ejemplo n.º 1
0
    def plugin_loaded():
        # Make sure the user's locale can handle non-ASCII. A whole bunch of
        # work was done to try and make Package Control work even if the locale
        # was poorly set, by manually encoding all file paths, but it ended up
        # being a fool's errand since the package loading code built into
        # Sublime Text is not written to work that way, and although packages
        # could be installed, they could not be loaded properly.
        try:
            os.path.exists(os.path.join(sublime.packages_path(), u"fran\u00e7ais"))
        except (UnicodeEncodeError):
            message = text.format(
                u'''
                Package Control

                Your system's locale is set to a value that can not handle
                non-ASCII characters. Package Control can not properly work
                unless this is fixed.

                On Linux, please reference your distribution's docs for
                information on properly setting the LANG and LC_CTYPE
                environmental variables. As a temporary work-around, you can
                launch Sublime Text from the terminal with:

                LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 sublime_text
                '''
            )
            sublime.error_message(message)
            return

        # This handles fixing unicode issues with tempdirs on ST2 for Windows
        tempfile_unicode_patch()

        pc_settings = sublime.load_settings(pc_settings_filename())

        if not pc_settings.get('bootstrapped'):
            console_write(
                u'''
                Not running package cleanup since bootstrapping is not yet complete
                '''
            )
        else:
            # Start shortly after Sublime starts so package renames don't cause errors
            # with keybindings, settings, etc disappearing in the middle of parsing
            sublime.set_timeout(lambda: PackageCleanup().start(), 2000)
    def plugin_loaded():
        # Make sure the user's locale can handle non-ASCII. A whole bunch of
        # work was done to try and make Package Control work even if the locale
        # was poorly set, by manually encoding all file paths, but it ended up
        # being a fool's errand since the package loading code built into
        # Sublime Text is not written to work that way, and although packages
        # could be installed, they could not be loaded properly.
        try:
            os.path.exists(os.path.join(sublime.packages_path(), u"fran\u2013ais"))
        except (UnicodeEncodeError):
            message = text.format(
                u'''
                Package Control

                Your system's locale is set to a value that can not handle
                non-ASCII characters. Package Control can not properly work
                unless this is fixed.

                On Linux, please reference your distribution's docs for
                information on properly setting the LANG and LC_CTYPE
                environmental variables. As a temporary work-around, you can
                launch Sublime Text from the terminal with:

                LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 sublime_text
                '''
            )
            sublime.error_message(message)
            return

        # This handles fixing unicode issues with tempdirs on ST2 for Windows
        tempfile_unicode_patch()

        pc_settings = sublime.load_settings(pc_settings_filename())

        if not pc_settings.get('bootstrapped'):
            console_write(
                u'''
                Not running package cleanup since bootstrapping is not yet complete
                '''
            )
        else:
            # Start shortly after Sublime starts so package renames don't cause errors
            # with keybindings, settings, etc disappearing in the middle of parsing
            sublime.set_timeout(lambda: PackageCleanup().start(), 2000)
Ejemplo n.º 3
0
    def plugin_loaded():
        # Make sure the user's locale can handle non-ASCII. A whole bunch of
        # work was done to try and make PackagesManager work even if the locale
        # was poorly set, by manually encoding all file paths, but it ended up
        # being a fool's errand since the package loading code built into
        # Sublime Text is not written to work that way, and although packages
        # could be installed, they could not be loaded properly.
        try:
            os.path.exists(os.path.join(sublime.packages_path(), u"fran\u2013ais"))
        except (UnicodeEncodeError):
            message = text.format(
                u'''
                PackagesManager

                Your system's locale is set to a value that can not handle
                non-ASCII characters. PackagesManager can not properly work
                unless this is fixed.

                On Linux, please reference your distribution's docs for
                information on properly setting the LANG and LC_CTYPE
                environmental variables. As a temporary work-around, you can
                launch Sublime Text from the terminal with:

                LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 sublime_text
                '''
            )
            sublime.error_message(message)
            return

        # This handles fixing unicode issues with tempdirs on ST2 for Windows
        tempfile_unicode_patch()

        # Ensure we have a Cache dir we can use for temporary data
        if not os.path.exists(sys_path.pc_cache_dir()):
            os.makedirs(sys_path.pc_cache_dir(), exist_ok=True)

        # Clean up the old HTTP cache dir
        legacy_http_cache = os.path.join(sublime.packages_path(), u'User', u'Package Control.cache')
        http_cache = os.path.join(sys_path.pc_cache_dir(), 'http_cache')
        if os.path.exists(legacy_http_cache):
            if not os.path.exists(http_cache):
                console_write(
                    u'''
                    Moving HTTP cache data into "Cache/Package Control/http_cache/"
                    '''
                )
                shutil.move(legacy_http_cache, http_cache)
            else:
                console_write(
                    u'''
                    Removing old HTTP cache data"
                    '''
                )
                shutil.rmtree(legacy_http_cache)

        # Clean up old CA bundle paths
        legacy_ca_filenames = [
            'Package Control.system-ca-bundle',
            'Package Control.merged-ca-bundle',
            'oscrypto-ca-bundle.crt'
        ]
        for legacy_ca_filename in legacy_ca_filenames:
            legacy_ca_path = os.path.join(sublime.packages_path(), 'User', legacy_ca_filename)
            if os.path.exists(legacy_ca_path):
                os.unlink(legacy_ca_path)

        pc_settings = sublime.load_settings(pc_settings_filename())

        if not pc_settings.get('bootstrapped'):
            console_write(
                u'''
                Not running package cleanup since bootstrapping is not yet complete
                '''
            )
        else:
            # Start shortly after Sublime starts so package renames don't cause errors
            # with keybindings, settings, etc disappearing in the middle of parsing
            sublime.set_timeout(lambda: PackageCleanup().start(), 2000)
Ejemplo n.º 4
0
def plugin_loaded():
    manager = PackageManager()
    settings = manager.settings.copy()

    if not os.path.exists(loader.loader_package_path):
        base_loader_code = """
            import sys
            import os
            from os.path import dirname


            # This file adds the package_control subdirectory of Package Control
            # to first in the sys.path so that all other packages may rely on
            # PC for utility functions, such as event helpers, adding things to
            # sys.path, downloading files from the internet, etc


            if sys.version_info >= (3,):
                def decode(path):
                    return path

                def encode(path):
                    return path

                loader_dir = dirname(__file__)

            else:
                def decode(path):
                    if not isinstance(path, unicode):
                        path = path.decode(sys.getfilesystemencoding())
                    return path

                def encode(path):
                    if isinstance(path, unicode):
                        path = path.encode(sys.getfilesystemencoding())
                    return path

                loader_dir = decode(os.getcwd())


            st_dir = dirname(dirname(loader_dir))

            found = False
            if sys.version_info >= (3,):
                installed_packages_dir = os.path.join(st_dir, u'Installed Packages')
                pc_package_path = os.path.join(installed_packages_dir, u'Package Control.sublime-package')
                if os.path.exists(encode(pc_package_path)):
                    found = True

            if not found:
                packages_dir = os.path.join(st_dir, u'Packages')
                pc_package_path = os.path.join(packages_dir, u'Package Control')
                if os.path.exists(encode(pc_package_path)):
                    found = True

            if found:
                if os.name == 'nt':
                    from ctypes import windll, create_unicode_buffer
                    buf = create_unicode_buffer(512)
                    if windll.kernel32.GetShortPathNameW(pc_package_path, buf, len(buf)):
                        pc_package_path = buf.value

                sys.path.insert(0, encode(pc_package_path))
                import package_control
                # We remove the import path right away so as not to screw up
                # Sublime Text and its import machinery
                sys.path.remove(encode(pc_package_path))

            else:
                print(u'Package Control: Error finding main directory from loader')
        """
        base_loader_code = dedent(base_loader_code)
        loader.add('00', 'package_control', base_loader_code)

    pc_settings = sublime.load_settings(pc_settings_filename())

    # Make sure we are track Package Control itself
    installed_packages = load_list_setting(pc_settings, 'installed_packages')
    if 'Package Control' not in installed_packages:
        installed_packages.append('Package Control')
        save_list_setting(pc_settings, pc_settings_filename(), 'installed_packages', installed_packages)

    orig_installed_dependencies = load_list_setting(pc_settings, 'installed_dependencies')
    installed_dependencies = list(orig_installed_dependencies)

    # Record that the loader itself is installed
    if loader.loader_package_name not in installed_dependencies:
        installed_dependencies.append(loader.loader_package_name)

    # Queue up installation of bz2
    if 'bz2' not in installed_dependencies:
        installed_dependencies.append('bz2')

    # Queue up installation of select module for ST2/Windows
    if sublime.platform() == 'windows' and sys.version_info < (3,) and 'select-windows' not in installed_dependencies:
        installed_dependencies.append('select-windows')

    save_list_setting(pc_settings, pc_settings_filename(), 'installed_dependencies', installed_dependencies, orig_installed_dependencies)


    # SSL support fo Linux
    if sublime.platform() == 'linux':
        linux_ssl_url = u'http://packagecontrol.io/ssl-linux.sublime-package'
        linux_ssl_hash = u'66ee695385657ae5cbed7fdda0b7d6c32379ca3e8e26ec268a51bf2f29f9e90b'
        linux_ssl_priority = u'01'

        def linux_ssl_show_restart():
            sublime.message_dialog(u'Package Control\n\n'
                u'Package Control just installed the missing Python _ssl ' + \
                u'module for Linux since Sublime Text does not include it.\n\n' + \
                u'Please restart Sublime Text to make SSL available to all ' + \
                u'packages.')

        linux_ssl_args = (settings, linux_ssl_url,
            linux_ssl_hash, linux_ssl_priority, linux_ssl_show_restart)
        threading.Thread(target=bootstrap_dependency, args=linux_ssl_args).start()


    # SSL support for SHA-2 certificates with ST2 on Windows
    if sublime.platform() == 'windows' and sys.version_info < (3,):
        win_ssl_url = u'http://packagecontrol.io/ssl-windows.sublime-package'
        win_ssl_hash = u'3c28982eb400039cfffe53d38510556adead39ba7321f2d15a6770d3ebc75030'
        win_ssl_priority = u'01'

        def win_ssl_show_restart():
            sublime.message_dialog(u'Package Control\n\n'
                u'Package Control just upgraded the Python _ssl module for ' + \
                u'ST2 on Windows because the bundled one does not include ' + \
                u'support for modern SSL certificates.\n\n' + \
                u'Please restart Sublime Text to complete the upgrade.')

        win_ssl_args = (settings, win_ssl_url, win_ssl_hash,
            win_ssl_priority, win_ssl_show_restart)
        threading.Thread(target=bootstrap_dependency, args=win_ssl_args).start()
Ejemplo n.º 5
0
def plugin_loaded():
    manager = PackageManager()
    settings = manager.settings.copy()

    if not os.path.exists(loader.loader_package_path):
        base_loader_code = """
            import sys
            import os
            from os.path import dirname


            # This file adds the package_control subdirectory of Package Control
            # to first in the sys.path so that all other packages may rely on
            # PC for utility functions, such as event helpers, adding things to
            # sys.path, downloading files from the internet, etc


            if sys.version_info >= (3,):
                def decode(path):
                    return path

                def encode(path):
                    return path

                loader_dir = dirname(__file__)

            else:
                def decode(path):
                    if not isinstance(path, unicode):
                        path = path.decode(sys.getfilesystemencoding())
                    return path

                def encode(path):
                    if isinstance(path, unicode):
                        path = path.encode(sys.getfilesystemencoding())
                    return path

                loader_dir = decode(os.getcwd())


            st_dir = dirname(dirname(loader_dir))

            found = False
            if sys.version_info >= (3,):
                installed_packages_dir = os.path.join(st_dir, u'Installed Packages')
                pc_package_path = os.path.join(installed_packages_dir, u'Package Control.sublime-package')
                if os.path.exists(encode(pc_package_path)):
                    found = True

            if not found:
                packages_dir = os.path.join(st_dir, u'Packages')
                pc_package_path = os.path.join(packages_dir, u'Package Control')
                if os.path.exists(encode(pc_package_path)):
                    found = True

            if found:
                if os.name == 'nt':
                    from ctypes import windll, create_unicode_buffer
                    buf = create_unicode_buffer(512)
                    if windll.kernel32.GetShortPathNameW(pc_package_path, buf, len(buf)):
                        pc_package_path = buf.value

                sys.path.insert(0, encode(pc_package_path))
                import package_control
                # We remove the import path right away so as not to screw up
                # Sublime Text and its import machinery
                sys.path.remove(encode(pc_package_path))

            else:
                print(u'Package Control: Error finding main directory from loader')
        """
        base_loader_code = dedent(base_loader_code)
        loader.add('00', 'package_control', base_loader_code)

    pc_settings = sublime.load_settings(pc_settings_filename())

    # Make sure we are track Package Control itself
    installed_packages = load_list_setting(pc_settings, 'installed_packages')
    if 'Package Control' not in installed_packages:
        installed_packages.append('Package Control')
        save_list_setting(pc_settings, pc_settings_filename(), 'installed_packages', installed_packages)

    # We no longer use the installed_dependencies setting because it is not
    # necessary and created issues with settings shared across operating systems
    if pc_settings.get('installed_dependencies'):
        pc_settings.erase('installed_dependencies')
        sublime.save_settings(pc_settings_filename())

    # SSL support fo Linux
    if sublime.platform() == 'linux':
        linux_ssl_url = u'http://packagecontrol.io/ssl/1.0.1/ssl-linux.sublime-package'
        linux_ssl_hash = u'862d061cbe666777cd1e9cd1cbc7c82f48ad8897dbb68332975f3edf5ce0f38d'
        linux_ssl_priority = u'01'
        linux_ssl_version = '1.0.1'

        def linux_ssl_show_restart():
            sublime.message_dialog(u'Package Control\n\n'
                u'Package Control just installed or upgraded the missing ' + \
                u'Python _ssl module for Linux since Sublime Text does not ' + \
                u'include it.\n\n' + \
                u'Please restart Sublime Text to make SSL available to all ' + \
                u'packages.')

        linux_ssl_args = (settings, linux_ssl_url,
            linux_ssl_hash, linux_ssl_priority, linux_ssl_version, linux_ssl_show_restart)
        threading.Thread(target=bootstrap_dependency, args=linux_ssl_args).start()


    # SSL support for SHA-2 certificates with ST2 on Windows
    if sublime.platform() == 'windows' and sys.version_info < (3,):
        win_ssl_url = u'http://packagecontrol.io/ssl/1.0.0/ssl-windows.sublime-package'
        win_ssl_hash = u'3c28982eb400039cfffe53d38510556adead39ba7321f2d15a6770d3ebc75030'
        win_ssl_priority = u'01'
        win_ssl_version = u'1.0.0'

        def win_ssl_show_restart():
            sublime.message_dialog(u'Package Control\n\n'
                u'Package Control just upgraded the Python _ssl module for ' + \
                u'ST2 on Windows because the bundled one does not include ' + \
                u'support for modern SSL certificates.\n\n' + \
                u'Please restart Sublime Text to complete the upgrade.')

        win_ssl_args = (settings, win_ssl_url, win_ssl_hash,
            win_ssl_priority, win_ssl_version, win_ssl_show_restart)
        threading.Thread(target=bootstrap_dependency, args=win_ssl_args).start()
Ejemplo n.º 6
0
def plugin_loaded():
    manager = PackageManager()
    settings = manager.settings.copy()

    if not loader.exists('package_control'):
        base_loader_code = """
            import sys
            import os
            from os.path import dirname


            # This file adds the package_control subdirectory of Package Control
            # to first in the sys.path so that all other packages may rely on
            # PC for utility functions, such as event helpers, adding things to
            # sys.path, downloading files from the internet, etc


            if sys.version_info >= (3,):
                def decode(path):
                    return path

                def encode(path):
                    return path

                loader_dir = dirname(__file__)

            else:
                def decode(path):
                    if not isinstance(path, unicode):
                        path = path.decode(sys.getfilesystemencoding())
                    return path

                def encode(path):
                    if isinstance(path, unicode):
                        path = path.encode(sys.getfilesystemencoding())
                    return path

                loader_dir = decode(os.getcwd())


            st_dir = dirname(dirname(loader_dir))

            found = False
            if sys.version_info >= (3,):
                installed_packages_dir = os.path.join(st_dir, u'Installed Packages')
                pc_package_path = os.path.join(installed_packages_dir, u'Package Control.sublime-package')
                if os.path.exists(encode(pc_package_path)):
                    found = True

            if not found:
                packages_dir = os.path.join(st_dir, u'Packages')
                pc_package_path = os.path.join(packages_dir, u'Package Control')
                if os.path.exists(encode(pc_package_path)):
                    found = True

            if found:
                if os.name == 'nt':
                    from ctypes import windll, create_unicode_buffer
                    buf = create_unicode_buffer(512)
                    if windll.kernel32.GetShortPathNameW(pc_package_path, buf, len(buf)):
                        pc_package_path = buf.value

                sys.path.insert(0, encode(pc_package_path))
                import package_control
                # We remove the import path right away so as not to screw up
                # Sublime Text and its import machinery
                sys.path.remove(encode(pc_package_path))

            else:
                print(u'Package Control: Error finding main directory from loader')
        """
        base_loader_code = dedent(base_loader_code).lstrip()
        loader.add('00', 'package_control', base_loader_code)

    # SSL support fo Linux
    if sublime.platform() == 'linux':
        linux_ssl_url = u'http://packagecontrol.io/ssl/1.0.1/ssl-linux.sublime-package'
        linux_ssl_hash = u'862d061cbe666777cd1e9cd1cbc7c82f48ad8897dbb68332975f3edf5ce0f38d'
        linux_ssl_priority = u'01'
        linux_ssl_version = '1.0.1'

        def linux_ssl_show_restart():
            sublime.message_dialog(text.format(
                u'''
                Package Control

                Package Control just installed or upgraded the missing Python
                _ssl module for Linux since Sublime Text does not include it.

                Please restart Sublime Text to make SSL available to all
                packages.
                '''
            ))

        linux_ssl_args = (settings, linux_ssl_url, linux_ssl_hash,
            linux_ssl_priority, linux_ssl_version, linux_ssl_show_restart)
        threading.Thread(target=bootstrap_dependency, args=linux_ssl_args).start()

    # SSL support for SHA-2 certificates with ST2 on Windows
    if sublime.platform() == 'windows' and sys.version_info < (3,):
        win_ssl_url = u'http://packagecontrol.io/ssl/1.0.0/ssl-windows.sublime-package'
        win_ssl_hash = u'3c28982eb400039cfffe53d38510556adead39ba7321f2d15a6770d3ebc75030'
        win_ssl_priority = u'01'
        win_ssl_version = u'1.0.0'

        def win_ssl_show_restart():
            sublime.message_dialog(text.format(
                u'''
                Package Control

                Package Control just upgraded the Python _ssl module for ST2 on
                Windows because the bundled one does not include support for
                modern SSL certificates.

                Please restart Sublime Text to complete the upgrade.
                '''
            ))

        win_ssl_args = (settings, win_ssl_url, win_ssl_hash, win_ssl_priority,
            win_ssl_version, win_ssl_show_restart)
        threading.Thread(target=bootstrap_dependency, args=win_ssl_args).start()

    pc_settings = sublime.load_settings(pc_settings_filename())

    # Make sure we are track Package Control itself
    installed_packages = load_list_setting(pc_settings, 'installed_packages')
    if 'Package Control' not in installed_packages:
        params = {
            'package': 'Package Control',
            'operation': 'install',
            'version': package_control.__version__
        }
        manager.record_usage(params)
        installed_packages.append('Package Control')
        save_list_setting(pc_settings, pc_settings_filename(), 'installed_packages', installed_packages)

    # We no longer use the installed_dependencies setting because it is not
    # necessary and created issues with settings shared across operating systems
    if pc_settings.get('installed_dependencies'):
        pc_settings.erase('installed_dependencies')
        sublime.save_settings(pc_settings_filename())