]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/queue.py
daklib/contents.py: update for multi-archive changes
[dak.git] / daklib / queue.py
old mode 100755 (executable)
new mode 100644 (file)
index e2ab846..5202fa0
@@ -233,47 +233,46 @@ def determine_new(filename, changes, files, warn=1, session = None, dsc = None,
 
 ################################################################################
 
-def check_valid(new, session = None):
-    """
-    Check if section and priority for NEW packages exist in database.
+def check_valid(overrides, session):
+    """Check if section and priority for new overrides exist in database.
+
     Additionally does sanity checks:
       - debian-installer packages have to be udeb (or source)
-      - non debian-installer packages can not be udeb
-      - source priority can only be assigned to dsc file types
-
-    @type new: dict
-    @param new: Dict of new packages with their section, priority and type.
-
-    """
-    for pkg in new.keys():
-        section_name = new[pkg]["section"]
-        priority_name = new[pkg]["priority"]
-        file_type = new[pkg]["type"]
-
-        section = get_section(section_name, session)
-        if section is None:
-            new[pkg]["section id"] = -1
-        else:
-            new[pkg]["section id"] = section.section_id
+      - non debian-installer packages cannot be udeb
 
-        priority = get_priority(priority_name, session)
-        if priority is None:
-            new[pkg]["priority id"] = -1
-        else:
-            new[pkg]["priority id"] = priority.priority_id
+    @type  overrides: list of dict
+    @param overrides: list of overrides to check. The overrides need
+                      to be given in form of a dict with the following keys:
 
-        # Sanity checks
-        di = section_name.find("debian-installer") != -1
+                      - package: package name
+                      - priority
+                      - section
+                      - component
+                      - type: type of requested override ('dsc', 'deb' or 'udeb')
 
-        # If d-i, we must be udeb and vice-versa
-        if     (di and file_type not in ("udeb", "dsc")) or \
-           (not di and file_type == "udeb"):
-            new[pkg]["section id"] = -1
+                      All values are strings.
 
-        # If dsc we need to be source and vice-versa
-        if (priority == "source" and file_type != "dsc") or \
-           (priority != "source" and file_type == "dsc"):
-            new[pkg]["priority id"] = -1
+    @rtype:  bool
+    @return: C{True} if all overrides are valid, C{False} if there is any
+             invalid override.
+    """
+    all_valid = True
+    for o in overrides:
+        o['valid'] = True
+        if session.query(Priority).filter_by(priority=o['priority']).first() is None:
+            o['valid'] = False
+        if session.query(Section).filter_by(section=o['section']).first() is None:
+            o['valid'] = False
+        if get_mapped_component(o['component'], session) is None:
+            o['valid'] = False
+        if o['type'] not in ('dsc', 'deb', 'udeb'):
+            raise Exception('Unknown override type {0}'.format(o['type']))
+        if o['type'] == 'udeb' and o['section'] != 'debian-installer':
+            o['valid'] = False
+        if o['section'] == 'debian-installer' and o['type'] not in ('dsc', 'udeb'):
+            o['valid'] = False
+        all_valid = all_valid and o['valid']
+    return all_valid
 
 ###############################################################################
 
@@ -298,6 +297,7 @@ class TarTime(object):
 
 def prod_maintainer(notes, upload):
     cnf = Config()
+    changes = upload.changes
 
     # Here we prepare an editor and get them ready to prod...
     (fd, temp_filename) = utils.temp_filename()
@@ -332,7 +332,15 @@ def prod_maintainer(notes, upload):
     user_email_address = utils.whoami() + " <%s>" % (
         cnf["Dinstall::MyAdminAddress"])
 
-    Subst = upload.Subst
+    changed_by = changes.changedby or changes.maintainer
+    maintainer = changes.maintainer
+    maintainer_to = utils.mail_addresses_for_upload(maintainer, changed_by, changes.fingerprint)
+
+    Subst = {
+        '__SOURCE__': upload.changes.source,
+        '__CHANGES_FILENAME__': upload.changes.changesname,
+        '__MAINTAINER_TO__': ", ".join(maintainer_to),
+        }
 
     Subst["__FROM_ADDRESS__"] = user_email_address
     Subst["__PROD_MESSAGE__"] = prod_message
@@ -376,8 +384,8 @@ def edit_note(note, upload, session, trainee=False):
         sys.exit(0)
 
     comment = NewComment()
-    comment.package = upload.pkg.changes["source"]
-    comment.version = upload.pkg.changes["version"]
+    comment.package = upload.changes.source
+    comment.version = upload.changes.version
     comment.comment = newnote
     comment.author  = utils.whoami()
     comment.trainee = trainee
@@ -655,7 +663,7 @@ class Upload(object):
         Cnf = Config()
 
         # Handle suite mappings
-        for m in Cnf.ValueList("SuiteMappings"):
+        for m in Cnf.value_list("SuiteMappings"):
             args = m.split()
             mtype = args[0]
             if mtype == "map" or mtype == "silent-map":
@@ -713,47 +721,39 @@ class Upload(object):
         # Extract package control information
         deb_file = utils.open_file(f)
         try:
-            control = apt_pkg.ParseSection(apt_inst.debExtractControl(deb_file))
+            control = apt_pkg.TagSection(utils.deb_extract_control(deb_file))
         except:
-            self.rejects.append("%s: debExtractControl() raised %s." % (f, sys.exc_info()[0]))
+            self.rejects.append("%s: deb_extract_control() raised %s." % (f, sys.exc_info()[0]))
             deb_file.close()
             # Can't continue, none of the checks on control would work.
             return
 
-        # Check for mandantory "Description:"
-        deb_file.seek(0)
-        try:
-            apt_pkg.ParseSection(apt_inst.debExtractControl(deb_file))["Description"] + '\n'
-        except:
-            self.rejects.append("%s: Missing Description in binary package" % (f))
-            return
-
         deb_file.close()
 
         # Check for mandatory fields
-        for field in [ "Package", "Architecture", "Version" ]:
-            if control.Find(field) == None:
+        for field in [ "Package", "Architecture", "Version", "Description" ]:
+            if field not in control:
                 # Can't continue
                 self.rejects.append("%s: No %s field in control." % (f, field))
                 return
 
         # Ensure the package name matches the one give in the .changes
-        if not self.pkg.changes["binary"].has_key(control.Find("Package", "")):
-            self.rejects.append("%s: control file lists name as `%s', which isn't in changes file." % (f, control.Find("Package", "")))
+        if not self.pkg.changes["binary"].has_key(control.find("Package", "")):
+            self.rejects.append("%s: control file lists name as `%s', which isn't in changes file." % (f, control.find("Package", "")))
 
         # Validate the package field
-        package = control.Find("Package")
+        package = control["Package"]
         if not re_valid_pkg_name.match(package):
             self.rejects.append("%s: invalid package name '%s'." % (f, package))
 
         # Validate the version field
-        version = control.Find("Version")
+        version = control["Version"]
         if not re_valid_version.match(version):
             self.rejects.append("%s: invalid version number '%s'." % (f, version))
 
         # Ensure the architecture of the .deb is one we know about.
         default_suite = cnf.get("Dinstall::DefaultSuite", "unstable")
-        architecture = control.Find("Architecture")
+        architecture = control["Architecture"]
         upload_suite = self.pkg.changes["distribution"].keys()[0]
 
         if      architecture not in [a.arch_string for a in get_suite_architectures(default_suite, session = session)] \
@@ -766,13 +766,13 @@ class Upload(object):
             self.rejects.append("%s: control file lists arch as `%s', which isn't in changes file." % (f, architecture))
 
         # Sanity-check the Depends field
-        depends = control.Find("Depends")
+        depends = control.find("Depends")
         if depends == '':
             self.rejects.append("%s: Depends field is empty." % (f))
 
         # Sanity-check the Provides field
-        provides = control.Find("Provides")
-        if provides:
+        provides = control.find("Provides")
+        if provides is not None:
             provide = re_spacestrip.sub('', provides)
             if provide == '':
                 self.rejects.append("%s: Provides field is empty." % (f))
@@ -783,8 +783,8 @@ class Upload(object):
 
         # If there is a Built-Using field, we need to check we can find the
         # exact source version
-        built_using = control.Find("Built-Using")
-        if built_using:
+        built_using = control.find("Built-Using")
+        if built_using is not None:
             try:
                 entry["built-using"] = []
                 for dep in apt_pkg.parse_depends(built_using):
@@ -806,19 +806,19 @@ class Upload(object):
 
 
         # Check the section & priority match those given in the .changes (non-fatal)
-        if     control.Find("Section") and entry["section"] != "" \
-           and entry["section"] != control.Find("Section"):
+        if control.find("Section") and entry["section"] != "" \
+           and entry["section"] != control.find("Section"):
             self.warnings.append("%s control file lists section as `%s', but changes file has `%s'." % \
-                                (f, control.Find("Section", ""), entry["section"]))
-        if control.Find("Priority") and entry["priority"] != "" \
-           and entry["priority"] != control.Find("Priority"):
+                                (f, control.find("Section", ""), entry["section"]))
+        if control.find("Priority") and entry["priority"] != "" \
+           and entry["priority"] != control.find("Priority"):
             self.warnings.append("%s control file lists priority as `%s', but changes file has `%s'." % \
-                                (f, control.Find("Priority", ""), entry["priority"]))
+                                (f, control.find("Priority", ""), entry["priority"]))
 
         entry["package"] = package
         entry["architecture"] = architecture
         entry["version"] = version
