feat(ST2.UtilPackages): bump up all packages

- Refresh PackageCache with latest versions of everything
This commit is contained in:
Iristyle
2013-09-16 22:35:46 -04:00
parent 7195197f0f
commit a000ce8acc
451 changed files with 14151 additions and 8317 deletions

View File

@@ -0,0 +1,39 @@
import os
from .add_channel_command import AddChannelCommand
from .add_repository_command import AddRepositoryCommand
from .create_binary_package_command import CreateBinaryPackageCommand
from .create_package_command import CreatePackageCommand
from .disable_package_command import DisablePackageCommand
from .discover_packages_command import DiscoverPackagesCommand
from .enable_package_command import EnablePackageCommand
from .grab_certs_command import GrabCertsCommand
from .install_package_command import InstallPackageCommand
from .list_packages_command import ListPackagesCommand
from .remove_package_command import RemovePackageCommand
from .upgrade_all_packages_command import UpgradeAllPackagesCommand
from .upgrade_package_command import UpgradePackageCommand
from .package_message_command import PackageMessageCommand
__all__ = [
'AddChannelCommand',
'AddRepositoryCommand',
'CreateBinaryPackageCommand',
'CreatePackageCommand',
'DisablePackageCommand',
'DiscoverPackagesCommand',
'EnablePackageCommand',
'InstallPackageCommand',
'ListPackagesCommand',
'RemovePackageCommand',
'UpgradeAllPackagesCommand',
'UpgradePackageCommand',
'PackageMessageCommand'
]
# Windows uses the wininet downloader, so it doesn't use the CA cert bundle
# and thus does not need the ability to grab to CA certs. Additionally,
# there is no openssl.exe on Windows.
if os.name != 'nt':
__all__.append('GrabCertsCommand')

View File

@@ -0,0 +1,46 @@
import re
import sublime
import sublime_plugin
from ..show_error import show_error
class AddChannelCommand(sublime_plugin.WindowCommand):
"""
A command to add a new channel (list of repositories) to the user's machine
"""
def run(self):
self.window.show_input_panel('Channel JSON URL', '',
self.on_done, self.on_change, self.on_cancel)
def on_done(self, input):
"""
Input panel handler - adds the provided URL as a channel
:param input:
A string of the URL to the new channel
"""
input = input.strip()
if re.match('https?://', input, re.I) == None:
show_error(u"Unable to add the channel \"%s\" since it does not appear to be served via HTTP (http:// or https://)." % input)
return
settings = sublime.load_settings('Package Control.sublime-settings')
channels = settings.get('channels', [])
if not channels:
channels = []
channels.append(input)
settings.set('channels', channels)
sublime.save_settings('Package Control.sublime-settings')
sublime.status_message(('Channel %s successfully ' +
'added') % input)
def on_change(self, input):
pass
def on_cancel(self):
pass

View File

@@ -0,0 +1,46 @@
import re
import sublime
import sublime_plugin
from ..show_error import show_error
class AddRepositoryCommand(sublime_plugin.WindowCommand):
"""
A command to add a new repository to the user's machine
"""
def run(self):
self.window.show_input_panel('GitHub or BitBucket Web URL, or Custom' +
' JSON Repository URL', '', self.on_done,
self.on_change, self.on_cancel)
def on_done(self, input):
"""
Input panel handler - adds the provided URL as a repository
:param input:
A string of the URL to the new repository
"""
input = input.strip()
if re.match('https?://', input, re.I) == None:
show_error(u"Unable to add the repository \"%s\" since it does not appear to be served via HTTP (http:// or https://)." % input)
return
settings = sublime.load_settings('Package Control.sublime-settings')
repositories = settings.get('repositories', [])
if not repositories:
repositories = []
repositories.append(input)
settings.set('repositories', repositories)
sublime.save_settings('Package Control.sublime-settings')
sublime.status_message('Repository %s successfully added' % input)
def on_change(self, input):
pass
def on_cancel(self):
pass

View File

@@ -0,0 +1,35 @@
import sublime_plugin
from ..package_creator import PackageCreator
class CreateBinaryPackageCommand(sublime_plugin.WindowCommand, PackageCreator):
"""
Command to create a binary .sublime-package file. Binary packages in
general exclude the .py source files and instead include the .pyc files.
Actual included and excluded files are controlled by settings.
"""
def run(self):
self.show_panel()
def on_done(self, picked):
"""
Quick panel user selection handler - processes the user package
selection and create the package file
:param picked:
An integer of the 0-based package name index from the presented
list. -1 means the user cancelled.
"""
if picked == -1:
return
package_name = self.packages[picked]
package_destination = self.get_package_destination()
if self.manager.create_package(package_name, package_destination,
binary_package=True):
self.window.run_command('open_dir', {"dir":
package_destination, "file": package_name +
'.sublime-package'})

View File

@@ -0,0 +1,32 @@
import sublime_plugin
from ..package_creator import PackageCreator
class CreatePackageCommand(sublime_plugin.WindowCommand, PackageCreator):
"""
Command to create a regular .sublime-package file
"""
def run(self):
self.show_panel()
def on_done(self, picked):
"""
Quick panel user selection handler - processes the user package
selection and create the package file
:param picked:
An integer of the 0-based package name index from the presented
list. -1 means the user cancelled.
"""
if picked == -1:
return
package_name = self.packages[picked]
package_destination = self.get_package_destination()
if self.manager.create_package(package_name, package_destination):
self.window.run_command('open_dir', {"dir":
package_destination, "file": package_name +
'.sublime-package'})

View File

@@ -0,0 +1,48 @@
import sublime
import sublime_plugin
from ..show_error import show_error
from ..package_manager import PackageManager
from ..preferences_filename import preferences_filename
class DisablePackageCommand(sublime_plugin.WindowCommand):
"""
A command that adds a package to Sublime Text's ignored packages list
"""
def run(self):
manager = PackageManager()
packages = manager.list_all_packages()
self.settings = sublime.load_settings(preferences_filename())
ignored = self.settings.get('ignored_packages')
if not ignored:
ignored = []
self.package_list = list(set(packages) - set(ignored))
self.package_list.sort()
if not self.package_list:
show_error('There are no enabled packages to disable.')
return
self.window.show_quick_panel(self.package_list, self.on_done)
def on_done(self, picked):
"""
Quick panel user selection handler - disables the selected package
:param picked:
An integer of the 0-based package name index from the presented
list. -1 means the user cancelled.
"""
if picked == -1:
return
package = self.package_list[picked]
ignored = self.settings.get('ignored_packages')
if not ignored:
ignored = []
ignored.append(package)
self.settings.set('ignored_packages', ignored)
sublime.save_settings(preferences_filename())
sublime.status_message(('Package %s successfully added to list of ' +
'disabled packages - restarting Sublime Text may be required') %
package)

View File

@@ -0,0 +1,11 @@
import sublime_plugin
class DiscoverPackagesCommand(sublime_plugin.WindowCommand):
"""
A command that opens the community package list webpage
"""
def run(self):
self.window.run_command('open_url',
{'url': 'http://wbond.net/sublime_packages/community'})

View File

@@ -0,0 +1,40 @@
import sublime
import sublime_plugin
from ..show_error import show_error
from ..preferences_filename import preferences_filename
class EnablePackageCommand(sublime_plugin.WindowCommand):
"""
A command that removes a package from Sublime Text's ignored packages list
"""
def run(self):
self.settings = sublime.load_settings(preferences_filename())
self.disabled_packages = self.settings.get('ignored_packages')
self.disabled_packages.sort()
if not self.disabled_packages:
show_error('There are no disabled packages to enable.')
return
self.window.show_quick_panel(self.disabled_packages, self.on_done)
def on_done(self, picked):
"""
Quick panel user selection handler - enables the selected package
:param picked:
An integer of the 0-based package name index from the presented
list. -1 means the user cancelled.
"""
if picked == -1:
return
package = self.disabled_packages[picked]
ignored = self.settings.get('ignored_packages')
self.settings.set('ignored_packages',
list(set(ignored) - set([package])))
sublime.save_settings(preferences_filename())
sublime.status_message(('Package %s successfully removed from list ' +
'of disabled packages - restarting Sublime Text may be required') %
package)

View File

@@ -0,0 +1,69 @@
import os
import re
import sublime
from ..package_manager import PackageManager
class ExistingPackagesCommand():
"""
Allows listing installed packages and their current version
"""
def __init__(self):
self.manager = PackageManager()
def make_package_list(self, action=''):
"""
Returns a list of installed packages suitable for displaying in the
quick panel.
:param action:
An action to display at the beginning of the third element of the
list returned for each package
:return:
A list of lists, each containing three strings:
0 - package name
1 - package description
2 - [action] installed version; package url
"""
packages = self.manager.list_packages()
if action:
action += ' '
package_list = []
for package in sorted(packages, key=lambda s: s.lower()):
package_entry = [package]
metadata = self.manager.get_metadata(package)
package_dir = os.path.join(sublime.packages_path(), package)
description = metadata.get('description')
if not description:
description = 'No description provided'
package_entry.append(description)
version = metadata.get('version')
if not version and os.path.exists(os.path.join(package_dir,
'.git')):
installed_version = 'git repository'
elif not version and os.path.exists(os.path.join(package_dir,
'.hg')):
installed_version = 'hg repository'
else:
installed_version = 'v' + version if version else \
'unknown version'
url = metadata.get('url')
if url:
url = '; ' + re.sub('^https?://', '', url)
else:
url = ''
package_entry.append(action + installed_version + url)
package_list.append(package_entry)
return package_list

View File

@@ -0,0 +1,109 @@
import os
import re
import socket
import threading
try:
# Python 3
from urllib.parse import urlparse
except (ImportError):
# Python 2
from urlparse import urlparse
import sublime
import sublime_plugin
from ..show_error import show_error
from ..open_compat import open_compat
from ..ca_certs import find_root_ca_cert
from ..thread_progress import ThreadProgress
from ..package_manager import PackageManager
class GrabCertsCommand(sublime_plugin.WindowCommand):
"""
A command that extracts the CA certs for a domain name, allowing a user to
fetch packages from sources other than those used by the default channel
"""
def run(self):
panel = self.window.show_input_panel('Domain Name', 'example.com', self.on_done,
None, None)
panel.sel().add(sublime.Region(0, panel.size()))
def on_done(self, domain):
"""
Input panel handler - grabs the CA certs for the domain name presented
:param domain:
A string of the domain name
"""
domain = domain.strip()
# Make sure the user enters something
if domain == '':
show_error(u"Please enter a domain name, or press cancel")
self.run()
return
# If the user inputs a URL, extract the domain name
if domain.find('/') != -1:
parts = urlparse(domain)
if parts.hostname:
domain = parts.hostname
# Allow _ even though it technically isn't valid, this is really
# just to try and prevent people from typing in gibberish
if re.match('^(?:[a-zA-Z0-9]+(?:[\-_]*[a-zA-Z0-9]+)*\.)+[a-zA-Z]{2,6}$', domain, re.I) == None:
show_error(u"Unable to get the CA certs for \"%s\" since it does not appear to be a validly formed domain name" % domain)
return
# Make sure it is a real domain
try:
socket.gethostbyname(domain)
except (socket.gaierror) as e:
error = unicode_from_os(e)
show_error(u"Error trying to lookup \"%s\":\n\n%s" % (domain, error))
return
manager = PackageManager()
thread = GrabCertsThread(manager.settings, domain)
thread.start()
ThreadProgress(thread, 'Grabbing CA certs for %s' % domain,
'CA certs for %s added to settings' % domain)
class GrabCertsThread(threading.Thread):
"""
A thread to run openssl so that the Sublime Text UI does not become frozen
"""
def __init__(self, settings, domain):
self.settings = settings
self.domain = domain
threading.Thread.__init__(self)
def run(self):
cert, cert_hash = find_root_ca_cert(self.settings, self.domain)
certs_dir = os.path.join(sublime.packages_path(), 'User',
'Package Control.ca-certs')
if not os.path.exists(certs_dir):
os.mkdir(certs_dir)
cert_path = os.path.join(certs_dir, self.domain + '-ca.crt')
with open_compat(cert_path, 'w') as f:
f.write(cert)
def save_certs():
settings = sublime.load_settings('Package Control.sublime-settings')
certs = settings.get('certs', {})
if not certs:
certs = {}
certs[self.domain] = [cert_hash, cert_path]
settings.set('certs', certs)
sublime.save_settings('Package Control.sublime-settings')
sublime.set_timeout(save_certs, 10)

View File

