← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/remove-lp-query-distro into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/remove-lp-query-distro into lp:launchpad.

Commit message:
Remove lp-query-distro.py, now that cron.germinate no longer uses it.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/remove-lp-query-distro/+merge/224835

Remove lp-query-distro.py, now that cron.germinate no longer uses it.
-- 
https://code.launchpad.net/~cjwatson/launchpad/remove-lp-query-distro/+merge/224835
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/remove-lp-query-distro into lp:launchpad.
=== removed file 'lib/lp/soyuz/scripts/querydistro.py'
--- lib/lp/soyuz/scripts/querydistro.py	2012-06-29 08:40:05 +0000
+++ lib/lp/soyuz/scripts/querydistro.py	1970-01-01 00:00:00 +0000
@@ -1,147 +0,0 @@
-# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Distribution querying utility."""
-
-__metaclass__ = type
-
-__all__ = ['LpQueryDistro']
-
-from lp.registry.interfaces.series import SeriesStatus
-from lp.services.scripts.base import (
-    LaunchpadScript,
-    LaunchpadScriptFailure,
-    )
-from lp.soyuz.adapters.packagelocation import (
-    build_package_location,
-    PackageLocationError,
-    )
-
-
-class LpQueryDistro(LaunchpadScript):
-    """Main class for scripts/ftpmaster-tools/lp-query-distro.py."""
-
-    def __init__(self, *args, **kwargs):
-        """Initialize dynamic 'usage' message and LaunchpadScript parent.
-
-        Also initialize the list 'allowed_arguments'.
-        """
-        self.allowed_actions = ['supported']
-        self.usage = '%%prog <%s>' % ' | '.join(self.allowed_actions)
-        LaunchpadScript.__init__(self, *args, **kwargs)
-
-    def add_my_options(self):
-        """Add 'distribution' and 'suite' context options."""
-        self.parser.add_option(
-            '-d', '--distribution', dest='distribution_name',
-            default='ubuntu', help='Context distribution name.')
-        self.parser.add_option(
-            '-s', '--suite', dest='suite', default=None,
-            help='Context suite name.')
-
-    def main(self):
-        """Main procedure, basically a runAction wrapper.
-
-        Execute the given and allowed action using the default presenter
-        (see self.runAction for further information).
-        """
-        self.runAction()
-
-    def _buildLocation(self):
-        """Build a PackageLocation object
-
-        The location will correspond to the given 'distribution' and 'suite',
-        Any PackageLocationError occurring at this point will be masked into
-        LaunchpadScriptFailure.
-        """
-        try:
-            self.location = build_package_location(
-                distribution_name=self.options.distribution_name,
-                suite=self.options.suite)
-        except PackageLocationError as err:
-            raise LaunchpadScriptFailure(err)
-
-    def defaultPresenter(self, result):
-        """Default result presenter.
-
-        Directly prints result in the standard output (print).
-        """
-        print result
-
-    def runAction(self, presenter=None):
-        """Run a given initialized action (self.action_name).
-
-        It accepts an optional 'presenter' which will be used to
-        store/present the action result.
-
-        Ensure at least one argument was passed, known as 'action'.
-        Verify if the given 'action' is listed as an 'allowed_action'.
-        Raise LaunchpadScriptFailure if those requirements were not
-        accomplished.
-
-        It builds context 'location' object (see self._buildLocation).
-
-        It may raise LaunchpadScriptFailure is the 'action' is not properly
-        supported by the current code (missing corresponding property).
-        """
-        if presenter is None:
-            presenter = self.defaultPresenter
-
-        if len(self.args) != 1:
-            raise LaunchpadScriptFailure('<action> is required')
-
-        [self.action_name] = self.args
-
-        if self.action_name not in self.allowed_actions:
-            raise LaunchpadScriptFailure(
-                'Action "%s" is not supported' % self.action_name)
-
-        self._buildLocation()
-
-        try:
-            action_result = getattr(self, self.action_name)
-        except AttributeError:
-            raise AssertionError(
-                "No handler found for action '%s'" % self.action_name)
-
-        presenter(action_result)
-
-    def checkNoSuiteDefined(self):
-        """Raises LaunchpadScriptError if a suite location was passed.
-
-        It is re-used in action properties to avoid conflicting contexts,
-        i.e, passing an arbitrary 'suite' and asking for the CURRENT suite
-        in the context distribution.
-        """
-        if self.options.suite is not None:
-            raise LaunchpadScriptFailure(
-                "Action does not accept defined suite.")
-
-    @property
-    def supported(self):
-        """Return the names of the distroseries currently supported.
-
-        'supported' means not EXPERIMENTAL or OBSOLETE.
-
-        It is restricted for the context distribution.
-
-        It may raise `LaunchpadScriptFailure` if a suite was passed on the
-        command-line or if there is not supported distroseries for the
-        distribution given.
-
-        Return a space-separated list of distroseries names.
-        """
-        self.checkNoSuiteDefined()
-        supported_series = []
-        unsupported_status = (SeriesStatus.EXPERIMENTAL,
-                              SeriesStatus.OBSOLETE)
-        for distroseries in self.location.distribution:
-            if distroseries.status not in unsupported_status:
-                supported_series.append(distroseries.name)
-
-        if not supported_series:
-            raise LaunchpadScriptFailure(
-                'There is no supported distroseries for %s' %
-                self.location.distribution.name)
-
-        return " ".join(supported_series)

