[tor-commits] [thandy/master] Make transactions not Thp specific
nickm at torproject.org
nickm at torproject.org
Thu Nov 3 19:14:20 UTC 2011
commit 3e752ddc9435831c5d74181e070ec8c5ba1b714e
Author: Tomás Touceda <chiiph at torproject.org>
Date: Tue Nov 1 13:20:49 2011 -0300
Make transactions not Thp specific
---
lib/thandy/ClientCLI.py | 25 +++++++++++------------
lib/thandy/packagesys/PackageSystem.py | 29 +++++++++++++++++++++++++++
lib/thandy/packagesys/ThpPackages.py | 8 +++++-
lib/thandy/repository.py | 34 ++++++++++++++-----------------
4 files changed, 62 insertions(+), 34 deletions(-)
diff --git a/lib/thandy/ClientCLI.py b/lib/thandy/ClientCLI.py
index f3192f9..d3bcaf0 100644
--- a/lib/thandy/ClientCLI.py
+++ b/lib/thandy/ClientCLI.py
@@ -15,7 +15,6 @@ import thandy.repository
import thandy.download
import thandy.master_keys
import thandy.packagesys.PackageSystem
-import thandy.packagesys.ThpPackages
import thandy.socksurls
import thandy.encodeToXML
@@ -121,7 +120,6 @@ def update(args):
lengths = {}
installable = {}
btMetadata = {}
- thpTransactions = {}
alreadyInstalled = set()
logging.info("Checking for files to update.")
files, downloadingFiles = repo.getFilesToUpdate(
@@ -131,23 +129,24 @@ def update(args):
usePackageSystem=use_packagesys,
installableDict=installable,
btMetadataDict=btMetadata,
- thpTransactionDict=thpTransactions,
- alreadyInstalledSet=alreadyInstalled)
+ alreadyInstalledSet=alreadyInstalled,
+ cacheRoot=repoRoot)
if forceCheck:
files.add("/meta/timestamp.txt")
forceCheck = False
- if thpTransactions and not files:
- for bundle in thpTransactions:
- tr = thandy.packagesys.ThpPackages.ThpTransaction(thpTransactions[bundle],
- alreadyInstalled,
- repoRoot)
- if tr.isReady():
+ if installable and not files:
+ for bundle, transaction in installable.items():
+ if transaction.isReady():
logCtrl("READY", BUNDLE=bundle)
- if install and tr.isReady():
- tr.install()
- logCtrl("INSTALLED", BUNDLE=bundle)
+ logging.info("Ready to install packages for files: %s",
+ ", ".join(sorted(installable.keys())))
+
+ if install:
+ for p in installable.values():
+ if p.isReady():
+ p.install()
return
diff --git a/lib/thandy/packagesys/PackageSystem.py b/lib/thandy/packagesys/PackageSystem.py
index d255bef..b2e66a1 100644
--- a/lib/thandy/packagesys/PackageSystem.py
+++ b/lib/thandy/packagesys/PackageSystem.py
@@ -121,6 +121,16 @@ def getInstaller(relPath, extra, defaultFormat, package):
return installer
+def getTransaction(transactionType, packages, alreadyInstalledSet, cacheRoot):
+ """ Return a transaction from the type transactionType considering
+ the alreadyInstalledSet and that works in the cacheRoot """
+ if transactionType == "thp":
+ import thandy.packagesys.ThpPackages
+ return thandy.packagesys.ThpPackages.ThpTransaction(packages,
+ alreadyInstalledSet,
+ cacheRoot)
+ return None
+
class PackageItem:
"""Represents a single item from a package."""
def __init__(self, relativePath, checker, installer):
@@ -237,4 +247,23 @@ class Installer:
"DOCDOC params, manifest"
return None, None
+class Transaction(object):
+ """ Abstract base class. A Transaction knows how to install or
+ remove a bundle. """
+ def __init__(self, packages, alreadyInstalled, repoRoot):
+ self._raw_packages = packages
+ self._repo_root = repoRoot
+ self._alreadyInstalled = alreadyInstalled
+ def isReady(self):
+ """ Returns True if the transaction is ready to start installing
+ or removing a bundle. """
+ raise NotImplemented()
+
+ def install(self):
+ """ Installs the packages that belong to this transaction. """
+ raise NotImplemented()
+
+ def remove(self):
+ """ Removes the packages that belong to this transaction. """
+ raise NotImplemented()
diff --git a/lib/thandy/packagesys/ThpPackages.py b/lib/thandy/packagesys/ThpPackages.py
index b558d59..f82415e 100644
--- a/lib/thandy/packagesys/ThpPackages.py
+++ b/lib/thandy/packagesys/ThpPackages.py
@@ -142,7 +142,7 @@ class ThpChecker(PS.Checker):
# we need to reinstall
return (status == "INSTALLED" and self._version in versions)
-class ThpTransaction(object):
+class ThpTransaction(PS.Transaction):
""" Represents the installation of a bundle that contains thp packages. """
def __init__(self, packages, alreadyInstalled, repoRoot):
self._raw_packages = packages
@@ -254,8 +254,12 @@ class ThpInstaller(PS.Installer):
except:
# Ignore if it already exists
pass
+
+ if "/" in file["name"]:
+ os.makedirs("/".join([destPath] + file["name"].split("/")[:-1]))
+
shutil.copy(os.path.join(self._pkg.getTmpPath(), "content", file['name']),
- os.path.join(destPath, file['name']));
+ os.path.join(destPath, file['name']));
if self._db.isUpgrading():
logging.info("Finishing upgrade.")
diff --git a/lib/thandy/repository.py b/lib/thandy/repository.py
index 0b45c8d..b294018 100644
--- a/lib/thandy/repository.py
+++ b/lib/thandy/repository.py
@@ -302,12 +302,13 @@ class LocalRepository:
def getFilesToUpdate(self, now=None, trackingBundles=(), hashDict=None,
lengthDict=None, usePackageSystem=True,
installableDict=None, btMetadataDict=None,
- thpTransactionDict=None, alreadyInstalledSet=None):
+ alreadyInstalledSet=None,
+ cacheRoot=None):
"""Return a set of relative paths for all files that we need
to fetch, and True if we're fetching actual files to install
instead of metadata. Assumes that we care about the bundles
'trackingBundles'.
- DOCDOC installableDict, hashDict, usePackageSystem, thpTransaction
+ DOCDOC installableDict, hashDict, usePackageSystem
"""
if now == None:
@@ -326,10 +327,8 @@ class LocalRepository:
if btMetadataDict == None:
btMetadataDict = {}
- if thpTransactionDict == None:
- thpTransactionDict = {}
-
pkgItems = None
+ transactions = {}
need = set()
@@ -497,10 +496,8 @@ class LocalRepository:
packages[rp] = pfile
- if pfile_data["format"] == "thp":
- if not bundle['name'] in thpTransactionDict.keys():
- thpTransactionDict[bundle['name']] = {}
- thpTransactionDict[bundle['name']][pfile_data['name']] = pfile_data
+ transactions.setdefault(pfile_data["format"], {})\
+ .setdefault(bundle["name"], {})[pfile_data["name"]] = pfile_data
# We have the packages. If we're downloading via bittorrent, we need
# the .torrent metafiles, as well.
@@ -546,8 +543,6 @@ class LocalRepository:
try:
if item.getChecker().isInstalled():
alreadyInstalledSet.add(item.getRelativePath())
- if item.getRelativePath() in thpTransactionDict.keys():
- thpTransactionDict.pop(item.getRelativePath())
except thandy.CheckNotSupported, err:
logging.warn("Can't check installed-ness of %s: %s",
f[0], err)
@@ -577,14 +572,15 @@ class LocalRepository:
if h_got != h_expected:
logging.info("Hash for %s not as expected; must load.", rp)
need.add(rp)
- else:
- # XXX What if not? Maybe this should always be true.
- # if that works, we can get rid of the second return
- # value and just use installableDict from the caller.
- if pkgItems.has_key(rp):
- if pkgItems[rp]:
- installableDict.setdefault(pkg_rp, {})[rp] = pkgItems[rp]
-
+ if len(need) == 0:
+ # We have done everything, lets see if we have thp bundles,
+ # and create the transaction for it as the installable item
+ for transaction_type in transactions:
+ for bundle in transactions[transaction_type]:
+ installableDict[bundle] = thandy.packagesys.PackageSystem.getTransaction(transaction_type,
+ transactions[transaction_type][bundle],
+ alreadyInstalledSet,
+ cacheRoot)
# Okay; these are the files we need.
return need, True
More information about the tor-commits
mailing list