[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Keep track of when a package was last added to a suite



---
 dak/dakdb/update115.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
 dak/process_policy.py  |  2 ++
 daklib/archive.py      |  2 ++
 daklib/dbconn.py       |  3 +++
 4 files changed, 66 insertions(+)
 create mode 100644 dak/dakdb/update115.py

diff --git a/dak/dakdb/update115.py b/dak/dakdb/update115.py
new file mode 100644
index 0000000..3dd3e84
--- /dev/null
+++ b/dak/dakdb/update115.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+# coding=utf8
+
+"""
+Add last_changed to suite
+
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2016, Ansgar Burchardt <ansgar@debian.org>
+@license: GNU General Public License version 2 or later
+"""
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+################################################################################
+
+import psycopg2
+from daklib.dak_exceptions import DBUpdateError
+from daklib.config import Config
+
+statements = [
+"""
+ALTER TABLE suite
+  ADD COLUMN last_changed TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
+""",
+"""
+COMMENT ON COLUMN suite.last_changed
+  IS 'When the suite was last changed by adding/removing packages and needs to be republished'
+"""
+]
+
+################################################################################
+def do_update(self):
+    print __doc__
+    try:
+        cnf = Config()
+
+        c = self.db.cursor()
+
+        for stmt in statements:
+            c.execute(stmt)
+
+        c.execute("UPDATE config SET value = '115' WHERE name = 'db_revision'")
+        self.db.commit()
+
+    except psycopg2.ProgrammingError as msg:
+        self.db.rollback()
+        raise DBUpdateError('Unable to apply sick update 115, rollback issued. Error message: {0}'.format(msg))
diff --git a/dak/process_policy.py b/dak/process_policy.py
index 8966dd6..ab37aa2 100755
--- a/dak/process_policy.py
+++ b/dak/process_policy.py
@@ -213,6 +213,8 @@ def comment_accept(upload, srcqueue, comments, transaction):
                 extra_archives=[upload.target_suite.archive],
             )
 
+        suite.update_last_changed()
+
     # Copy .changes if needed
     if upload.target_suite.copychanges:
         src = os.path.join(upload.policy_queue.path, upload.changes.changesname)
diff --git a/daklib/archive.py b/daklib/archive.py
index fc31b6a..bfab2c6 100644
--- a/daklib/archive.py
+++ b/daklib/archive.py
@@ -1068,6 +1068,8 @@ class ArchiveUpload(object):
             dst = os.path.join(suite.archive.path, 'dists', suite.suite_name, self.changes.filename)
             self.transaction.fs.copy(src, dst, mode=suite.archive.mode)
 
+        suite.update_last_changed()
+
         return (db_source, db_binaries)
 
     def _install_changes(self):
diff --git a/daklib/dbconn.py b/daklib/dbconn.py
index 3d3561f..58ad041 100755
--- a/daklib/dbconn.py
+++ b/daklib/dbconn.py
@@ -1948,6 +1948,9 @@ class Suite(ORMObject):
         else:
             return object_session(self).query(Suite).filter_by(suite_name=self.overridesuite).one()
 
+    def update_last_changed(self):
+        self.last_changed = sqlalchemy.func.now()
+
     @property
     def path(self):
         return os.path.join(self.archive.path, 'dists', self.suite_name)
-- 
2.1.4



Reply to: