]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/command.py
daklib/command.py: process all sections and not only the first one
[dak.git] / daklib / command.py
index 31551d7536162377c86dc1e3585a3d079439f8e5..88f65558c5e9659fe31da57acd4c95a4e7fa4c4b 100644 (file)
@@ -62,18 +62,23 @@ class CommandFile(object):
     def _evaluate_sections(self, sections, session):
         session.rollback()
         try:
-            sections.next()
-            section = sections.section
-
-            action = section.get('Action', None)
-            if action is None:
-                raise CommandError('Encountered section without Action field')
-            self.result.append('Action: {0}'.format(action))
-
-            if action == 'dm':
-                self.action_dm(self.fingerprint, section, session)
-            else:
-                raise CommandError('Unknown action: {0}'.format(action))
+            while True:
+                sections.next()
+                section = sections.section
+
+                action = section.get('Action', None)
+                if action is None:
+                    raise CommandError('Encountered section without Action field')
+                self.result.append('Action: {0}'.format(action))
+
+                if action == 'dm':
+                    self.action_dm(self.fingerprint, section, session)
+                elif action == 'break-the-archive':
+                    self.action_break_the_archive(self.fingerprint, section, session)
+                else:
+                    raise CommandError('Unknown action: {0}'.format(action))
+
+                self.result.append('')
         except StopIteration:
             pass
         finally:
@@ -155,13 +160,12 @@ class CommandFile(object):
             self.result.append('')
         except Exception as e:
             self.log.log(['ERROR', e])
-            self.result.append("There was an error processing this section:\n{0}".format(e))
+            self.result.append("There was an error processing this section. No changes were committed.\nDetails:\n{0}".format(e))
             result = False
 
         self._notify_uploader()
 
         session.close()
-        self.log.log(['done', self.filename])
 
         return result
 
@@ -201,11 +205,17 @@ class CommandFile(object):
             self.result.append('Uid: {0}'.format(addresses[0]))
 
         for source in self._split_packages(section.get('Allow', '')):
+            # Check for existance of source package to catch typos
+            if session.query(DBSource).filter_by(source=source).first() is None:
+                raise CommandError('Tried to grant permissions for unknown source package: {0}'.format(source))
+
             if session.query(ACLPerSource).filter_by(acl=acl, fingerprint=fpr, source=source).first() is None:
                 aps = ACLPerSource()
                 aps.acl = acl
                 aps.fingerprint = fpr
                 aps.source = source
+                aps.created_by = fingerprint
+                aps.reason = section.get('Reason')
                 session.add(aps)
                 self.log.log(['dm', 'allow', fpr.fingerprint, source])
                 self.result.append('Allowed: {0}'.format(source))
@@ -215,8 +225,20 @@ class CommandFile(object):
         session.flush()
 
         for source in self._split_packages(section.get('Deny', '')):
-            session.query(ACLPerSource).filter_by(acl=acl, fingerprint=fpr, source=source).delete()
+            count = session.query(ACLPerSource).filter_by(acl=acl, fingerprint=fpr, source=source).delete()
+            if count == 0:
+                raise CommandError('Tried to remove upload permissions for package {0}, '
+                                   'but no upload permissions were granted before.'.format(source))
+
             self.log.log(['dm', 'deny', fpr.fingerprint, source])
             self.result.append('Denied: {0}'.format(source))
 
         session.commit()
+
+    def action_break_the_archive(self, fingerprint, section, session):
+        name = 'Dave'
+        uid = fingerprint.uid
+        if uid is not None and uid.name is not None:
+            name = uid.name.split()[0]
+
+        self.result.append("DAK9000: I'm sorry, {0}. I'm afraid I can't do that.".format(name))