@@ -0,0 +1,50 @@
import threading
import sublime
import sublime_plugin
from ..show_error import show_error
from ..package_installer import PackageInstaller
from ..thread_progress import ThreadProgress
class InstallPackageCommand(sublime_plugin.WindowCommand):
"""
A command that presents the list of available packages and allows the
user to pick one to install.
"""
def run(self):
thread = InstallPackageThread(self.window)
thread.start()
ThreadProgress(thread, 'Loading repositories', '')
class InstallPackageThread(threading.Thread, PackageInstaller):
"""
A thread to run the action of retrieving available packages in. Uses the
default PackageInstaller.on_done quick panel handler.
"""
def __init__(self, window):
"""
:param window:
An instance of :class:`sublime.Window` that represents the Sublime
Text window to show the available package list in.
"""
self.window = window
self.completion_type = 'installed'
threading.Thread.__init__(self)
PackageInstaller.__init__(self)
def run(self):
self.package_list = self.make_package_list(['upgrade', 'downgrade',
'reinstall', 'pull', 'none'])
def show_quick_panel():
if not self.package_list:
show_error('There are no packages available for installation')
return
self.window.show_quick_panel(self.package_list, self.on_done)
sublime.set_timeout(show_quick_panel, 10)

View File

@@ -0,0 +1,63 @@
import threading
import os
import sublime
import sublime_plugin
from ..show_error import show_error
from .existing_packages_command import ExistingPackagesCommand
class ListPackagesCommand(sublime_plugin.WindowCommand):
"""
A command that shows a list of all installed packages in the quick panel
"""
def run(self):
ListPackagesThread(self.window).start()
class ListPackagesThread(threading.Thread, ExistingPackagesCommand):
"""
A thread to prevent the listing of existing packages from freezing the UI
"""
def __init__(self, window):
"""
:param window:
An instance of :class:`sublime.Window` that represents the Sublime
Text window to show the list of installed packages in.
"""
self.window = window
threading.Thread.__init__(self)
ExistingPackagesCommand.__init__(self)
def run(self):
self.package_list = self.make_package_list()
def show_quick_panel():
if not self.package_list:
show_error('There are no packages to list')
return
self.window.show_quick_panel(self.package_list, self.on_done)
sublime.set_timeout(show_quick_panel, 10)
def on_done(self, picked):
"""
Quick panel user selection handler - opens the homepage for any
selected package in the user's browser
:param picked:
An integer of the 0-based package name index from the presented
list. -1 means the user cancelled.
"""
if picked == -1:
return
package_name = self.package_list[picked][0]
def open_dir():
self.window.run_command('open_dir',
{"dir": os.path.join(sublime.packages_path(), package_name)})
sublime.set_timeout(open_dir, 10)

View File

@@ -0,0 +1,11 @@
import sublime
import sublime_plugin
class PackageMessageCommand(sublime_plugin.TextCommand):
"""
A command to write a package message to the Package Control messaging buffer
"""
def run(self, edit, string=''):
self.view.insert(edit, self.view.size(), string)

View File

@@ -0,0 +1,88 @@
import threading
import sublime
import sublime_plugin
from ..show_error import show_error
from .existing_packages_command import ExistingPackagesCommand
from ..preferences_filename import preferences_filename
from ..thread_progress import ThreadProgress
class RemovePackageCommand(sublime_plugin.WindowCommand,
ExistingPackagesCommand):
"""
A command that presents a list of installed packages, allowing the user to
select one to remove
"""
def __init__(self, window):
"""
:param window:
An instance of :class:`sublime.Window` that represents the Sublime
Text window to show the list of installed packages in.
"""
self.window = window
ExistingPackagesCommand.__init__(self)
def run(self):
self.package_list = self.make_package_list('remove')
if not self.package_list:
show_error('There are no packages that can be removed.')
return
self.window.show_quick_panel(self.package_list, self.on_done)
def on_done(self, picked):
"""
Quick panel user selection handler - deletes the selected package
:param picked:
An integer of the 0-based package name index from the presented
list. -1 means the user cancelled.
"""
if picked == -1:
return
package = self.package_list[picked][0]
settings = sublime.load_settings(preferences_filename())
ignored = settings.get('ignored_packages')
if not ignored:
ignored = []
# Don't disable Package Control so it does not get stuck disabled
if package != 'Package Control':
if not package in ignored:
ignored.append(package)
settings.set('ignored_packages', ignored)
sublime.save_settings(preferences_filename())
ignored.remove(package)
thread = RemovePackageThread(self.manager, package,
ignored)
thread.start()
ThreadProgress(thread, 'Removing package %s' % package,
'Package %s successfully removed' % package)
class RemovePackageThread(threading.Thread):
"""
A thread to run the remove package operation in so that the Sublime Text
UI does not become frozen
"""
def __init__(self, manager, package, ignored):
self.manager = manager
self.package = package
self.ignored = ignored
threading.Thread.__init__(self)
def run(self):
self.result = self.manager.remove_package(self.package)
def unignore_package():
settings = sublime.load_settings(preferences_filename())
settings.set('ignored_packages', self.ignored)
sublime.save_settings(preferences_filename())
sublime.set_timeout(unignore_package, 10)

