[Pkg-debile-commits] [debile-slave] 91/100: Refactored config class

Sylvestre Ledru sylvestre at alioth.debian.org
Mon Aug 19 14:53:16 UTC 2013


This is an automated email from the git hooks/post-receive script.

sylvestre pushed a commit to branch master
in repository debile-slave.

commit 1f9450b92c50bd177bd9dd7e0bf790c220ac640b
Author: Léo Cavaillé <leo at cavaille.net>
Date:   Mon Jul 29 11:32:35 2013 +0200

    Refactored config class
---
 ethel/commands/adequate.py      |    7 +++----
 ethel/commands/build.py         |    2 +-
 ethel/commands/clanganalyzer.py |    7 +++++--
 ethel/commands/piuparts.py      |    7 +++----
 ethel/config.py                 |   21 +++++++--------------
 ethel/daemon.py                 |    9 ++++++---
 6 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/ethel/commands/adequate.py b/ethel/commands/adequate.py
index df754fe..12caf2a 100644
--- a/ethel/commands/adequate.py
+++ b/ethel/commands/adequate.py
@@ -1,16 +1,15 @@
 from ethel.runners.adequate import adequate, version
-from ethel.config import load
+from ethel.config import Config
 
 
 def run(debs, package, job, firehose):
     if any((not x.endswith(".deb") for x in debs)):
         raise Exception("Non-deb given")
 
-    config = load()
-    all_arch = config['all-arch']
+    config = Config()
     arch = package['arch']
     if package['arch'] == 'all':
-        arch = all_arch
+        arch = config.get('capabilities', 'all-arch')
 
     chroot_name = "{suite}-{arch}".format(
         suite=package['suite'],
diff --git a/ethel/commands/build.py b/ethel/commands/build.py
index 87dc389..9edc94a 100644
--- a/ethel/commands/build.py
+++ b/ethel/commands/build.py
@@ -24,7 +24,7 @@ def run(dsc, package, job, firehose):
 
     if not ftbfs:
         changes = changes[0]
-        upload(changes, job['_id'])
+        upload(changes, job['id'])
 
     return (info, out, ftbfs)
 
diff --git a/ethel/commands/clanganalyzer.py b/ethel/commands/clanganalyzer.py
index 82f0596..e55e709 100644
--- a/ethel/commands/clanganalyzer.py
+++ b/ethel/commands/clanganalyzer.py
@@ -1,11 +1,14 @@
 from ethel.runners.clanganalyzer import clanganalyzer, version
+from ethel.config import Config
 
 
 # target package firehose
 def run(dsc, package, job, firehose):
+    config = Config()
     suite = job['suite']
-    #FIXME : hardcoded here, but does not really matter
-    arch = 'amd64'
+    arch = package['arch']
+    if package['arch'] == 'all':
+        arch = config.get('capabilities', 'all-arch')
 
     return clanganalyzer(dsc, suite, arch, firehose)
 
diff --git a/ethel/commands/piuparts.py b/ethel/commands/piuparts.py
index b9abb9a..57cee6d 100644
--- a/ethel/commands/piuparts.py
+++ b/ethel/commands/piuparts.py
@@ -1,16 +1,15 @@
 from ethel.runners.piuparts import piuparts, version
-from ethel.config import load
+from ethel.config import Config
 
 
 def run(debs, package, job, firehose):
+    config = Config()
     if any((not x.endswith(".deb") for x in debs)):
         raise Exception("Non-deb given")
 
-    config = load()
-    all_arch = config['all-arch']
     arch = package['arch']
     if package['arch'] == 'all':
-        arch = all_arch
+        arch = config.get('capabilities', 'all-arch')
 
     chroot_name = "{suite}-{arch}".format(
         suite=package['suite'],
diff --git a/ethel/config.py b/ethel/config.py
index 8a7f0f0..2885080 100644
--- a/ethel/config.py
+++ b/ethel/config.py
@@ -1,24 +1,17 @@
 import ConfigParser
 
 class Config(ConfigParser.ConfigParser):
+
+    _instance = None
+    def __new__(cls, *args, **kwargs):
+        if not cls._instance:
+            cls._instance = super(Config, cls).__new__(cls, *args, **kwargs)
+            return cls._instance
+
     def __init__(self, location="/etc/ethel.ini"):
         ConfigParser.ConfigParser.__init__(self)
         self.read(location)
 
-    def __getitem__(self, val):
-        return ConfigSection(val, self.items(val))
-
     def verify():
         # TODO, check that after constructor the conf is fine
         return True
-
-class ConfigSection(Config):
-    def __init__(self, name, vals):
-        self.section_name = name
-        self.vals = vals
-
-    def __getitem__(self, val):
-        for k,v in self.vals:
-            if k == val:
-                return v
-        raise Exception("No such key %s in the configuration", val)
diff --git a/ethel/daemon.py b/ethel/daemon.py
index 02b5454..b2bfb9c 100644
--- a/ethel/daemon.py
+++ b/ethel/daemon.py
@@ -51,9 +51,8 @@ def generate_sut_from_source(package):
 
 
 def generate_sut_from_binary(package):
-    source = proxy.get_source_package(package['source'])
     arch = package['arch']
-    name = source['name']
+    name = package['name']
     local = None
     version = source['version']
     if "-" in version:
@@ -79,14 +78,18 @@ def create_firehose(package, version_getter):
 def iterate():
     suites = listize(config['host']['suites'])
     arches = listize(config['host']['arches'])
+
+    # job is a serialized dictionary from Lucy ORM
+    # {'package': {'user_id': 2, 'name': 'cimg', 'created_at': None, 'updated_at': None, 'version': '1.5.6-1', 'source_id': 2, 'type': 'source', 'dsc': 'cimg_1.5.6-1.dsc'}, 'finished_at': None, 'machine': {'last_ping': <DateTime '20130729T09:10:47' at 1906050>, 'password': 'password', 'id': 1, 'gpg_fingerprint': 'D0FEF8101640900183B8C37A42FE51628224AAA3', 'name': 'debian-builder1'}, 'package_id': 2, 'assigned_at': <DateTime '20130729T09:10:48' at 1906098>, 'type': 'perlcritic', 'suite':  [...]
     with workon(suites, arches, list(PLUGINS.keys())) as job:
         if job is None:
             raise IDidNothingError("No more jobs")
 
         package = job['package']
 
-
+        # Retrieve functions in the module to launch the command and get the version
         handler, version_getter = load_module(job['type'])
+        # Create an empty firehose report with SUT metadata
         firehose = create_firehose(package, version_getter)
 
         with tdir() as fd:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-debile/debile-slave.git



More information about the Pkg-debile-commits mailing list