From patchwork Mon Sep 5 12:53:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygmunt Krynicki X-Patchwork-Id: 3864 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 6E7E723EFA for ; Mon, 5 Sep 2011 12:53:16 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 5462BA1854F for ; Mon, 5 Sep 2011 12:53:16 +0000 (UTC) Received: by fxd18 with SMTP id 18so5077683fxd.11 for ; Mon, 05 Sep 2011 05:53:16 -0700 (PDT) Received: by 10.223.76.201 with SMTP id d9mr3235326fak.119.1315227196107; Mon, 05 Sep 2011 05:53:16 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.11.8 with SMTP id m8cs62049lab; Mon, 5 Sep 2011 05:53:15 -0700 (PDT) Received: by 10.227.152.81 with SMTP id f17mr3810851wbw.80.1315227195100; Mon, 05 Sep 2011 05:53:15 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com [91.189.90.7]) by mx.google.com with ESMTPS id et9si5972707wbb.44.2011.09.05.05.53.14 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Sep 2011 05:53:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1R0Yfq-0005vE-JU for ; Mon, 05 Sep 2011 12:53:14 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 869E9E013D for ; Mon, 5 Sep 2011 12:53:14 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-server X-Launchpad-Branch: ~linaro-validation/lava-server/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 233 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-server/trunk] Rev 233: Make lava-server a lava-tool extension, add support for instances Message-Id: <20110905125314.29960.76241.launchpad@ackee.canonical.com> Date: Mon, 05 Sep 2011 12:53:14 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13830"; Instance="initZopeless config overlay" X-Launchpad-Hash: ce30f78126f444cfbf21b0dfcf111abb31724063 ------------------------------------------------------------ revno: 233 committer: Zygmunt Krynicki branch nick: trunk timestamp: Mon 2011-09-05 14:51:34 +0200 message: Make lava-server a lava-tool extension, add support for instances modified: lava_server/manage.py setup.py --- lp:lava-server https://code.launchpad.net/~linaro-validation/lava-server/trunk You are subscribed to branch lp:lava-server. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-server/trunk/+edit-subscription === modified file 'lava_server/manage.py' --- lava_server/manage.py 2011-06-03 04:02:34 +0000 +++ lava_server/manage.py 2011-09-05 12:51:34 +0000 @@ -18,28 +18,84 @@ # You should have received a copy of the GNU Affero General Public License # along with LAVA Server. If not, see . +import os +import sys +import pkg_resources +import argparse + +from lava_tool.dispatcher import LavaDispatcher, run_with_dispatcher_class +from lava_tool.interface import Command + + +class LAVAServerDispatcher(LavaDispatcher): + + toolname = 'lava_server' + description = """ + LAVA Application Server + """ + epilog = """ + Please report all bugs using the Launchpad bug tracker: + http://bugs.launchpad.net/lava-server/+filebug + """ + + def __init__(self): + # XXX The below needs to allow some customization. + parser_args = dict(add_help=False) + if self.description is not None: + parser_args['description'] = self.description + if self.epilog is not None: + parser_args['epilog'] = self.epilog + self.parser = argparse.ArgumentParser(**parser_args) + self.subparsers = self.parser.add_subparsers( + title="Sub-command to invoke") + prefixes = [] + if self.toolname is not None: + prefixes.append(self.toolname) + for prefix in prefixes: + for entrypoint in pkg_resources.iter_entry_points( + "%s.commands" % prefix): + self.add_command_cls(entrypoint.load()) + + +class manage(Command): + """ + Manage the LAVA server + """ + + @classmethod + def register_arguments(cls, parser): + parser.add_argument("-p", "--production", + action="store_true", + default=False, + help="Use production settings") + parser.add_argument("-i", "--instance", + action="store", + default=None, + help="Use the specified instance (works only with --production)") + parser.add_argument("command", nargs="...", + help="Invoke this Django management command") + + def invoke(self): + settings_module = "lava_server.settings.development" + if self.args.production: + settings_module = "lava_server.settings.debian" + if self.args.instance: + if not os.path.isdir(self.args.instance): + self.parser.error("Specified instance does not exsit") + os.environ["DJANGO_DEBIAN_SETTINGS_TEMPLATE"] = self.args.instance + "/etc/{filename}.conf" + settings = __import__(settings_module, fromlist=['']) + from django.core.management import execute_manager + execute_manager(settings, ['lava-server'] + self.args.command) + + def find_sources(): - import os - import sys base_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), "..") if os.path.exists(os.path.join(base_path, "lava_server")): sys.path.insert(0, base_path) -find_sources() - -from django.core.management import execute_manager -try: - import lava_server.settings.development as settings -except ImportError as ex: - import logging - logging.exception("Unable to import application settings") - raise SystemExit(ex) - def main(): - execute_manager(settings) - -if __name__ == "__main__": - main() + find_sources() + run_with_dispatcher_class(LAVAServerDispatcher) === modified file 'setup.py' --- setup.py 2011-07-20 20:34:22 +0000 +++ setup.py 2011-09-05 12:51:34 +0000 @@ -30,6 +30,8 @@ entry_points=""" [console_scripts] lava-server = lava_server.manage:main + [lava_server.commands] + manage=lava_server.manage:manage """, test_suite="lava_server.tests.run_tests", license="AGPL", @@ -51,7 +53,8 @@ "Topic :: Software Development :: Testing", ], install_requires=[ - "django-staticfiles == 0.3.4", + 'lava-tool >= 0.2', + 'django-staticfiles == 0.3.4', 'django >= 1.2', 'django-openid-auth >= 0.2', 'linaro-django-xmlrpc >= 0.4',