[tor-commits] [thandy/master] Adds the ThpTransaction class and its basic structure

nickm at torproject.org nickm at torproject.org
Thu Nov 3 19:14:20 UTC 2011


commit 4e9e40f156aee7b4da7519ae1f71d3b1c32e375a
Author: Tomas Touceda <chiiph at gentoo.org>
Date:   Fri Jun 24 10:23:13 2011 -0300

    Adds the ThpTransaction class and its basic structure
---
 lib/thandy/packagesys/ThpPackages.py |   70 ++++++++++++++++++++++++++--------
 lib/thandy/repository.py             |    2 +-
 2 files changed, 55 insertions(+), 17 deletions(-)

diff --git a/lib/thandy/packagesys/ThpPackages.py b/lib/thandy/packagesys/ThpPackages.py
index 3ca9d52..c976d50 100644
--- a/lib/thandy/packagesys/ThpPackages.py
+++ b/lib/thandy/packagesys/ThpPackages.py
@@ -21,6 +21,9 @@ class ThpDB(object):
         if self._thp_db_root is None:
           raise Exception("There is no THP_DB_ROOT variable set")
 
+    def dbPath(self):
+        return self._thp_db_root
+
     def insert(self, pkg):
         thandy.util.replaceFile(os.path.join(self._thp_db_root, "pkg-status",
                                              pkg['package_name'])+".json",
@@ -79,39 +82,70 @@ class ThpChecker(PS.Checker):
     def isInstalled(self):
         return self._version in self.getInstalledVersions()
 
-class ThpInstaller(PS.Installer):
-    def __init__(self, relPath):
-        PS.Installer.__init__(self, relPath)
+class ThpTransaction(object):
+    def __init__(self, packages):
+        self._raw_packages = packages
+        self._installers = []
         self._db = ThpDB()
 
-    def __repr__(self):
-        return "ThpInstaller(%r)" %(self._relPath)
+        self._process()
 
-    def install(self):
-        print "Running thp installer", self._cacheRoot, self._relPath
-        self._thp_root = os.environ.get("THP_INSTALL_ROOT")
-        if self._thp_root is None:
-          raise Exception("There is no THP_INSTALL_ROOT variable set")
+    def _process(self):
+        for package in self._raw_packages:
+            self._installers.append(ThpInstaller(package['path']))
+
+    def _orderByDep(self):
+        """ Orders packages with a topological order by its dependencies """
+        pass
 
-        lockfile = os.path.join(self._thp_db_root, ".lock")
+    def install(self):
+        lockfile = os.path.join(self._db.getPath(), ".lock")
         lock = LockFile(lockfile)
         try:
             lock.acquire()
-            pkg = ThpPackage(os.path.join(self._cacheRoot, self._relPath[1:]))
-            shutil.copytree()
+            order = self._orderByDep(self)
+            for pkg in order:
+                pkg.install()
         except AlreadyLocked:
             print "You can't run more than one instance of Thandy"
         except LockFailed:
             print "Can't acquire lock on %s" % lockfile
+
+        lock.release()
+
+    def remote(self):
+        raise NotImplemented()
+
+class ThpInstaller(PS.Installer):
+    def __init__(self, relPath, db = None):
+        PS.Installer.__init__(self, relPath)
+        self._db = db
+        if db is None:
+            self._db = ThpDB()
+        self._pkg = ThpPackage(os.path.join(self._cacheRoot, self._relPath[1:]))
+
+    def __repr__(self):
+        return "ThpInstaller(%r)" %(self._relPath)
+
+    def install(self):
+        print "Running thp installer", self._cacheRoot, self._relPath
+        self._thp_root = os.environ.get("THP_INSTALL_ROOT")
+        if self._thp_root is None:
+            raise Exception("There is no THP_INSTALL_ROOT variable set")
+
+#        shutil.copytree()
+
 #        self._db.insert(pkg.getAll())
 #        self._db.statusInstalled(pkg.getAll())
 #        self._db.delete(pkg.getAll())
-#        print self._db.exists(pkg.get("package_name"))
 
 
     def remove(self):
         print "Running thp remover"
 
+    def getDeps(self):
+        return self._pkg.getDeps()
+
 class ThpPackage(object):
     def __init__(self, thp_path):
         self._thp_path = thp_path
@@ -125,7 +159,7 @@ class ThpPackage(object):
 
     def _process(self):
         tmpPath = tempfile.mkdtemp(suffix=str(time.time()),
-                                  prefix="thp")
+                                   prefix="thp")
 
         thpFile = zipfile.ZipFile(self._thp_path)
         thpFile.extractall(tmpPath)
@@ -137,11 +171,15 @@ class ThpPackage(object):
 
     def get(self, key):
         if self._metadata:
-          return self._metadata.get(key)
+            return self._metadata.get(key)
 
     def getAll(self):
         return self._metadata
 
+    def getDeps(self):
+        if 'require_packages' in self._metadata.keys():
+            return self._metadata['require_packages']
+
     def isValid(self):
         return self._valid
 
diff --git a/lib/thandy/repository.py b/lib/thandy/repository.py
index ab1c356..d082afb 100644
--- a/lib/thandy/repository.py
+++ b/lib/thandy/repository.py
@@ -496,7 +496,7 @@ class LocalRepository:
                 packages[rp] = pfile
 
             if thpBundle:
-                thpTransactionDict[bundle['name']] = [bundle['packages']]
+                thpTransactionDict[bundle['name']] = bundle['packages']
             thpBundle = False
 
         # We have the packages. If we're downloading via bittorrent, we need





More information about the tor-commits mailing list