def __cmp__(self, other): result = super(PackageLinkedBranch, self).__cmp__(other) if result != 0: return result # The versions are reversed as we want the greater Version to sort # before the lesser one. Hence self in the other tuple, and other in # the self tuple. Next compare the distribution name. my_parts = (self.suite_sourcepackage.distribution.name, Version(other.suite_sourcepackage.distroseries.version), self.suite_sourcepackage.sourcepackagename.name, self.suite_sourcepackage.pocket) other_parts = (other.suite_sourcepackage.distribution.name, Version(self.suite_sourcepackage.distroseries.version), other.suite_sourcepackage.sourcepackagename.name, other.suite_sourcepackage.pocket) return cmp(my_parts, other_parts)
def _validate(self, version): """See `UniqueField`.""" super(DistroSeriesVersionField, self)._validate(version) if not sane_version(version): raise LaunchpadValidationError("%s is not a valid version" % version) # Avoid circular import hell. from lp.archivepublisher.debversion import Version, VersionError try: # XXX sinzui 2009-07-25 bug=404613: DistributionMirror and buildd # have stricter version rules than the schema. The version must # be a debversion. Version(version) except VersionError as error: raise LaunchpadValidationError("'%s': %s" % (version, error))
def getCDImageMirroredFlavoursBySeries(self): """Return a list of _FlavoursByDistroSeries objects ordered descending by version. """ all_series = {} for cdimage in self.context.cdimage_series: series, flavour = cdimage.distroseries, cdimage.flavour flavours_by_series = all_series.get(series) if flavours_by_series is None: flavours_by_series = _FlavoursByDistroSeries(series, []) all_series[series] = flavours_by_series flavours_by_series.flavours.append(flavour) flavours_by_series = all_series.values() return sorted(flavours_by_series, reverse=True, key=lambda item: Version(item.distroseries.version))
def parse_changelog(changelines): state = 0 firstline = "" stanza = [] rets = [] for line in changelines: #print line[:-1] if state == 0: if (line.startswith(" ") or line.startswith("\t") or not line.rstrip()): #print "State0 skip" continue try: (source, version, urgency) = parse_first_line(line.strip()) Version(version) except: stanza.append(line) #print "state0 Exception skip" continue firstline = line.strip() stanza = [line, '\n'] state = 1 continue if state == 1: stanza.append(line) stanza.append('\n') if line.startswith(" --") and "@" in line: #print "state1 accept" # Last line of stanza rets.append( parse_changelog_stanza(firstline, stanza, line.strip()[3:])) state = 0 # leftovers with no close line if state == 1: rets[-1]["changes"] += firstline if len(rets): rets[-1]["changes"] += "".join(stanza).strip("\n") return rets
def process(self, packageupload, libraryfilealias): if packageupload.package_name is None: self.setComponents(libraryfilealias.filename) else: self.package_name = packageupload.package_name # Ignore translations not with main distribution purposes and not in # redirected PPAs. distroseries = None if packageupload.archive.purpose in MAIN_ARCHIVE_PURPOSES: distroseries = packageupload.distroseries elif packageupload.archive.reference in REDIRECTED_PPAS: redirect = REDIRECTED_PPAS[packageupload.archive.reference] if packageupload.distroseries.name in redirect: distro_name, distroseries_name = redirect[ packageupload.distroseries.name] distro = getUtility(IDistributionSet).getByName(distro_name) distroseries = distro[distroseries_name] if distroseries is None: if self.logger is not None: self.logger.debug( "Skipping translations since its purpose is not " "in MAIN_ARCHIVE_PURPOSES and the archive is not " "whitelisted.") return # If the distroseries is 11.10 (oneiric) or later, the valid names # check is not required. (See bug 788685.) do_names_check = Version(distroseries.version) < Version('11.10') latest_publication = self._findSourcePublication(packageupload) component_name = latest_publication.component.name spr = latest_publication.sourcepackagerelease valid_pockets = (PackagePublishingPocket.RELEASE, PackagePublishingPocket.SECURITY, PackagePublishingPocket.UPDATES, PackagePublishingPocket.PROPOSED) valid_components = ('main', 'restricted') if (packageupload.pocket not in valid_pockets or (do_names_check and component_name not in valid_components)): # XXX: CarlosPerelloMarin 2006-02-16 bug=31665: # This should be implemented using a more general rule to accept # different policies depending on the distribution. # Ubuntu's MOTU told us that they are not able to handle # translations like we do in main. We are going to import only # packages in main. return if distroseries != packageupload.distroseries: # Make sure that the target distroseries has a matching # Packaging record, since we want to make sure that exists # before importing translations so that message sharing works. sourcepackage = distroseries.getSourcePackage(spr.name) if sourcepackage is not None and sourcepackage.packaging is None: original_sourcepackage = ( packageupload.distroseries.getSourcePackage(spr.name)) if original_sourcepackage is not None: original_packaging = original_sourcepackage.packaging if original_packaging is not None: sourcepackage.setPackaging( original_packaging.productseries, original_packaging.owner) blamee = (packageupload.findPersonToNotify() or latest_publication.creator or getUtility(ILaunchpadCelebrities).rosetta_experts) getUtility(IPackageTranslationsUploadJobSource).create( distroseries, libraryfilealias, spr.sourcepackagename, blamee)
def testAcceptsNumber(self): """Version should accept a number.""" self.assertEqual(str(Version(1.2)), "1.2")
def testAcceptsInteger(self): """Version should accept an integer.""" self.assertEqual(str(Version(1)), "1")
def testReturnString(self): """Version should convert to a string.""" self.assertEqual(str(Version("1.0")), "1.0")
def testAcceptsString(self): """Version should accept a string input.""" Version("1.0")
def notestNullRevisionIsZero(self): """Version should treat an omitted revision as being equal to zero. """ self.assertEqual(Version("1.0"), Version("1.0-0")) self.assertTrue(Version("1.0") == Version("1.0-0"))
def testComparisons(self): """Sample Version comparisons should pass.""" for x, y in self.COMPARISONS: self.failUnless(Version(x) < Version(y))
def testComparisons(self): """Sample Version comparisons should pass.""" for x, y in self.COMPARISONS: self.assertTrue(Version(x) < Version(y))
def testValues(self): """Version should give same input as output.""" for value in self.VALUES: result = str(Version(value)) self.assertEqual(value, result)
def testRevisionNotEmpty(self): """Version should not allow an empty revision.""" v = Version("1-") self.assertEqual("1-", v.upstream_version) self.assertIsNone(v.debian_version)
def summarized_source_series(self): mirrors = self.context.getSummarizedMirroredSourceSeries() return sorted(mirrors, reverse=True, key=lambda mirror: Version(mirror.distroseries.version))
def distroseries_sort_key(item): return Version(item.version)
def testNullEpochIsZero(self): """Version should treat an omitted epoch as a zero one.""" self.assertEqual(Version("1.0"), Version("0:1.0"))