diff --git a/installsystems/database.py b/installsystems/database.py index d0bfbf30c21bfecdf7809a4b54bfdad7b5fd8816..2237134daeeba5c14d6176e76d23b7a8eeaebad7 100644 --- a/installsystems/database.py +++ b/installsystems/database.py @@ -40,15 +40,24 @@ class Database(object): def add(self, package): '''Add a packaged image to a db''' arrow("Adding metadata to db", 1, self.verbose) - name = "%s.json" % package.name() + # naming + name = "%s.json" % package.name newdb_path = "%s.new" % self.path + # compute md5 + arrow("Compute MD5 of %s" % os.path.relpath(package.path), 2, self.verbose) + md5 = package.md5 + arrow("Formating metadata", 2, self.verbose) + desc = package.description + desc["md5"] = md5 + jdesc = json.dumps(desc) try: + arrow("Adding to tarball", 2, self.verbose) db = Tarball.open(self.path, mode='r:bz2') newdb = Tarball.open(newdb_path, mode='w:bz2') for ti in db.getmembers(): if ti.name != name: newdb.addfile(ti, db.extractfile(ti)) - newdb.add_str(name, package.jdescription(), tarfile.REGTYPE, 0444) + newdb.add_str(name, jdesc, tarfile.REGTYPE, 0444) db.close() newdb.close() # preserve permission and stats when moving diff --git a/installsystems/image.py b/installsystems/image.py index 389ebef6b95568c5f75813059f746666dd36838b..4484a501079fd07e953f69f4815d02ae0c00226b 100644 --- a/installsystems/image.py +++ b/installsystems/image.py @@ -13,7 +13,6 @@ import json import StringIO import ConfigParser import subprocess -import json import tarfile import re import installsystems.template as istemplate @@ -267,6 +266,22 @@ class PackageImage(Image): self.tarball = Tarball.open(self.path, mode='r:bz2') self.parse() + @property + def md5(self): + '''Return md5sum of the current tarball''' + return istools.md5sum(self.path) + + @property + def name(self): + '''Return image name''' + return "%s-%s" % (self.description["name"], self.description["version"]) + + @property + def databalls(self): + '''Create a dict of image and data tarballs''' + return [ os.path.join(self.base_path, d) + for d in self.description["data"] ] + def parse(self): '''Parse tarball and extract metadata''' # extract metadata @@ -289,29 +304,13 @@ class PackageImage(Image): arrow("Check MD5", 1, self.verbose) databalls = self.description["data"] for databall in databalls: - arrow(databall, 2, self.verbose) + md5_path = os.path.join(self.base_path, databall) + arrow(os.path.relpath(md5_path), 2, self.verbose) md5_meta = databalls[databall]["md5"] - md5_file = istools.md5sum(os.path.join(self.base_path, databall)) + md5_file = istools.md5sum(md5_path) if md5_meta != md5_file: raise Exception("Invalid md5: %s" % databall) - def description(self): - '''Return metadatas of a tarball''' - return self.description - - def jdescription(self): - '''Return json formated metadatas''' - return json.dumps(self.description) - - def name(self): - '''Return image name''' - return "%s-%s" % (self.description["name"], self.description["version"]) - - def databalls(self): - '''Create a dict of image and data tarballs''' - return [ os.path.join(self.base_path, d) - for d in self.description["data"] ] - def run_parser(self, gl): '''Run parser scripts''' self.run_scripts(gl, "parser") diff --git a/installsystems/repository.py b/installsystems/repository.py index 16759299430b439318e911226c3d333f089359a1..88fc9acb73a6475a58684088b664dd7e0e32d8cc 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -73,10 +73,10 @@ class Repository(object): '''Add a packaged image to repository''' # copy file to directory arrow("Adding file to directories", 1, self.verbose) - arrow("Adding %s" % os.path.basename(package.path), 2, self.verbose) + arrow("Adding %s" % os.path.relpath(package.path), 2, self.verbose) istools.copy(package.path, self.config.image, self.config.chown, self.config.chgroup, self.config.fchmod) - for db in package.databalls(): + for db in package.databalls: arrow("Adding %s" % os.path.basename(db), 2, self.verbose) istools.copy(db, self.config.data, self.config.chown, self.config.chgroup, self.config.fchmod) @@ -92,8 +92,8 @@ class Repository(object): error("Unable to find %s version %s in database" % (name, version)) # removing script tarballs arrow("Removing script tarball", 1, self.verbose) - tpath = os.path.join(self.config.image, "%s-%s%s" % (name, version, - Image.image_extension)) + tpath = os.path.join(self.config.image, + "%s-%s%s" % (name, version, Image.image_extension)) if os.path.exists(tpath): os.unlink(tpath) arrow("%s removed" % os.path.basename(tpath), 2, self.verbose) @@ -201,8 +201,8 @@ class RepositoryCache(object): arrow("Updating repositories", 1, self.verbose) for r in self.repos: debug("%s: remote_last: %s, local_last:%s" % (r, - self.repos[r].last(), - self.last(r))) + self.repos[r].last(), + self.last(r))) if self.repos[r].last() > self.last(r): # copy last file istools.copy(self.repos[r].last_path, os.path.join(self.last_path, r))