+
+################################################################################
+
+# Determine what parts in a .changes are NEW
+
+def determine_new(changes, files, projectB, warn=1):
+ new = {}
+
+ # Build up a list of potentially new things
+ for file_entry in files.keys():
+ f = files[file_entry]
+ # Skip byhand elements
+ if f["type"] == "byhand":
+ continue
+ pkg = f["package"]
+ priority = f["priority"]
+ section = f["section"]
+ file_type = get_type(f)
+ component = f["component"]
+
+ if file_type == "dsc":
+ priority = "source"
+ if not new.has_key(pkg):
+ new[pkg] = {}
+ new[pkg]["priority"] = priority
+ new[pkg]["section"] = section
+ new[pkg]["type"] = file_type
+ new[pkg]["component"] = component
+ new[pkg]["files"] = []
+ else:
+ old_type = new[pkg]["type"]
+ if old_type != file_type:
+ # source gets trumped by deb or udeb
+ if old_type == "dsc":
+ new[pkg]["priority"] = priority
+ new[pkg]["section"] = section
+ new[pkg]["type"] = file_type
+ new[pkg]["component"] = component
+ new[pkg]["files"].append(file_entry)
+ if f.has_key("othercomponents"):
+ new[pkg]["othercomponents"] = f["othercomponents"]
+
+ for suite in changes["suite"].keys():
+ suite_id = database.get_suite_id(suite)
+ for pkg in new.keys():
+ component_id = database.get_component_id(new[pkg]["component"])
+ type_id = database.get_override_type_id(new[pkg]["type"])
+ q = projectB.query("SELECT package FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (pkg, suite_id, component_id, type_id))
+ ql = q.getresult()
+ if ql:
+ for file_entry in new[pkg]["files"]:
+ if files[file_entry].has_key("new"):
+ del files[file_entry]["new"]
+ del new[pkg]
+
+ if warn:
+ if changes["suite"].has_key("stable"):
+ print "WARNING: overrides will be added for stable!"
+ if changes["suite"].has_key("oldstable"):
+ print "WARNING: overrides will be added for OLDstable!"
+ for pkg in new.keys():
+ if new[pkg].has_key("othercomponents"):
+ print "WARNING: %s already present in %s distribution." % (pkg, new[pkg]["othercomponents"])
+
+ return new
+
+################################################################################
+
+def get_type(f):
+ # Determine the type
+ if f.has_key("dbtype"):
+ file_type = f["dbtype"]
+ elif f["type"] in [ "orig.tar.gz", "orig.tar.bz2", "tar.gz", "tar.bz2", "diff.gz", "diff.bz2", "dsc" ]:
+ file_type = "dsc"
+ else:
+ utils.fubar("invalid type (%s) for new. Dazed, confused and sure as heck not continuing." % (file_type))
+
+ # Validate the override type
+ type_id = database.get_override_type_id(file_type)
+ if type_id == -1:
+ utils.fubar("invalid type (%s) for new. Say wha?" % (file_type))
+
+ return file_type
+
+################################################################################
+
+# check if section/priority values are valid
+
+def check_valid(new):
+ for pkg in new.keys():
+ section = new[pkg]["section"]
+ priority = new[pkg]["priority"]
+ file_type = new[pkg]["type"]
+ new[pkg]["section id"] = database.get_section_id(section)
+ new[pkg]["priority id"] = database.get_priority_id(new[pkg]["priority"])
+ # Sanity checks
+ di = section.find("debian-installer") != -1
+ if (di and file_type != "udeb") or (not di and file_type == "udeb"):
+ new[pkg]["section id"] = -1
+ if (priority == "source" and file_type != "dsc") or \
+ (priority != "source" and file_type == "dsc"):
+ new[pkg]["priority id"] = -1
+
+