From patchwork Tue Jul 19 21:40:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygmunt Krynicki X-Patchwork-Id: 2770 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 E98E823F57 for ; Tue, 19 Jul 2011 21:41:00 +0000 (UTC) Received: from mail-qy0-f180.google.com (mail-qy0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id B1CB4A185C9 for ; Tue, 19 Jul 2011 21:41:00 +0000 (UTC) Received: by qyk30 with SMTP id 30so3277727qyk.11 for ; Tue, 19 Jul 2011 14:41:00 -0700 (PDT) Received: by 10.229.25.212 with SMTP id a20mr6473374qcc.148.1311111660088; Tue, 19 Jul 2011 14:41:00 -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.229.217.78 with SMTP id hl14cs96244qcb; Tue, 19 Jul 2011 14:40:59 -0700 (PDT) Received: by 10.227.55.130 with SMTP id u2mr7211187wbg.41.1311111659135; Tue, 19 Jul 2011 14:40:59 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id d1si10721390wbh.132.2011.07.19.14.40.58; Tue, 19 Jul 2011 14:40:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QjI2E-0000Io-Ck for ; Tue, 19 Jul 2011 21:40:58 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 5654D2E896C for ; Tue, 19 Jul 2011 21:40:58 +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: 211 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-server/trunk] Rev 211: Improve extension list to support named mapping lookup Message-Id: <20110719214058.22172.15751.launchpad@loganberry.canonical.com> Date: Tue, 19 Jul 2011 21:40:58 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13405"; Instance="initZopeless config overlay" X-Launchpad-Hash: aba82ec212f60c0e5ca0471ea5325a991dc031e1 ------------------------------------------------------------ revno: 211 committer: Zygmunt Krynicki branch nick: trunk timestamp: Tue 2011-07-19 23:36:43 +0200 message: Improve extension list to support named mapping lookup modified: lava_server/extension.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/extension.py' --- lava_server/extension.py 2011-07-13 10:59:13 +0000 +++ lava_server/extension.py 2011-07-19 21:36:43 +0000 @@ -172,8 +172,31 @@ """ List of extensions """ + + class ExtensionMapping(object): + """ + Class that exposes extensions by application name + """ + + def __init__(self, extension_list): + self._extension_list = extension_list + + def __getattr__(self, attr): + for extension in self._extension_list: + if extension.app_name == attr: + return extension + + class ExtensionList(list): + """ + List with an additional property, useful for Django views + """ + + @property + def as_mapping(self): + return ExtensionMapping(self) + if self._extensions is None: - self._extensions = [] + self._extensions = ExtensionList() for name in self._find_extensions(): try: extension = self._load_extension(name)