-        entry["maintainer"] = control.Find("Maintainer", "")
+        entry["maintainer"] = control.find("Maintainer", "")
 
         if f.endswith(".udeb"):
             self.pkg.files[f]["dbtype"] = "udeb"
@@ -827,7 +827,7 @@ class Upload(object):
         else:
             self.rejects.append("%s is neither a .deb or a .udeb." % (f))
 
-        entry["source"] = control.Find("Source", entry["package"])
+        entry["source"] = control.find("Source", entry["package"])
 
         # Get the source version
         source = entry["source"]
@@ -852,7 +852,7 @@ class Upload(object):
         if entry["package"] != file_package:
             self.rejects.append("%s: package part of filename (%s) does not match package name in the %s (%s)." % \
                                 (f, file_package, entry["dbtype"], entry["package"]))
-        epochless_version = re_no_epoch.sub('', control.Find("Version"))
+        epochless_version = re_no_epoch.sub('', control.find("Version"))
 
         #  version
         file_version = m.group(2)
@@ -962,7 +962,7 @@ class Upload(object):
             return
 
         # Handle component mappings
-        for m in cnf.ValueList("ComponentMappings"):
+        for m in cnf.value_list("ComponentMappings"):
             (source, dest) = m.split()
             if entry["component"] == source:
                 entry["original component"] = source
