[tor-commits] [thandy/master] Log with loggin instead of print, and add thp files to download when needed

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


commit f3602b42ad6db5918323c3b3be1c0d4c335e9c61
Author: Tomás Touceda <chiiph at torproject.org>
Date:   Thu Sep 1 23:50:54 2011 -0300

    Log with loggin instead of print, and add thp files to download when needed
---
 lib/thandy/packagesys/PackageSystem.py |    9 +++++----
 lib/thandy/packagesys/ThpPackages.py   |   30 +++++++++++++++---------------
 lib/thandy/repository.py               |    7 ++++---
 3 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/lib/thandy/packagesys/PackageSystem.py b/lib/thandy/packagesys/PackageSystem.py
index d1060d0..9fb878f 100755
--- a/lib/thandy/packagesys/PackageSystem.py
+++ b/lib/thandy/packagesys/PackageSystem.py
@@ -18,8 +18,11 @@ def getItemsFromPackage(pkg):
             extra = {}
         checker = getChecker(relPath, extra, defaultFormat=format,
                              package=pkg)
-        installer = getInstaller(relPath, extra,
-                                 defaultFormat=format, package=pkg)
+        # we don't need this
+        # installer = getInstaller(relPath, extra,
+        #                          defaultFormat=format, package=pkg)
+        installer = None
+
         result[relPath] = PackageItem(relPath, checker, installer)
     return result
 
@@ -70,7 +73,6 @@ def getChecker(relPath, extra, defaultFormat, package):
         k,v=extra['registry_ent']
         return thandy.packagesys.ExePackages.RegistryChecker(k,v)
     elif checkType == 'thp':
-        print "Getting thp checker"
         import thandy.packagesys.ThpPackages
         return thandy.packagesys.ThpPackages.ThpChecker(
             extra['thp_name'], extra['thp_version'])
@@ -109,7 +111,6 @@ def getInstaller(relPath, extra, defaultFormat, package):
         installer = thandy.packagesys.ExePackages.CommandInstaller(
             relPath, extra['cmd_install'], extra.get('cmd_remove'))
     elif installType == 'thp':
-        print "Getting thp installer"
         import thandy.packagesys.ThpPackages
         installer = thandy.packagesys.ThpPackages.ThpInstaller(
             relPath)
diff --git a/lib/thandy/packagesys/ThpPackages.py b/lib/thandy/packagesys/ThpPackages.py
index 0579b5c..090fe55 100755
--- a/lib/thandy/packagesys/ThpPackages.py
+++ b/lib/thandy/packagesys/ThpPackages.py
@@ -124,22 +124,22 @@ class ThpTransaction(object):
         lockfile = os.path.join(self._db.getPath(), "db")
         lock = LockFile(lockfile)
         try:
-            print "Acquiring lock..."
+            logging.info("Acquiring lock...")
             lock.acquire()
-            print "Lock acquired"
+            logging.info("Lock acquired")
             order = self._orderByDep()
             for pkg in order:
                 if pkg.run('checkinst') != 0:
-                    print "Check inst failed for %s" % pkg
+                    logging.info("Check inst failed for %s" % pkg)
                     sys.exit(1)
             for pkg in order:
-                print "Starting installation using", pkg
+                logging.info("Starting installation using %s" % pkg)
                 if pkg.run('preinst') != 0:
-                    print "Preinst script for %s failed" % pkg
+                    logging.info("Preinst script for %s failed" % pkg)
                     sys.exit(1)
                 pkg.install()
                 if pkg.run('postinst') != 0:
-                    print "WARN: postinst script failed"
+                    logging.info("postinst script failed")
         except AlreadyLocked:
             print "You can't run more than one instance of Thandy"
         except LockFailed:
@@ -163,16 +163,16 @@ class ThpInstaller(PS.Installer):
         return "ThpInstaller(%r)" %(self._relPath)
 
     def install(self):
-        print "Running thp installer", self._cacheRoot, self._relPath
+        logging.info("Running thp installer %s %s" % (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")
 
         destPath = os.path.join(self._thp_root, self._pkg.get("package_name"))
-        print "Destination directory:", destPath
+        logging.info("Destination directory: %s" % destPath)
 
         if self._db.exists(self._pkg.get("package_name")):
-            print "%s is already installed, switching to upgrade mode." % self._pkg.get("package_name")
+            logging.info("%s is already installed, switching to upgrade mode." % self._pkg.get("package_name"))
             self._db.startUpgrade()
 
         pkg_metadata = self._pkg.getAll()
@@ -183,13 +183,13 @@ class ThpInstaller(PS.Installer):
         try:
             os.mkdir(dir)
         except:
-            print "%s: Already exists, using it." % dir
+            logging.info("%s: Already exists, using it." % dir)
 
         for file in self._pkg.get('manifest'):
             if file['is_config']:
-                print "Ignoring file:", file
+                logging.info("Ignoring file: %s" % file)
             else:
-              print "Processing file:", file
+              logging.info("Processing file: %s" % file)
               try:
                   # Create all the needed dirs
                   os.makedirs(os.sep.join((os.path.join(destPath, file['name'])
@@ -201,7 +201,7 @@ class ThpInstaller(PS.Installer):
                               os.path.join(destPath, file['name']));
 
         if self._db.isUpgrading():
-            print "Finishing upgrade."
+            logging.info("Finishing upgrade.")
             self._db.finishUpgrade(self._pkg.get('package_name'))
 
         self._db.statusInstalled(pkg_metadata)
@@ -243,8 +243,8 @@ class ThpPackage(object):
         (allOk, where) = self._validateFiles(self._tmp_path)
 
         if not allOk:
-            print "These files have different digests:"
-            print where
+            logging.info("These files have different digests:")
+            logging.info(where)
             sys.exit(1)
 
         if "scripts" in self._metadata:
diff --git a/lib/thandy/repository.py b/lib/thandy/repository.py
index f0b51b8..bb7d2f6 100755
--- a/lib/thandy/repository.py
+++ b/lib/thandy/repository.py
@@ -489,13 +489,14 @@ class LocalRepository:
                 # are thp too. But we continue with the loop to check every
                 # package digest and signature
                 pfile_data = pfile.get()
+
+                packages[rp] = pfile
+
                 if pfile_data["format"] == "thp":
                     thpTransactionDict[bundle['name']] = {}
                     thpTransactionDict[bundle['name']][pfile_data['name']] = pfile_data
                     continue
 
-                packages[rp] = pfile
-
         # We have the packages. If we're downloading via bittorrent, we need
         # the .torrent metafiles, as well.
         if thandy.bt_compat.BtCompat.shouldUseBt():
@@ -524,7 +525,7 @@ class LocalRepository:
         # files?
         for pfile in packages.values():
             package = pfile.get()
-
+            
             alreadyInstalled = set()
             pkgItems = {}
 





More information about the tor-commits mailing list