=== removed file 'lib/lp/soyuz/scripts/tests/test_lpquerydistro.py'
--- lib/lp/soyuz/scripts/tests/test_lpquerydistro.py	2012-06-20 01:19:03 +0000
+++ lib/lp/soyuz/scripts/tests/test_lpquerydistro.py	1970-01-01 00:00:00 +0000
@@ -1,212 +0,0 @@
-# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-__metaclass__ = type
-
-import operator
-import os
-import subprocess
-import sys
-import unittest
-
-from zope.component import getUtility
-
-from lp.registry.interfaces.distribution import IDistributionSet
-from lp.services.config import config
-from lp.services.scripts.base import LaunchpadScriptFailure
-from lp.soyuz.scripts.querydistro import LpQueryDistro
-from lp.testing.layers import (
-    LaunchpadLayer,
-    LaunchpadZopelessLayer,
-    )
-
-
-class TestLpQueryDistroScript(unittest.TestCase):
-    """Test the lp-query-distro.py script."""
-    layer = LaunchpadLayer
-
-    def runLpQueryDistro(self, extra_args=None):
-        """Run lp-query.distro.py, returning the result and output.
-
-        Returns a tuple of the process's return code, stdout output and
-        stderr output.
-        """
-        if extra_args is None:
-            extra_args = []
-        script = os.path.join(
-            config.root, "scripts", "ftpmaster-tools", "lp-query-distro.py")
-        args = [sys.executable, script]
-        args.extend(extra_args)
-        process = subprocess.Popen(
-            args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-        stdout, stderr = process.communicate()
-        return (process.returncode, stdout, stderr)
-
-    def testSimpleRun(self):
-        """Try a simple lp-query-distro.py run.
-
-        Check that:
-         * return code is ZERO,
-         * standard error is empty
-         * standard output contains only the 'supported distroseries' names
-        """
-        returncode, out, err = self.runLpQueryDistro(
-            extra_args=['supported'])
-
-        self.assertEqual(
-            0, returncode, "\nScript Failed:%s\nStdout:\n%s\nStderr\n%s\n"
-            % (returncode, out, err))
-        self.assertEqual(out.strip(), 'hoary warty')
-        self.assertEqual(err.strip(), '')
-
-    def testMissingAction(self):
-        """Making lp-query-distro.py to fail by not passing an action.
-
-        Check that:
-         * return code is ONE,
-         * standard output is empty
-         * standard error contains additional information about the failure.
-        """
-        returncode, out, err = self.runLpQueryDistro(
-            extra_args=[])
-
-        self.assertEqual(
-            1, returncode,
-            "\nScript didn't fail:%s\nStdout:\n%s\nStderr\n%s\n"
-            % (returncode, out, err))
-        self.assertEqual(out.strip(), '')
-        self.assertEqual(err.strip(), 'ERROR   <action> is required')
-
-    def testUnknownAction(self):
-        """Making lp-query-distro.py to fail by passing an unknown action.
-
-        Check if:
-         * return code is ONE,
-         * standard output is empty
-         * standard error contains the additional information about the
-           failure.
-        """
-        returncode, out, err = self.runLpQueryDistro(
-            extra_args=['nahhh'])
-
-        self.assertEqual(
-            1, returncode,
-            "\nScript didn't fail:%s\nStdout:\n%s\nStderr\n%s\n"
-            % (returncode, out, err))
-        self.assertEqual(out.strip(), '')
-        self.assertEqual(
-            err.strip(), 'ERROR   Action "nahhh" is not supported')
-
-    def testUnexpectedArgument(self):
-        """Making lp-query-distro.py to fail by passing unexpected action.
-
-        Check if:
-         * return code is ONE,
-         * standard output is empty
-         * standard error contains additional information about the failure.
-        """
-        returncode, out, err = self.runLpQueryDistro(
-            extra_args=['-s', 'warty', 'supported'])
-
-        self.assertEqual(
-            1, returncode,
-            "\nScript didn't fail:%s\nStdout:\n%s\nStderr\n%s\n"
-            % (returncode, out, err))
-        self.assertEqual(out.strip(), '')
-        self.assertEqual(
-            err.strip(), 'ERROR   Action does not accept defined suite.')
-
-
-class TestLpQueryDistro(unittest.TestCase):
-    """Test the LpQueryDistro class."""
-    layer = LaunchpadZopelessLayer
-
-    def setUp(self):
-        self.test_output = None
-        self.ubuntu = getUtility(IDistributionSet)['ubuntu']
-
-    def getLpQueryDistro(self, test_args=None):
-        """Return a built and LpQueryDistro object."""
-        lp_query_distro = LpQueryDistro(
-            name='testing-lpquerydistro', test_args=test_args)
-        return lp_query_distro
-
-    def presenter(self, *args):
-        """Test result presenter.
-
-        It stores results in self.test_output for later test-inspection.
-        """
-        self.test_output = '%s' % args
-
-    def testUnknownAction(self):
-        """'runAction' should fail for an unknown action."""
-        helper = self.getLpQueryDistro(test_args=['boom'])
-        self.assertRaises(LaunchpadScriptFailure,
-                          helper.runAction, self.presenter)
-
-    def testMissingAction(self):
-        """'runAction' should fail for an missing action request."""
-        helper = self.getLpQueryDistro(test_args=[])
-        self.assertRaises(LaunchpadScriptFailure,
-                          helper.runAction, self.presenter)
-
-    def testUnexpectedArgument(self):
-        """'runAction' should fail for an unexpected argument request.
-
-        Some actions do not allow passing 'suite'.
-        See testActionswithDefinedSuite for further information.
-        """
-        helper = self.getLpQueryDistro(
-            test_args=['-s', 'warty', 'supported'])
-        self.assertRaises(LaunchpadScriptFailure,
-                          helper.runAction, self.presenter)
-
-    def testDefaultContextLocation(self):
-        """Check the default location context."""
-        helper = self.getLpQueryDistro(test_args=[])
-        helper._buildLocation()
-
-        self.assertEqual(helper.location.distribution.name, u'ubuntu')
-        self.assertEqual(helper.location.distroseries.name, u'hoary')
-        self.assertEqual(helper.location.pocket.name, 'RELEASE')
-
-    def testLocationFailures(self):
-        """Location failures are wraped into LaunchpadScriptfailure."""
-        # Unknown distribution.
-        helper = self.getLpQueryDistro(test_args=['-d', 'foobar'])
-        self.assertRaises(LaunchpadScriptFailure, helper._buildLocation)
-        # Unknown distroseries.
-        helper = self.getLpQueryDistro(test_args=['-s', 'biscuit'])
-        self.assertRaises(LaunchpadScriptFailure, helper._buildLocation)
-        # Unknown pocket.
-        helper = self.getLpQueryDistro(test_args=['-s', 'hoary-biscuit'])
-        self.assertRaises(LaunchpadScriptFailure, helper._buildLocation)
-
-    def testActionsWithUndefinedSuite(self):
-        """Check the actions supposed to work with undefined suite.
-
-        Only 'supported' works with undefined suite.
-        """
-        helper = self.getLpQueryDistro(test_args=[])
-        helper._buildLocation()
-
-        self.assertEqual(helper.supported, 'hoary warty')
-
-    def assertAttributeRaisesScriptFailure(self, obj, attr_name):
-        """Asserts if accessing the given attribute name fails.
-
-        Check if `LaunchpadScriptFailure` is raised.
-        """
-        self.assertRaises(
-            LaunchpadScriptFailure, operator.attrgetter(attr_name), obj)
-
-    def testActionsWithDefinedSuite(self):
-        """Opposite of  testActionsWithUndefinedSuite.
-
-        The 'supported' action will raise LaunchpadScriptError if the suite
-        is defined.
-        """
-        helper = self.getLpQueryDistro(test_args=['-s', 'warty'])
-        helper._buildLocation()
-
-        self.assertAttributeRaisesScriptFailure(helper, 'supported')

=== removed file 'scripts/ftpmaster-tools/lp-query-distro.py'
--- scripts/ftpmaster-tools/lp-query-distro.py	2013-01-07 02:40:55 +0000
+++ scripts/ftpmaster-tools/lp-query-distro.py	1970-01-01 00:00:00 +0000
@@ -1,27 +0,0 @@
-#!/usr/bin/python -S
-#
-# Copyright 2009-2012 Canonical Ltd.  This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""It provides easy integration of other scripts without database access.
-
-   It should provide an easy way to retrieve current information from
-   Launchpad when using plain shell scripts, for example:
-
-   * SUPPORTED distroseries names:
-       `./lp-query-distro.py -d ubuntu supported`
-
-   Standard Output will carry the successfully executed information and
-   exit_code will be ZERO.
-   In case of failure, exit_code will be different than ZERO and Standard
-   Error will contain debug information.
-   """
-
-import _pythonpath
-
-from lp.soyuz.scripts.querydistro import LpQueryDistro
-
-
-if __name__ == '__main__':
-    script = LpQueryDistro('lp-query-distro', dbuser='ro')
-    script.run()


Follow ups