commit f7d25a033439d904d24a4ef290fab440b0a54a1a Author: Tomas Touceda chiiph@gentoo.org Date: Wed Jun 22 10:08:57 2011 -0300
Add really simple checker, installer and thpdb
But it's still not finished. --- lib/thandy/formats.py | 1 + lib/thandy/packagesys/PackageSystem.py | 4 ++ lib/thandy/packagesys/ThpPackages.py | 73 ++++++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/lib/thandy/formats.py b/lib/thandy/formats.py index d1b9e5f..f57ab46 100644 --- a/lib/thandy/formats.py +++ b/lib/thandy/formats.py @@ -782,6 +782,7 @@ def makePackageObj(config_fname, package_fname): extra['cmd_install'] = [ "${FILE}" ] + r['exe_args'] elif format == 'thp': extra['check_type'] = 'thp' + extra['install_type'] = 'thp' extra['thp_name'] = r['name'] extra['thp_version'] = r['version']
diff --git a/lib/thandy/packagesys/PackageSystem.py b/lib/thandy/packagesys/PackageSystem.py index 6a8ab60..ccf5532 100644 --- a/lib/thandy/packagesys/PackageSystem.py +++ b/lib/thandy/packagesys/PackageSystem.py @@ -107,6 +107,10 @@ def getInstaller(relPath, extra, defaultFormat, package): import thandy.packagesys.ExePackages installer = thandy.packagesys.ExePackages.CommandInstaller( relPath, extra['cmd_install'], extra.get('cmd_remove')) + elif installType == 'thp': + import thandy.packagesys.ThpPackages + installer = thandy.packagesys.ThpPackages.ThpInstaller( + relPath) else: return None
diff --git a/lib/thandy/packagesys/ThpPackages.py b/lib/thandy/packagesys/ThpPackages.py index 10392e4..ae86128 100644 --- a/lib/thandy/packagesys/ThpPackages.py +++ b/lib/thandy/packagesys/ThpPackages.py @@ -7,11 +7,78 @@ import thandy.util import thandy.packagesys.PackageSystem as PS import thandy.packagesys.PackageDB as PDB
+json = thandy.util.importJSON() + class ThpDB(object): - pass + def __init__(self): + 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 insert(self, pkg): + thandy.util.replaceFile(os.path.join(self._thp_root, + pkg['package_name']), + pkg) + + def delete(self, pkg): + try: + os.unlink(os.path.join(self._thp_root, + pkg['package_name'])) + except Exception as e: + print e + + def update(self, pkg): + self.insert(pkg) + + def exists(self, name): + fname = os.path.join(self._thp_root, name) + fexists = os.path.exists(fname) + + version = -1 + if fexists: + contents = open(fname, "r").read() + metadata = json.loads(contents) + version = metadata['package_version'] + return exists, version
class ThpChecker(PS.Checker): - pass + def __init__(self, name, version): + PS.Checker.__init__(self) + self._name = name + self._version = version + self._db = ThpDB() + + def __repr__(self): + return "ThpChecker(%r, %r)"%(self._name, self._version) + + def getInstalledVersions(self): + versions = [] + (exists, version) = self._db.exists(self._name): + + if exists: + versions.append(version) + + return versions + + def isInstalled(self): + return self._version in self.getInstalledVersions()
class ThpInstaller(PS.Installer): - pass + def __init__(self, relPath, installCommand, removeCommand=None): + PS.Installer.__init__(self, relPath) + self._db = ThpDB() + + def __repr__(self): + return "ThpInstaller(%r)" %(self._relPath) + + def install(self): + 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() + + def remove(self): + if self._removeCommand: + raise thandy.RemoveNotSupported() + self._runCommand(self._removeCommand)
tor-commits@lists.torproject.org