Skip to content
Snippets Groups Projects
Commit 803e86d7 authored by Seblu's avatar Seblu
Browse files

handle db add in repo add

parent 09f8b869
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment