[Pkg-bazaar-commits] ./bzr-builddeb/trunk.old r273: Merge the revspec from the 2.0 branch.
James Westby
jw+debian at jameswestby.net
Wed Dec 10 08:33:05 UTC 2008
------------------------------------------------------------
revno: 273
committer: James Westby <jw+debian at jameswestby.net>
branch nick: trunk
timestamp: Wed 2008-09-03 13:07:07 +0100
message:
Merge the revspec from the 2.0 branch.
added:
revspec.py
tests/test_revspec.py
modified:
errors.py
tests/__init__.py
------------------------------------------------------------
revno: 266.1.4
committer: James Westby <jw+debian at jameswestby.net>
branch nick: 2.0
timestamp: Wed 2008-09-03 13:04:58 +0100
message:
Add a revisionspec that allows you to specify revisions by package versions.
"package:" allows you to specify a revision by passing a version number,
and optionally a distribution.
https://blueprints.launchpad.net/bzr-builddeb/+spec/package-revisionspec
added:
revspec.py
tests/test_revspec.py
modified:
errors.py
tests/__init__.py
-------------- next part --------------
=== modified file 'errors.py'
--- a/errors.py 2008-08-27 15:15:19 +0000
+++ b/errors.py 2008-09-03 12:04:58 +0000
@@ -100,4 +100,35 @@
self.version = str(version)
+class AmbiguousPackageSpecification(BzrError):
+ _fmt = ("You didn't specify a distribution with the package "
+ "specification, and tags exists that state that the "
+ "version that you specified has been uploaded to more "
+ "than one distribution. Please specify which version "
+ "you wish to refer to by by appending ':debian' or "
+ "':ubuntu' to the revision specifier: %(specifier)s")
+
+ def __init__(self, specifier):
+ self.specifier = specifier
+
+
+class UnknownVersion(BzrError):
+ _fmt = ("No tag exists in this branch indicating that version "
+ "'%(version)s' has been uploaded.")
+
+ def __init__(self, version):
+ self.version = version
+
+
+class UnknownDistribution(BzrError):
+ _fmt = "Unknown distribution: %(distribution)s."
+
+ def __init__(self, distribution):
+ self.distribution = distribution
+
+
+class VersionNotSpecified(BzrError):
+ _fmt = "You did not specify a package version."
+
+
# vim: ts=2 sts=2 sw=2
=== added file 'revspec.py'
--- a/revspec.py 1970-01-01 00:00:00 +0000
+++ b/revspec.py 2008-09-03 12:04:58 +0000
@@ -0,0 +1,69 @@
+
+from bzrlib.errors import NoSuchTag
+from bzrlib.revisionspec import RevisionSpec, RevisionInfo, SPEC_TYPES
+
+from bzrlib.plugins.builddeb.errors import (
+ AmbiguousPackageSpecification,
+ UnknownDistribution,
+ UnknownVersion,
+ VersionNotSpecified,
+ )
+from bzrlib.plugins.builddeb.util import lookup_distribution
+
+
+class RevisionSpec_package(RevisionSpec):
+ """Selects a revision based on the version of the package."""
+
+ help_txt = """Selects the revision corresponding to a version of a package.
+
+ Given a package version number this revision specifier will allow you
+ specify the revision corresponding to the upload of that version of
+ the package.
+ """
+ prefix = 'package:'
+
+ def _match_on(self, branch, revs):
+ loc = self.spec.find(':')
+ if loc == -1:
+ version_spec = self.spec
+ dist_spec = None
+ else:
+ version_spec = self.spec[:loc]
+ dist_spec = self.spec[loc+1:]
+
+ if version_spec == '':
+ raise VersionNotSpecified
+ else:
+ if dist_spec:
+ # We were told a distribution, so use that
+ dist_name = lookup_distribution(dist_spec)
+ if dist_name is None:
+ if dist_spec not in ("debian", "ubuntu"):
+ raise UnknownDistribution(dist_spec)
+ dist_name = dist_spec
+ tags_to_lookup = ("%s-%s" % (dist_name, version_spec),)
+ else:
+ # We weren't given a distribution, so try both and
+ # see if there is ambiguity.
+ tags_to_lookup = ("debian-%s" % version_spec,
+ "ubuntu-%s" % version_spec)
+
+ revision_id = None
+ for tag_name in tags_to_lookup:
+ tag_revid = None
+ try:
+ tag_revid = branch.tags.lookup_tag(tag_name)
+ except NoSuchTag:
+ pass
+ if tag_revid is not None:
+ if revision_id is not None:
+ raise AmbiguousPackageSpecification(self.prefix+self.spec)
+ revision_id = tag_revid
+
+ if revision_id is None:
+ raise UnknownVersion(version_spec)
+ return RevisionInfo.from_revision_id(branch,
+ revision_id, revs)
+
+SPEC_TYPES.append(RevisionSpec_package)
+
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2008-08-29 12:46:07 +0000
+++ b/tests/__init__.py 2008-09-03 12:07:07 +0000
@@ -123,6 +123,7 @@
'test_import_dsc',
'test_merge_upstream',
'test_repack_tarball_extra',
+ 'test_revspec',
'test_util',
]
suite.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i)
=== added file 'tests/test_revspec.py'
--- a/tests/test_revspec.py 1970-01-01 00:00:00 +0000
+++ b/tests/test_revspec.py 2008-09-03 12:04:58 +0000
@@ -0,0 +1,49 @@
+
+from bzrlib.tests.test_revisionspec import TestRevisionSpec
+
+from bzrlib.revisionspec import RevisionSpec
+
+from bzrlib.plugins.builddeb.errors import (
+ AmbiguousPackageSpecification,
+ UnknownDistribution,
+ UnknownVersion,
+ VersionNotSpecified,
+ )
+from bzrlib.plugins.builddeb.revspec import RevisionSpec_package
+
+
+class TestRevisionSpec_package(TestRevisionSpec):
+
+ def test_from_string_package(self):
+ spec = RevisionSpec.from_string('package:0.1-1')
+ self.assertIsInstance(spec, RevisionSpec_package)
+ self.assertEqual(spec.spec, '0.1-1')
+ spec = RevisionSpec.from_string('package:0.1-1:debian')
+ self.assertIsInstance(spec, RevisionSpec_package)
+ self.assertEqual(spec.spec, '0.1-1:debian')
+
+ def test_simple_package(self):
+ self.tree.branch.tags.set_tag('debian-0.1-1', 'r1')
+ self.assertInHistoryIs(1, 'r1', 'package:0.1-1')
+ self.assertInHistoryIs(1, 'r1', 'package:0.1-1:debian')
+
+ def test_ambiguous_package(self):
+ self.tree.branch.tags.set_tag('debian-0.1-1', 'r1')
+ self.tree.branch.tags.set_tag('ubuntu-0.1-1', 'r2')
+ self.assertRaises(AmbiguousPackageSpecification,
+ self.get_in_history, 'package:0.1-1')
+ self.assertInHistoryIs(1, 'r1', 'package:0.1-1:debian')
+ self.assertInHistoryIs(2, 'r2', 'package:0.1-1:ubuntu')
+
+ def test_unkown_distribution(self):
+ self.assertRaises(UnknownDistribution,
+ self.get_in_history, 'package:0.1-1:nonsense')
+
+ def test_unkown_version(self):
+ self.assertRaises(UnknownVersion,
+ self.get_in_history, 'package:0.1-1')
+
+ def test_missing_version(self):
+ self.assertRaises(VersionNotSpecified,
+ self.get_in_history, 'package:')
+
More information about the Pkg-bazaar-commits
mailing list