]> git.donarmstrong.com Git - dak.git/blobdiff - daklib/policy.py
Use Package-List to look for NEW binaries.
[dak.git] / daklib / policy.py
index eef18a4f343f4bde8fe8f17bb1900d4b2d2893d0..aeed9a2c19cbfb679274520e3418a73f42dc3722 100644 (file)
@@ -17,7 +17,7 @@
 """module to process policy queue uploads"""
 
 from .config import Config
-from .dbconn import BinaryMetadata, Component, MetadataKey, Override, OverrideType, get_mapped_component
+from .dbconn import BinaryMetadata, Component, MetadataKey, Override, OverrideType, Suite, get_mapped_component
 from .fstransactions import FilesystemTransaction
 from .regexes import re_file_changes, re_file_safe
 import daklib.utils as utils
@@ -39,7 +39,7 @@ class UploadCopy(object):
     given by the C{directory} attribute.  The copy will be removed on leaving
     the with-block.
     """
-    def __init__(self, upload):
+    def __init__(self, upload, group=None):
         """initializer
 
         @type  upload: L{daklib.dbconn.PolicyQueueUpload}
@@ -48,8 +48,9 @@ class UploadCopy(object):
 
         self.directory = None
         self.upload = upload
+        self.group = group
 
-    def export(self, directory, mode=None, symlink=True):
+    def export(self, directory, mode=None, symlink=True, ignore_existing=False):
         """export a copy of the upload
 
         @type  directory: str
@@ -60,6 +61,9 @@ class UploadCopy(object):
 
         @type  symlink: bool
         @param symlink: use symlinks instead of copying the files
+
+        @type  ignore_existing: bool
+        @param ignore_existing: ignore already existing files
         """
         with FilesystemTransaction() as fs:
             source = self.upload.source
@@ -69,29 +73,42 @@ class UploadCopy(object):
                 for dsc_file in source.srcfiles:
                     f = dsc_file.poolfile
                     dst = os.path.join(directory, os.path.basename(f.filename))
-                    fs.copy(f.fullpath, dst, mode=mode, symlink=symlink)
+                    if not os.path.exists(dst) or not ignore_existing:
+                        fs.copy(f.fullpath, dst, mode=mode, symlink=symlink)
+
             for binary in self.upload.binaries:
                 f = binary.poolfile
                 dst = os.path.join(directory, os.path.basename(f.filename))
-                fs.copy(f.fullpath, dst, mode=mode, symlink=symlink)
+                if not os.path.exists(dst) or not ignore_existing:
+                    fs.copy(f.fullpath, dst, mode=mode, symlink=symlink)
 
             # copy byhand files
             for byhand in self.upload.byhand:
                 src = os.path.join(queue.path, byhand.filename)
                 dst = os.path.join(directory, byhand.filename)
-                fs.copy(src, dst, mode=mode, symlink=symlink)
+                if not os.path.exists(dst) or not ignore_existing:
+                    fs.copy(src, dst, mode=mode, symlink=symlink)
 
             # copy .changes
             src = os.path.join(queue.path, self.upload.changes.changesname)
             dst = os.path.join(directory, self.upload.changes.changesname)
-            fs.copy(src, dst, mode=mode, symlink=symlink)
+            if not os.path.exists(dst) or not ignore_existing:
+                fs.copy(src, dst, mode=mode, symlink=symlink)
 
     def __enter__(self):
         assert self.directory is None
 
+        mode = 0o0700
+        symlink = True
+        if self.group is not None:
+            mode = 0o2750
+            symlink = False
+
         cnf = Config()
-        self.directory = tempfile.mkdtemp(dir=cnf.get('Dir::TempPath'))
-        self.export(self.directory, symlink=True)
+        self.directory = utils.temp_dirname(parent=cnf.get('Dir::TempPath'),
+                                            mode=mode,
+                                            group=self.group)
+        self.export(self.directory, symlink=symlink)
         return self
 
     def __exit__(self, *args):
@@ -188,7 +205,7 @@ class PolicyQueueUploadHandler(object):
 
         fn = os.path.join(self.upload.policy_queue.path, 'COMMENTS', fn1)
         try:
-            fh = os.open(fn, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
+            fh = os.open(fn, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
             os.write(fh, 'NOTOK\n')
             os.write(fh, 'From: {0} <{1}>\n\n'.format(utils.whoami(), cnf['Dinstall::MyAdminAddress']))
             os.write(fh, reason)
@@ -247,7 +264,7 @@ class PolicyQueueUploadHandler(object):
             if section.find('/') != -1:
                 component = section.split('/', 1)[0]
             override = self._binary_override(binary, component)
-            if override is None:
+            if override is None and not any(o['package'] == binary.package and o['type'] == binary.binarytype for o in missing):
                 hint = hints_map.get((binary.binarytype, binary.package))
                 if hint is not None:
                     missing.append(hint)
@@ -262,13 +279,18 @@ class PolicyQueueUploadHandler(object):
                             ))
             components.add(component)
 
+        source = self.upload.source
         source_component = '(unknown)'
-        for component in ('main', 'contrib', 'non-free'):
+        for component, in self.session.query(Component.component_name).order_by(Component.ordering):
             if component in components:
                 source_component = component
                 break
+            else:
+                if source is not None:
+                    if self._source_override(component) is not None:
+                        source_component = component
+                        break
 
-        source = self.upload.source
         if source is not None:
             override = self._source_override(source_component)
             if override is None: