diff --git a/installsystems/database.py b/installsystems/database.py index e7e8f111016ae3684a88756d35172d6b4d317dfb..844b1212fe8b5a69bc86b114e4ef211a32b9e274 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 7baa8a506e15c3aaa983064b8e5b757e2e5f4269..1322e8fba32c8e0caa03f79be6fc4f1d97a17557 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()