+# Determine what parts in a .changes are NEW
+
+def determine_new(changes, files, projectB, warn=1):
+ """
+ Determine what parts in a C{changes} file are NEW.
+
+ @type changes: Upload.Pkg.changes dict
+ @param changes: Changes dictionary
+
+ @type files: Upload.Pkg.files dict
+ @param files: Files dictionary
+
+ @type projectB: pgobject
+ @param projectB: DB handle
+
+ @type warn: bool
+ @param warn: Warn if overrides are added for (old)stable
+
+ @rtype: dict
+ @return: dictionary of NEW components.
+
+ """
+ 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(file):
+ """
+ Get the file type of C{file}
+
+ @type file: dict
+ @param file: file entry
+
+ @rtype: string
+ @return: filetype
+
+ """
+ # Determine the type
+ if file.has_key("dbtype"):
+ file_type = file["dbtype"]
+ elif file["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
+
+################################################################################
+
+
+
+def check_valid(new):
+ """
+ Check if section and priority for NEW packages 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 = 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 not in ("udeb", "dsc")) 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
+