]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/command.py
Add by-hash support
[dak.git] / daklib / command.py
index 3fe47703765a0c8c13e87027172432a390cfdd4e..867f7e3692589a5c26d1f1bc059cb40d7a62298f 100644 (file)
@@ -35,15 +35,15 @@ class CommandError(Exception):
     pass
 
 class CommandFile(object):
-    def __init__(self, path, log=None):
+    def __init__(self, filename, data, log=None):
         if log is None:
             from daklib.daklog import Logger
             log = Logger()
         self.cc = []
         self.result = []
         self.log = log
-        self.path = path
-        self.filename = os.path.basename(path)
+        self.filename = filename
+        self.data = data
 
     def _check_replay(self, signed_file, session):
         """check for replays
@@ -130,8 +130,7 @@ class CommandFile(object):
         keyrings = session.query(Keyring).filter_by(active=True).order_by(Keyring.priority)
         keyring_files = [ k.keyring_name for k in keyrings ]
 
-        raw_contents = open(self.path, 'r').read()
-        signed_file = SignedFile(raw_contents, keyring_files)
+        signed_file = SignedFile(self.data, keyring_files)
         if not signed_file.valid:
             self.log.log(['invalid signature', self.filename])
             return False
@@ -159,6 +158,8 @@ class CommandFile(object):
             section = sections.section
             if 'Uploader' in section:
                 self.uploader = section['Uploader']
+            if 'Cc' in section:
+                self.cc.append(section['Cc'])
             # TODO: Verify first section has valid Archive field
             if 'Archive' not in section:
                 raise CommandError('No Archive field in first section.')
@@ -307,13 +308,13 @@ class CommandFile(object):
 
         self.log.log(['dm-migrate', 'from={0}'.format(fpr_hash_from), 'to={0}'.format(fpr_hash_to)])
 
-        count = 0
+        sources = []
         for entry in session.query(ACLPerSource).filter_by(acl=acl, fingerprint=fpr_from):
             self.log.log(['dm-migrate', 'from={0}'.format(fpr_hash_from), 'to={0}'.format(fpr_hash_to), 'source={0}'.format(entry.source)])
             entry.fingerprint = fpr_to
-            count += 1
+            sources.append(entry.source)
 
-        self.result.append('Migrated {0} to {1}.\n{2} acl entries changed.'.format(fpr_hash_from, fpr_hash_to, count))
+        self.result.append('Migrated {0} to {1}.\n{2} acl entries changed: {3}'.format(fpr_hash_from, fpr_hash_to, len(sources), ", ".join(sources)))
 
         session.commit()