PKW4=v packagedownloaderplugin.pyimport sublime, sublimeplugin, packagedownloader, threading, zipfile, sys, os, shutil from functools import partial # class DownloadPackagesOnSublimeTextWikiCommand(sublimeplugin.ApplicationCommand): # name = "Package Downloader" # # def getPackages(self): # packageList = packagedownloader.downloadPackages() # # # Interrupt main thread to notify # sublime.setTimeout(partial(self.notify, packageList), 1) # # def notify(self, packageList): # if len(packageList) == 0: # msg = "No Packages Downloaded" # # else: # msg = ("Downloaded these packages;%sPackages will be installed next time " # "you start Sublime Text." % ("\n\n%s\n\n" % "\n".join(packageList))) # # sublime.messageBox(msg) # # def run(self, args): # sublime.statusMessage("Downloading Packages") # threading.Thread(target=self.getPackages).start() class BrowsePackagesOnSublimeTextWikiCommand(sublimeplugin.WindowCommand): def getPackages(self): packageList = packagedownloader.listPackages() # Interrupt main thread to notify sublime.setTimeout(partial(self.notify, packageList), 1) def notify(self, packageNames): self.window.showQuickPanel("", "packageSelectedForInstallation", packageNames, packageNames, sublime.QUICK_PANEL_MULTI_SELECT) def run(self, window, args): self.window = window sublime.statusMessage("Downloading Packages") threading.Thread(target=self.getPackages).start() class PackageSelectedForInstallationCommand(sublimeplugin.TextCommand): def run(self, view, args): if len(args) == 0: sublime.messageBox("You didn't select anything.") else: name = args[0] url = packagedownloader.packageRoot() + name + ".sublime-package" answer = sublime.questionBox("Download '%s'?" % url) if answer: localPackageRoot = packagedownloader.packageDir() if localPackageRoot == None: sublime.messageBox("Could not find package folder. Sorry.") return destination = "c:/downloaded-by-sublime-text-package-downloader.sublime-package" packagedownloader.downloadSinglePackage(url, destination) packageFolder = os.path.join(localPackageRoot, name) existsAlready = "" if os.path.exists(packageFolder): existsAlready = " This folder already exists and will be replaced." unpackAnswer = sublime.questionBox("Download succeeded. Do you wish to install in '%s'?%s " % (packageFolder, existsAlready)) if not unpackAnswer: os.remove(destination) return self.expandPackage(destination, packageFolder) os.remove(destination) sublime.messageBox("Unpacked to %s" % packageFolder) def expandPackage(self, zipPath, destinationFolder): if os.path.exists(destinationFolder): # must delete existing path. shutil.rmtree(destinationFolder) os.mkdir(destinationFolder) zfobj = zipfile.ZipFile(zipPath) for name in zfobj.namelist(): if name.endswith('/'): d = os.path.join(destinationFolder, name) os.mkdir(d) else: file = os.path.join(destinationFolder, name) outfile = open(file, 'wb') outfile.write(zfobj.read(name)) outfile.close() PKW4=μA  packagedownloader.py# # package downloader # import sys, os, urllib, _winreg class FakeFile: content = "" def write(self, block): self.content += block def getUrl(url): fl = FakeFile() downloadUrl(url, fl) return fl.content def downloadUrl(url, writer): package = urllib.urlopen(url) for block in readIter(package): writer.write(block) package.close() def readIter(f, blocksize=8192): """Given a file 'f', returns an iterator that returns bytes of size 'blocksize' from the file, using read().""" while True: data = f.read(blocksize) if not data: break yield data def progFilesDir(): progFiles32 = "c:\\program files" progFiles64 = "c:\\program files (x86)" if os.path.exists(progFiles64): return progFiles64 if os.path.exists(progFiles32): return progFiles32 return None def packageDir(): Hive = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER) Key = _winreg.OpenKey(Hive, "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") _winreg.CloseKey(Hive) for i in range(0, _winreg.QueryInfoKey(Key)[1]): name, value, val_type = _winreg.EnumValue(Key, i) if name == "AppData": candidate = os.path.join(value, "Sublime Text", "Packages") if os.path.exists(candidate): return candidate return None def packageRoot(): return "http://sublime-text-community-packages.googlecode.com/svn/packages/" def listPackages(): packageList = getUrl(packageRoot() + "all.sublime-distro") packageLines = [ line for line in packageList.split("\n") if line.strip() != ""] packageNames = [ os.path.splitext(line)[0] for line in packageLines ] packageNames.sort() return packageNames def downloadPackages(): print "SublimeTextWiki.com Package Downloader" packageContainerUrls = [ "http://sublime-text-community-packages.googlecode.com/svn/packages" ] completedPackageNames = [] for packageUrl in packageContainerUrls: print "Getting package list from " + packageUrl packageList = getUrl(packageUrl) packageNames = [ line for line in packageList.split("\n") if line.strip() != ""] for package in packageNames: downloadLink = packageUrl + "/" + package destination = os.path.join(progFilesDir(), "Sublime Text\\Pristine Packages", package) print "Downloading %s from %s to %s..." % (package, downloadLink, destination) downloadSinglePackage(downloadLink, destination) completedPackageNames.append(package) print "...Downloaded to %s" % destination print "done" return completedPackageNames def downloadSinglePackage(downloadLink, destination): downloadFile = open(destination, 'wb') downloadUrl(downloadLink, downloadFile) downloadFile.close() PKW4=main.sublime-distroPKW4=qL\Package Downloader.package-menu PKW4=Default.sublime-keymap --> PKW4=qf README.txtDownloads any package at [http://sublime-text-community-packages.googlecode.com/svn/index.html](http://sublime-text-community-packages.googlecode.com/svn/index.html). Install it (see below for instructions) and there will now be a menu item to download packages at Tools | Packages | Package Downloader | Browse Packages. Choose a package to download. You should not need to restart Sublime Text -- the plugin should start working straight away.PKW4=v packagedownloaderplugin.pyPKW4=μA  packagedownloader.pyPKW4=\main.sublime-distroPKW4=qL\Package Downloader.package-menuPKW4=Default.sublime-keymapPKW4=qf README.txtPK