@@ -1116,7 +1116,7 @@ class Upload(object):
             if not has_source:
                 self.rejects.append("no source found and Architecture line in changes mention source.")
 
-            if (not has_binaries) and (not cnf.FindB("Dinstall::AllowSourceOnlyUploads")):
+            if (not has_binaries) and (not cnf.find_b("Dinstall::AllowSourceOnlyUploads")):
                 self.rejects.append("source only uploads are not supported.")
 
     ###########################################################################
@@ -1243,7 +1243,7 @@ class Upload(object):
             if field:
                 # Have apt try to parse them...
                 try:
-                    apt_pkg.ParseSrcDepends(field)
+                    apt_pkg.parse_src_depends(field)
                 except:
                     self.rejects.append("%s: invalid %s field (can not be parsed by apt)." % (dsc_filename, field_name.title()))
 
@@ -1330,7 +1330,7 @@ class Upload(object):
             self.rejects.append("'dpkg-source -x' failed for %s. (%s)" % (dsc_filename, str(e)))
             return
 
-        if not cnf.Find("Dir::BTSVersionTrack"):
+        if not cnf.find("Dir::BTSVersionTrack"):
             return
 
         # Get the upstream version
@@ -1614,7 +1614,7 @@ class Upload(object):
             if not self.pkg.changes.has_key("urgency"):
                 self.pkg.changes["urgency"] = cnf["Urgency::Default"]
             self.pkg.changes["urgency"] = self.pkg.changes["urgency"].lower()
-            if self.pkg.changes["urgency"] not in cnf.ValueList("Urgency::Valid"):
+            if self.pkg.changes["urgency"] not in cnf.value_list("Urgency::Valid"):
                 self.warnings.append("%s is not a valid urgency; it will be treated as %s by testing." % \
                                      (self.pkg.changes["urgency"], cnf["Urgency::Default"]))
                 self.pkg.changes["urgency"] = cnf["Urgency::Default"]
@@ -1888,7 +1888,7 @@ class Upload(object):
             # Will be None if nothing is in testing.
             current = get_source_in_suite(source, "testing", session)
             if current is not None:
-                compare = apt_pkg.VersionCompare(current.version, expected)
+                compare = apt_pkg.version_compare(current.version, expected)
 
             if current is None or compare < 0:
                 # This is still valid, the current version in testing is older than
@@ -2055,7 +2055,7 @@ distribution."""
 
                 del self.Subst["__ANNOUNCE_LIST_ADDRESS__"]
 
-        if cnf.FindB("Dinstall::CloseBugs") and cnf.has_key("Dinstall::BugServer"):
+        if cnf.find_b("Dinstall::CloseBugs") and cnf.has_key("Dinstall::BugServer"):
             summary = self.close_bugs(summary, action)
 
         del self.Subst["__SHORT_SUMMARY__"]
@@ -2219,7 +2219,7 @@ distribution."""
         self.announce(short_summary, 1)
 
         ## Helper stuff for DebBugs Version Tracking
-        if cnf.Find("Dir::BTSVersionTrack"):
+        if cnf.find("Dir::BTSVersionTrack"):
             if self.pkg.changes["architecture"].has_key("source"):
                 (fd, temp_filename) = utils.temp_filename(cnf["Dir::BTSVersionTrack"], prefix=".")
                 version_history = os.fdopen(fd, 'w')
@@ -2272,7 +2272,7 @@ distribution."""
         cnf = Config()
 
         # Abandon the check if override disparity checks have been disabled
-        if not cnf.FindB("Dinstall::OverrideDisparityCheck"):
+        if not cnf.find_b("Dinstall::OverrideDisparityCheck"):
             return
 
         summary = self.pkg.check_override()
@@ -2548,7 +2548,7 @@ distribution."""
         anysuite = [suite] + [ vc.reference.suite_name for vc in get_version_checks(suite, "Enhances") ]
         for (s, v) in sv_list:
             if s in [ x.lower() for x in anysuite ]:
-                if not anyversion or apt_pkg.VersionCompare(anyversion, v) <= 0:
+                if not anyversion or apt_pkg.version_compare(anyversion, v) <= 0:
                     anyversion = v
 
         return anyversion
@@ -2589,7 +2589,7 @@ distribution."""
                 must_be_newer_than.append(target_suite)
 
             for (suite, existent_version) in sv_list:
-                vercmp = apt_pkg.VersionCompare(new_version, existent_version)
+                vercmp = apt_pkg.version_compare(new_version, existent_version)
 
                 if suite in must_be_newer_than and sourceful and vercmp < 1:
                     self.rejects.append("%s: old version (%s) in %s >= new version (%s) targeted at %s." % (filename, existent_version, suite, new_version, target_suite))
@@ -2623,12 +2623,12 @@ distribution."""
                             # we could just stick with the "...old version..." REJECT
                             # for this, I think.
                             self.rejects.append("Won't propogate NEW packages.")
-                        elif apt_pkg.VersionCompare(new_version, add_version) < 0:
+                        elif apt_pkg.version_compare(new_version, add_version) < 0:
                             # propogation would be redundant. no need to reject though.
                             self.warnings.append("ignoring versionconflict: %s: old version (%s) in %s <= new version (%s) targeted at %s." % (filename, existent_version, suite, new_version, target_suite))
                             cansave = 1
-                        elif apt_pkg.VersionCompare(new_version, add_version) > 0 and \
-                             apt_pkg.VersionCompare(add_version, target_version) >= 0:
+                        elif apt_pkg.version_compare(new_version, add_version) > 0 and \
+                             apt_pkg.version_compare(add_version, target_version) >= 0:
                             # propogate!!
                             self.warnings.append("Propogating upload to %s" % (addsuite))
                             self.pkg.changes.setdefault("propdistribution", {})