From: Michael Tremer Date: Sat, 26 Oct 2013 21:20:10 +0000 (+0200) Subject: Add scriptlets to the database and actually execute them. X-Git-Tag: 0.9.27~14^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=752688419abfb704ac860f2bc224defe900e849f;p=pakfire.git Add scriptlets to the database and actually execute them. --- diff --git a/src/pakfire/packages/base.py b/src/pakfire/packages/base.py index 543f50969..36758e318 100644 --- a/src/pakfire/packages/base.py +++ b/src/pakfire/packages/base.py @@ -483,6 +483,9 @@ class Package(object): def scriptlets(self): return self.metadata.get("PKG_SCRIPTLETS", "").splitlines() + def get_scriptlet(self, action): + raise NotImplementedError + @property def filelist(self): raise NotImplementedError diff --git a/src/pakfire/packages/installed.py b/src/pakfire/packages/installed.py index 6210c8887..b358f6404 100644 --- a/src/pakfire/packages/installed.py +++ b/src/pakfire/packages/installed.py @@ -198,6 +198,21 @@ class DatabasePackage(Package): def scriptlet(self): return self.metadata.get("scriptlet") + def get_scriptlet(self, action): + c = self.db.cursor() + c.execute("SELECT scriptlet FROM scriptlets WHERE pkg = ? AND action = ? LIMIT 1", (self.id, action,)) + + try: + row = c.fetchone() + + # If no row was returned, no scriptlet for this action + # does exist. + if row: + return row["scriptlet"] + + finally: + c.close() + @property def filename(self): return self.metadata.get("filename") diff --git a/src/pakfire/packages/solv.py b/src/pakfire/packages/solv.py index d6a8a407b..e8975028c 100644 --- a/src/pakfire/packages/solv.py +++ b/src/pakfire/packages/solv.py @@ -255,7 +255,3 @@ class SolvPackage(base.Package): self.repo.download(self, text=text, logger=logger) return self.get_from_cache() - - def get_scriptlet(self, type): - # XXX TODO - return None diff --git a/src/pakfire/repository/database.py b/src/pakfire/repository/database.py index 4b3506e69..6780aa217 100644 --- a/src/pakfire/repository/database.py +++ b/src/pakfire/repository/database.py @@ -406,6 +406,17 @@ class DatabaseLocal(Database): " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", ((f.name, pkg_id, f.size, f.is_config(), f.is_datafile(), f.type, f.hash1, f.mode, f.user, f.group, f.mtime, f.capabilities or "") for f in pkg.filelist)) + # Add scriptlets + for scriptlet_action in SCRIPTS: + scriptlet = pkg.get_scriptlet(scriptlet_action) + + # If there is no scriptlet, just skip to the next one. + if not scriptlet: + continue + + c.execute("INSERT INTO scriptlets(pkg, action, scriptlet) VALUES(?, ?, ?)", + (pkg_id, scriptlet_action, scriptlet)) + except: raise @@ -422,6 +433,7 @@ class DatabaseLocal(Database): # First, delete all files from the database and then delete the pkg itself. c = self.cursor() c.execute("DELETE FROM files WHERE pkg = ?", (pkg.id,)) + c.execute("DELETE FROM scriptlets WHERE pkg = ?", (pkg.id,)) c.execute("DELETE FROM packages WHERE id = ?", (pkg.id,)) c.close()