[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r17429: {updater} Yes, I did mean get. (updater/trunk/lib/thandy/packagesys)



Author: nickm
Date: 2008-12-01 10:49:08 -0500 (Mon, 01 Dec 2008)
New Revision: 17429

Modified:
   updater/trunk/lib/thandy/packagesys/PackageSystem.py
Log:
Yes, I did mean get.

Modified: updater/trunk/lib/thandy/packagesys/PackageSystem.py
===================================================================
--- updater/trunk/lib/thandy/packagesys/PackageSystem.py	2008-12-01 15:42:44 UTC (rev 17428)
+++ updater/trunk/lib/thandy/packagesys/PackageSystem.py	2008-12-01 15:49:08 UTC (rev 17429)
@@ -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 @@
             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 @@
     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 @@
     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 @@
     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 @@
         return self._installer
 
 class Checker:
+    """
+    """
     def __init__(self):
         self._transaction = None
 
@@ -130,10 +156,10 @@
         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):