View File

@@ -0,0 +1,77 @@
import time
import threading
import sublime
import sublime_plugin
from ..thread_progress import ThreadProgress
from ..package_installer import PackageInstaller, PackageInstallerThread
from ..package_renamer import PackageRenamer
class UpgradeAllPackagesCommand(sublime_plugin.WindowCommand):
"""
A command to automatically upgrade all installed packages that are
upgradable.
"""
def run(self):
package_renamer = PackageRenamer()
package_renamer.load_settings()
thread = UpgradeAllPackagesThread(self.window, package_renamer)
thread.start()
ThreadProgress(thread, 'Loading repositories', '')
class UpgradeAllPackagesThread(threading.Thread, PackageInstaller):
"""
A thread to run the action of retrieving upgradable packages in.
"""
def __init__(self, window, package_renamer):
self.window = window
self.package_renamer = package_renamer
self.completion_type = 'upgraded'
threading.Thread.__init__(self)
PackageInstaller.__init__(self)
def run(self):
self.package_renamer.rename_packages(self)
package_list = self.make_package_list(['install', 'reinstall', 'none'])
disabled_packages = []
def do_upgrades():
# Pause so packages can be disabled
time.sleep(0.5)
# We use a function to generate the on-complete lambda because if
# we don't, the lambda will bind to info at the current scope, and
# thus use the last value of info from the loop
def make_on_complete(name):
return lambda: self.reenable_package(name)
for info in package_list:
if info[0] in disabled_packages:
on_complete = make_on_complete(info[0])
else:
on_complete = None
thread = PackageInstallerThread(self.manager, info[0],
on_complete)
thread.start()
ThreadProgress(thread, 'Upgrading package %s' % info[0],
'Package %s successfully %s' % (info[0],
self.completion_type))
# Disabling a package means changing settings, which can only be done
# in the main thread. We then create a new background thread so that
# the upgrade process does not block the UI.
def disable_packages():
package_names = []
for info in package_list:
package_names.append(info[0])
disabled_packages.extend(self.disable_packages(package_names))
threading.Thread(target=do_upgrades).start()
sublime.set_timeout(disable_packages, 1)

View File

@@ -0,0 +1,81 @@
import threading
import sublime
import sublime_plugin
from ..show_error import show_error
from ..thread_progress import ThreadProgress
from ..package_installer import PackageInstaller, PackageInstallerThread
from ..package_renamer import PackageRenamer
class UpgradePackageCommand(sublime_plugin.WindowCommand):
"""
A command that presents the list of installed packages that can be upgraded
"""
def run(self):
package_renamer = PackageRenamer()
package_renamer.load_settings()
thread = UpgradePackageThread(self.window, package_renamer)
thread.start()
ThreadProgress(thread, 'Loading repositories', '')
class UpgradePackageThread(threading.Thread, PackageInstaller):
"""
A thread to run the action of retrieving upgradable packages in.
"""
def __init__(self, window, package_renamer):
"""
:param window:
An instance of :class:`sublime.Window` that represents the Sublime
Text window to show the list of upgradable packages in.
:param package_renamer:
An instance of :class:`PackageRenamer`
"""
self.window = window
self.package_renamer = package_renamer
self.completion_type = 'upgraded'
threading.Thread.__init__(self)
PackageInstaller.__init__(self)
def run(self):
self.package_renamer.rename_packages(self)
self.package_list = self.make_package_list(['install', 'reinstall',
'none'])
def show_quick_panel():
if not self.package_list:
show_error('There are no packages ready for upgrade')
return
self.window.show_quick_panel(self.package_list, self.on_done)
sublime.set_timeout(show_quick_panel, 10)
def on_done(self, picked):
"""
Quick panel user selection handler - disables a package, upgrades it,
then re-enables the package
:param picked:
An integer of the 0-based package name index from the presented
list. -1 means the user cancelled.
"""
if picked == -1:
return
name = self.package_list[picked][0]
if name in self.disable_packages(name):
on_complete = lambda: self.reenable_package(name)
else:
on_complete = None
thread = PackageInstallerThread(self.manager, name, on_complete)
thread.start()
ThreadProgress(thread, 'Upgrading package %s' % name,
'Package %s successfully %s' % (name, self.completion_type))