summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@torproject.org>2011-11-01 13:20:49 -0300
committerTomás Touceda <chiiph@torproject.org>2011-11-01 13:20:49 -0300
commit3e752ddc9435831c5d74181e070ec8c5ba1b714e (patch)
tree48f899e0c6c6d435b614ac7711a9fb1b33911317
parent87470801fdc396b54bf0f7f8bfe73f05431aa080 (diff)
Make transactions not Thp specific
-rw-r--r--lib/thandy/ClientCLI.py25
-rw-r--r--lib/thandy/packagesys/PackageSystem.py29
-rw-r--r--lib/thandy/packagesys/ThpPackages.py8
-rw-r--r--lib/thandy/repository.py34
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