From 803e86d7aad136179e8038a9f3a3fafbe269443d Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Tue, 28 Jun 2011 13:49:32 +0200 Subject: [PATCH] handle db add in repo add --- installsystems/database.py | 35 ----------------------------------- installsystems/repository.py | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/installsystems/database.py b/installsystems/database.py index e7e8f11..844b121 100644 --- a/installsystems/database.py +++ b/installsystems/database.py @@ -68,38 +68,3 @@ class Database(object): Ask question to db ''' return self.conn.execute(sql, args) - - def add(self, image): - '''Add a packaged image to a db''' - try: - # let's go - arrow("Begin transaction to db") - arrowlevel(1) - self.conn.execute("BEGIN TRANSACTION") - # insert image information - arrow("Add image metadata") - self.conn.execute("INSERT INTO image values (?,?,?,?,?,?,?)", - (image.md5, - image.name, - image.version, - image.date, - image.author, - image.description, - image.size, - )) - # insert data informations - arrow("Add payload metadata") - for name, obj in image.payload.items(): - self.conn.execute("INSERT INTO payload values (?,?,?,?,?)", - (obj.md5, - image.md5, - name, - obj.isdir, - obj.size, - )) - # on commit - arrow("Commit transaction to db") - self.conn.execute("COMMIT TRANSACTION") - arrowlevel(-1) - except Exception as e: - raise Exception("Adding metadata fail: %s" % e) diff --git a/installsystems/repository.py b/installsystems/repository.py index 7baa8a5..1322e8f 100644 --- a/installsystems/repository.py +++ b/installsystems/repository.py @@ -118,7 +118,31 @@ class Repository(object): # checking image and payload after copy r_image.check("Check image and payload after copy") # add description to db - self.db.add(r_image) + arrow("Adding metadata") + self.db.begin() + # insert image information + arrow("Image", 1) + self.db.ask("INSERT INTO image values (?,?,?,?,?,?,?)", + (image.md5, + image.name, + image.version, + image.date, + image.author, + image.description, + image.size, + )) + # insert data informations + arrow("Payloads", 1) + for name, obj in image.payload.items(): + self.db.ask("INSERT INTO payload values (?,?,?,?,?)", + (obj.md5, + image.md5, + name, + obj.isdir, + obj.size, + )) + # on commit + self.db.commit() # update last file self.update_last() -- GitLab