launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #23820
[Merge] lp:~cjwatson/launchpad/version-info-script into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/version-info-script into lp:launchpad.
Commit message:
Add a script to show version information.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/version-info-script/+merge/370529
This is useful in deployment scripts. I've found a few places where deployment code is calling something like "bzr revno /path/to/launchpad", which will break when we migrate to git. This script will allow replacing that with "/path/to/launchpad/bin/version-info -a revision"; that's a bit wordier, but not unreasonably so, and it can easily be extended if we find similar but slightly different requirements.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/version-info-script into lp:launchpad.
=== added file 'lib/lp/scripts/utilities/tests/test_versioninfo.py'
--- lib/lp/scripts/utilities/tests/test_versioninfo.py 1970-01-01 00:00:00 +0000
+++ lib/lp/scripts/utilities/tests/test_versioninfo.py 2019-07-23 22:39:29 +0000
@@ -0,0 +1,80 @@
+# Copyright 2019 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Test the script to show version information."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+
+from textwrap import dedent
+
+from fixtures import MockPatch
+from testtools.content import text_content
+
+from lp.app import versioninfo
+from lp.scripts.utilities.versioninfo import main as versioninfo_main
+from lp.services.utils import CapturedOutput
+from lp.testing import TestCase
+
+
+class TestVersionInfo(TestCase):
+
+ def runScript(self, args, expect_exit=False):
+ try:
+ with MockPatch('sys.argv', ['version-info'] + args):
+ with CapturedOutput() as captured:
+ versioninfo_main()
+ except SystemExit:
+ exited = True
+ else:
+ exited = False
+ stdout = captured.stdout.getvalue()
+ stderr = captured.stderr.getvalue()
+ self.addDetail('stdout', text_content(stdout))
+ self.addDetail('stderr', text_content(stderr))
+ if expect_exit:
+ if not exited:
+ raise AssertionError('Script unexpectedly exited successfully')
+ else:
+ if exited:
+ raise AssertionError(
+ 'Script unexpectedly exited unsuccessfully')
+ self.assertEqual('', stderr)
+ return stdout
+
+ def test_attribute_revision(self):
+ self.assertEqual(
+ versioninfo.revision + '\n',
+ self.runScript(['--attribute', 'revision']))
+
+ def test_attribute_display_revision(self):
+ self.assertEqual(
+ versioninfo.display_revision + '\n',
+ self.runScript(['--attribute', 'display_revision']))
+
+ def test_attribute_date(self):
+ self.assertEqual(
+ versioninfo.date + '\n',
+ self.runScript(['--attribute', 'date']))
+
+ def test_attribute_branch_nick(self):
+ self.assertEqual(
+ versioninfo.branch_nick + '\n',
+ self.runScript(['--attribute', 'branch_nick']))
+
+ def test_attribute_nonsense(self):
+ self.runScript(['--attribute', 'nonsense'], expect_exit=True)
+
+ def test_all_attributes(self):
+ expected_output = dedent('''\
+ Revision: {revision}
+ Display revision: {display_revision}
+ Date: {date}
+ Branch nick: {branch_nick}
+ ''').format(
+ revision=versioninfo.revision,
+ display_revision=versioninfo.display_revision,
+ date=versioninfo.date,
+ branch_nick=versioninfo.branch_nick)
+ self.assertEqual(expected_output, self.runScript([]))
=== added file 'lib/lp/scripts/utilities/versioninfo.py'
--- lib/lp/scripts/utilities/versioninfo.py 1970-01-01 00:00:00 +0000
+++ lib/lp/scripts/utilities/versioninfo.py 2019-07-23 22:39:29 +0000
@@ -0,0 +1,35 @@
+# Copyright 2019 Canonical Ltd. This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Script to show version information.
+
+This is useful in deployment scripts.
+"""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = ['main']
+
+import argparse
+
+from lp.app import versioninfo
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description=__doc__,
+ formatter_class=argparse.RawDescriptionHelpFormatter)
+ parser.add_argument(
+ '--attribute',
+ choices=['revision', 'display_revision', 'date', 'branch_nick'],
+ help='Display a single version information attribute.')
+ args = parser.parse_args()
+
+ if args.attribute:
+ print(getattr(versioninfo, args.attribute))
+ else:
+ print('Revision:', versioninfo.revision)
+ print('Display revision:', versioninfo.display_revision)
+ print('Date:', versioninfo.date)
+ print("Branch nick:", versioninfo.branch_nick)
=== modified file 'setup.py'
--- setup.py 2019-06-18 16:52:56 +0000
+++ setup.py 2019-07-23 22:39:29 +0000
@@ -309,6 +309,7 @@
'test = lp.scripts.utilities.test:main',
'tracereport = zc.zservertracelog.tracereport:main',
'twistd = twisted.scripts.twistd:run',
+ 'version-info = lp.scripts.utilities.versioninfo:main',
'watch_jsbuild = lp.scripts.utilities.js.watchjsbuild:main',
'with-xvfb = lp.scripts.utilities.withxvfb:main',
]
Follow ups