From 8519bcad8db1af803d00a0e439a8860fc2d6c631 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 1 Dec 2008 15:49:08 +0000 Subject: Yes, I did mean get. git-svn-id: file:///home/or/svnrepo/updater/trunk@17429 55e972cd-5a19-0410-ae62-a4d7a52db4cd --- lib/thandy/packagesys/PackageSystem.py | 50 ++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/thandy/packagesys/PackageSystem.py b/lib/thandy/packagesys/PackageSystem.py index 0145727..94d788c 100644 --- a/lib/thandy/packagesys/PackageSystem.py +++ b/lib/thandy/packagesys/PackageSystem.py @@ -3,6 +3,11 @@ import os def getItemsFromPackage(pkg): + """Given a Thandy package decoded from its json format, return a dict + with an entry for each installable item in the path, mapping the + item's relative path to a PackageItem object that can check or + install that item. + """ result = {} format = pkg.get('format') for item in pkg['files']: @@ -11,19 +16,27 @@ def getItemsFromPackage(pkg): extra = item[2] else: extra = {} - checkFormat = extra.get("check_type") - installFormat = extra.get("install_type") - - checker = getChecker(checkFormat, relPath, extra, defaultFormat=format, + checker = getChecker(relPath, extra, defaultFormat=format, package=pkg) - installer = getInstaller(installFormat, relPath, extra, + installer = getInstaller(relPath, extra, defaultFormat=format, package=pkg) result[relPath] = PackageItem(relPath, checker, installer) return result -def getChecker(checkType, relPath, extra, defaultFormat, package): +def getChecker(relPath, extra, defaultFormat, package): + """Return a Checker instance for an item in a package, or None if we + don't know how to check that item. + + relPath -- the item's relative path in the repository. + extra -- the info part of the item's entry in the package. + defaultFormat -- the value of the package's "format" field. + Only used for obsolete checker types. + package -- the package object itself. Only used for obsolete + checker types. + """ + checkType = extra.get("check_type") if checkType == None: - #DOCDOC obsolete + # This part is for obsolete packages. if defaultFormat == 'rpm': import thandy.packagesys.RPMPackages return thandy.packagesys.RPMPackages.RPMChecker( @@ -56,9 +69,14 @@ def getChecker(checkType, relPath, extra, defaultFormat, package): else: return None -def getInstaller(installType, relPath, extra, defaultFormat, package): +def getInstaller(relPath, extra, defaultFormat, package): + """Return an Installer for an item in a package, or None if we don't + know how to install that item. Arguments are as for getChecker(). + """ + installType = extra.get("install_type") + if installType == None: - # XXX obsolete. + # This part is for obsolete packages. if defaultFormat == 'rpm': import thandy.packagesys.RPMPackages return thandy.packagesys.RPMPackages.RPMInstaller( @@ -81,7 +99,7 @@ def getInstaller(installType, relPath, extra, defaultFormat, package): elif installType == 'command': import thandy.packagesys.ExePackages installer = thandy.packagesys.ExePackages.CommandInstaller( - relPath, extra['cmd_install']) + relPath, extra['cmd_install'], extra.get('cmd_remove')) else: return None @@ -93,23 +111,29 @@ def getInstaller(installType, relPath, extra, defaultFormat, package): return installer class PackageItem: + """Represents a single item from a package.""" def __init__(self, relativePath, checker, installer): self._relPath = relativePath self._checker = checker self._installer = installer def setTransaction(self, transaction): + """Set the transaction context for this item to 'transaction'. + """ if self._cheker is not None: self._checker.setTransaction(transaction) if self._installer is not None: self._installer.setTransaction(transaction) def setCacheRoot(self, cacheRoot): + """Tell this item to look for files relative to 'cacheRoot'.""" if self._installer is not None: self._installer.setCacheRoot(cacheRoot) def canCheck(self): + """Return true iff we know how to check if this item is installed.""" return self._checker != None def canInstall(self): + """Return true iff we know how to install this item.""" return self._installer != None def getChecker(self): return self._checker @@ -117,6 +141,8 @@ class PackageItem: return self._installer class Checker: + """ + """ def __init__(self): self._transaction = None @@ -130,10 +156,10 @@ class Checker: raise len(self.getInstalledVersions()) > 1 def getInstalledVersions(self): - raise NotImplemented() + raise NotImplemented def isInstalled(self): - raise NotImplemented() + raise NotImplemented class Installer: def __init__(self, relativePath): -- cgit v1.2.3