[Pkg-bazaar-commits] ./bzr-builddeb/trunk.old r251: Add a mark-uploaded command that sets the relevant tag.
James Westby
jw+debian at jameswestby.net
Wed Dec 10 08:32:54 UTC 2008
------------------------------------------------------------
revno: 251
committer: James Westby <jw+debian at jameswestby.net>
branch nick: 2.0
timestamp: Wed 2008-08-27 12:57:30 +0100
message:
Add a mark-uploaded command that sets the relevant tag.
added:
tests/blackbox/test_mark_uploaded.py
modified:
TODO
__init__.py
tests/blackbox/__init__.py
tests/test_util.py
util.py
-------------- next part --------------
=== modified file 'TODO'
--- a/TODO 2008-08-26 17:41:31 +0000
+++ b/TODO 2008-08-27 11:57:30 +0000
@@ -24,4 +24,5 @@
somewhere else so that the build doesn't fail.
- Falling back to ../tarballs if .. doesn't have what we need.
- Moving a source result.
+ - .changes files for packages with an epoch.
=== modified file '__init__.py'
--- a/__init__.py 2008-08-26 17:41:31 +0000
+++ b/__init__.py 2008-08-27 11:57:30 +0000
@@ -48,8 +48,13 @@
from bzrlib.plugins.builddeb.errors import (StopBuild,
)
from bzrlib.plugins.builddeb.hooks import run_hook
+from bzrlib.plugins.builddeb.import_dsc import DistributionBranch
from bzrlib.plugins.builddeb.properties import BuildProperties
-from bzrlib.plugins.builddeb.util import goto_branch, find_changelog, tarball_name
+from bzrlib.plugins.builddeb.util import (goto_branch,
+ find_changelog,
+ tarball_name,
+ lookup_distribution,
+ )
from bzrlib.plugins.builddeb.version import version_info
@@ -615,6 +620,57 @@
register_command(cmd_bd_do)
+class cmd_mark_uploaded(Command):
+ """Mark that this branch has been uploaded, prior to pushing it.
+
+ When a package has been uploaded we want to mark the revision
+ that it was uploaded in. This command automates doing that
+ by marking the current tip revision with the version indicated
+ in debian/changelog.
+ """
+ no_user_conf = Option('no-user-config', help="Stop builddeb from reading the user's "
+ +"config file. Used mainly for tests")
+ force = Option('force', help="Mark the upload even if it is already "
+ "marked.")
+
+ takes_options = [merge_opt, no_user_conf, force]
+
+ def run(self, merge=False, no_user_config=False, force=None):
+ t = WorkingTree.open_containing('.')[0]
+ t.lock_write()
+ try:
+ if t.changes_from(t.basis_tree()).has_changed():
+ raise BzrCommandError("There are uncommitted changes in the "
+ "working tree. You must commit before using this command")
+ if no_user_config:
+ config_files = [(local_conf, True), (default_conf, False)]
+ else:
+ config_files = [(local_conf, True), (global_conf, True),
+ (default_conf, False)]
+ config = DebBuildConfig(config_files)
+ if not merge:
+ merge = config.merge
+ (changelog, larstiq) = find_changelog(t, False)
+ distributions = changelog.distributions.strip()
+ target_dist = distributions.split()[0]
+ distribution_name = lookup_distribution(target_dist)
+ if distribution_name is None:
+ raise BzrCommandError("Unknown target distribution: %s" \
+ % target_dist)
+ db = DistributionBranch(distribution_name, t.branch, None)
+ if db.has_version(changelog.version):
+ if not force:
+ raise BzrCommandError("This version has already been "
+ "marked uploaded. Use --force to force marking "
+ "this new version.")
+ db.tag_version(changelog.version)
+ finally:
+ t.unlock()
+
+
+register_command(cmd_mark_uploaded)
+
+
def test_suite():
from unittest import TestSuite
from bzrlib.plugins.builddeb import tests
=== modified file 'tests/blackbox/__init__.py'
--- a/tests/blackbox/__init__.py 2007-10-29 18:00:52 +0000
+++ b/tests/blackbox/__init__.py 2008-08-27 11:57:30 +0000
@@ -26,6 +26,7 @@
'test_builddeb',
'test_do',
'test_import_dsc',
+ 'test_mark_uploaded',
'test_merge_upstream',
]
loader = TestUtil.TestLoader()
=== added file 'tests/blackbox/test_mark_uploaded.py'
--- a/tests/blackbox/test_mark_uploaded.py 1970-01-01 00:00:00 +0000
+++ b/tests/blackbox/test_mark_uploaded.py 2008-08-27 11:57:30 +0000
@@ -0,0 +1,107 @@
+# test_mark_uploaded.py -- Blackbox tests for mark-uploaded.
+# Copyright (C) 2007 James Westby <jw+debian at jameswestby.net>
+#
+# This file is part of bzr-builddeb.
+#
+# bzr-builddeb is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# bzr-builddeb is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with bzr-builddeb; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+from debian_bundle.changelog import Changelog, Version
+
+from bzrlib.plugins.builddeb.tests import BuilddebTestCase
+
+
+class TestMarkUploaded(BuilddebTestCase):
+
+ def make_unuploaded(self):
+ self.wt = self.make_branch_and_tree('.')
+ self.build_tree(['debian/'])
+ cl = Changelog()
+ v = Version("0.1-1")
+ cl.new_block(package='package',
+ version=Version('0.1-1'),
+ distributions='unstable',
+ urgency='low',
+ author='James Westby <jw+debian at jameswestby.net>',
+ date='Thu, 3 Aug 2006 19:16:22 +0100',
+ )
+ cl.add_change('');
+ cl.add_change(' * Initial packaging.');
+ cl.add_change('');
+ f = open('debian/changelog', 'wb')
+ try:
+ cl.write_to_open_file(f)
+ finally:
+ f.close()
+ self.wt.add(["debian/", "debian/changelog"])
+ self.wt.commit("one")
+
+ def test_mark_uploaded_available(self):
+ self.run_bzr('mark-uploaded --help')
+
+ def test_mark_uploaded_changes(self):
+ self.make_unuploaded()
+ self.build_tree(['foo'])
+ self.wt.add(['foo'])
+ self.run_bzr_error(["There are uncommitted changes"],
+ "mark-uploaded")
+
+ def test_mark_uploaded_unkown_dist(self):
+ self.make_unuploaded()
+ cl = Changelog()
+ v = Version("0.1-1")
+ cl.new_block(package='package',
+ version=Version('0.1-1'),
+ distributions='UNRELEASED',
+ urgency='low',
+ author='James Westby <jw+debian at jameswestby.net>',
+ date='Thu, 3 Aug 2006 19:16:22 +0100',
+ )
+ cl.add_change('');
+ cl.add_change(' * Initial packaging.');
+ cl.add_change('');
+ f = open('debian/changelog', 'wb')
+ try:
+ cl.write_to_open_file(f)
+ finally:
+ f.close()
+ self.wt.commit("two")
+ self.run_bzr_error(["Unknown target distribution: UNRELEASED"],
+ "mark-uploaded")
+
+ def test_mark_uploaded_already(self):
+ self.make_unuploaded()
+ self.run_bzr("mark-uploaded")
+ self.build_tree(["foo"])
+ self.wt.add(["foo"])
+ self.wt.commit("two")
+ self.run_bzr_error(["This version has already been marked uploaded"],
+ "mark-uploaded")
+
+ def test_mark_uploaded(self):
+ self.make_unuploaded()
+ self.run_bzr("mark-uploaded")
+ tagged_revision = self.wt.branch.tags.lookup_tag('debian-0.1-1')
+ self.assertEqual(tagged_revision, self.wt.branch.last_revision())
+
+ def test_mark_uploaded_force(self):
+ self.make_unuploaded()
+ self.run_bzr("mark-uploaded")
+ self.build_tree(["foo"])
+ self.wt.add(["foo"])
+ self.wt.commit("two")
+ self.run_bzr("mark-uploaded --force")
+ tagged_revision = self.wt.branch.tags.lookup_tag('debian-0.1-1')
+ self.assertEqual(tagged_revision, self.wt.branch.last_revision())
=== modified file 'tests/test_util.py'
--- a/tests/test_util.py 2008-07-11 21:45:33 +0000
+++ b/tests/test_util.py 2008-08-27 11:57:30 +0000
@@ -27,6 +27,7 @@
find_changelog,
recursive_copy,
get_snapshot_revision,
+ lookup_distribution,
)
from bzrlib.tests import (TestCaseWithTransport,
@@ -173,4 +174,33 @@
def test_non_numeric_snapshot(self):
self.assertEquals(None, get_snapshot_revision("0.4.4~bzra"))
+
+class LookupDistributionTests(TestCase):
+
+ def lookup_ubuntu(self, target):
+ self.assertEqual(lookup_distribution(target), 'ubuntu')
+
+ def lookup_debian(self, target):
+ self.assertEqual(lookup_distribution(target), 'debian')
+
+ def lookup_other(self, target):
+ self.assertEqual(lookup_distribution(target), None)
+
+ def test_lookup_ubuntu(self):
+ self.lookup_ubuntu('intrepid')
+ self.lookup_ubuntu('hardy-proposed')
+ self.lookup_ubuntu('gutsy-updates')
+ self.lookup_ubuntu('feisty-security')
+ self.lookup_ubuntu('dapper-backports')
+
+ def test_lookup_debian(self):
+ self.lookup_debian('unstable')
+ self.lookup_debian('stable-security')
+ self.lookup_debian('testing-proposed-updates')
+ self.lookup_debian('etch-backports')
+
+ def test_lookup_other(self):
+ self.lookup_other('not-a-target')
+
+
# vim: ts=2 sts=2 sw=2
=== modified file 'util.py'
--- a/util.py 2008-03-05 17:00:51 +0000
+++ b/util.py 2008-08-27 11:57:30 +0000
@@ -95,4 +95,21 @@
return None
return match.groups()[0]
+
+def lookup_distribution(target_dist):
+ debian_releases = ('woody', 'sarge', 'etch', 'lenny', 'stable',
+ 'testing', 'unstable', 'experimental', 'frozen')
+ debian_targets = ('', '-security', '-proposed-updates', '-backports')
+ ubuntu_releases = ('warty', 'hoary', 'breezy', 'dapper', 'edgy',
+ 'feisty', 'gutsy', 'hardy', 'intrepid')
+ ubuntu_targets = ('', '-proposed', '-updates', '-security', '-backports')
+ all_debian = [r + t for r in debian_releases for t in debian_targets]
+ all_ubuntu = [r + t for r in ubuntu_releases for t in ubuntu_targets]
+ if target_dist in all_debian:
+ return "debian"
+ if target_dist in all_ubuntu:
+ return "ubuntu"
+ return None
+
+
# vim: ts=2 sts=2 sw=2
More information about the Pkg-bazaar-commits
mailing list