[Pkg-debile-commits] [debile-master] 96/126: BROKEN : snapshot of nomongo dev

Sylvestre Ledru sylvestre at alioth.debian.org
Mon Aug 19 14:56:22 UTC 2013


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

sylvestre pushed a commit to branch scan-build-html
in repository debile-master.

commit 95b512dc9be550d776fdecfb451fa65d2ca09975
Author: Léo Cavaillé <leo at cavaille.net>
Date:   Thu Jul 25 17:52:41 2013 +0200

    BROKEN : snapshot of nomongo dev
---
 lucy/__init__.py               |    9 --
 lucy/archive.py                |   16 +---
 lucy/cli/incoming.py           |    2 +-
 lucy/cli/init.py               |   62 +++++++------
 lucy/config.py                 |   25 ++++++
 lucy/core.py                   |   16 ----
 lucy/incoming.py               |  176 ++++++++++++++++++++++---------------
 lucy/models/__init__.py        |   79 -----------------
 lucy/models/config.py          |   11 ---
 lucy/orm.py                    |   87 ++++++++++++++++++
 lucy/server.py                 |  190 ++++++++++++++++++++++++----------------
 lucy/tests/__init__.py         |   25 ------
 lucy/tests/test_lucy_base.py   |   41 ---------
 lucy/tests/test_lucy_source.py |   25 ------
 lucy/tests/test_lucy_user.py   |   32 -------
 scripts/lucy-processd          |    2 +-
 16 files changed, 368 insertions(+), 430 deletions(-)

diff --git a/lucy/__init__.py b/lucy/__init__.py
index 1f8d813..c6034dc 100644
--- a/lucy/__init__.py
+++ b/lucy/__init__.py
@@ -1,11 +1,2 @@
 __appname__ = "lucy"
 __version__ = "0.0.1"
-
-
-from lucy.models.machine import Machine  # NOQA
-from lucy.models.source import Source  # NOQA
-from lucy.models.binary import Binary  # NOQA
-from lucy.models.report import Report  # NOQA
-from lucy.models.config import Config  # NOQA
-from lucy.models.user import User  # NOQA
-from lucy.models.job import Job  # NOQA
diff --git a/lucy/archive.py b/lucy/archive.py
index eb24008..2d46c0a 100644
--- a/lucy/archive.py
+++ b/lucy/archive.py
@@ -1,20 +1,10 @@
 import shutil
 import os
 
-
-def uuid_to_path(uuid, base=None):
-    nodes = uuid.split("-")
-    ids = os.path.join(*nodes)
-    path = os.path.join(*list(nodes[-1])[:4])
-    path = os.path.join(ids, path)
-    return path
-
-
-def move_to_pool(config, package, changes, root=None):
+def move_to_pool(package, changes, root=None):
+    #TODO ADD CONFIG here
     pool = config['pool']
-    uid = package
-    ret = uuid_to_path(uid, base=pool)
-    path = os.path.join(pool, ret)
+    path = os.path.join(pool, package.id)
     if root:
         path = os.path.join(path, root)
 
diff --git a/lucy/cli/incoming.py b/lucy/cli/incoming.py
index 4e65dd7..bd1aea8 100644
--- a/lucy/cli/incoming.py
+++ b/lucy/cli/incoming.py
@@ -1,8 +1,8 @@
-from lucy.models.config import Config
 from lucy.incoming import process
 
 
 def main():
+    #TODO ADD Config here
     obj = Config.load('default')
     process(obj)
 
diff --git a/lucy/cli/init.py b/lucy/cli/init.py
index 8668432..d37bc6f 100644
--- a/lucy/cli/init.py
+++ b/lucy/cli/init.py
@@ -1,38 +1,44 @@
 from clint.textui import progress, puts
 from clint import args
-
-from lucy.models.machine import Machine
-from lucy.models.config import Config
-from lucy.models.user import User
+import lucy.orm as lucymodel
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
 
 import json
 
+metadata = lucymodel.Base.metadata
 
 def main():
-    if not args.files:
-        raise Exception("WTF - need a config")
-
-    config = args.files.pop(0)
-    obj = json.load(open(config, 'r'))
-
-    machines = obj['machines']
-    configs = obj['configs']
-    users = obj['users']
-
-    puts("Loading users:")
-    for conf in progress.bar(users):
-        u = User(**conf)
-        u.save()
-
-    puts("Loading machines:")
-    for conf in progress.bar(machines):
-        m = Machine(**conf)
-        m.save()
-
-    puts("Loading configs:")
-    for conf in progress.bar(configs):
-        c = Config(**conf)
-        c.save()
+    engine = create_engine('postgresql://leo:prout@localhost/lucy', echo=True)
+
+    metadata.drop_all(bind=engine)
+    metadata.create_all(bind=engine)
+
+
+#    if not args.files:
+#        raise Exception("WTF - need a config")
+#
+#    config = args.files.pop(0)
+#    obj = json.load(open(config, 'r'))
+#
+#    machines = obj['machines']
+#    configs = obj['configs']
+#    users = obj['users']
+#
+#    puts("Loading users:")
+#    for conf in progress.bar(users):
+#        u = User(**conf)
+#        u.save()
+#
+#    puts("Loading machines:")
+#    for conf in progress.bar(machines):
+#        m = Machine(**conf)
+#        m.save()
+#
+#    puts("Loading configs:")
+#    for conf in progress.bar(configs):
+#        c = Config(**conf)
+#        c.save()
 
 
 if __name__ == "__main__":
diff --git a/lucy/config.py b/lucy/config.py
new file mode 100644
index 0000000..5f59bdf
--- /dev/null
+++ b/lucy/config.py
@@ -0,0 +1,25 @@
+import ConfigParser
+
+class Config(ConfigParser.ConfigParser):
+    def __init__(self, location="/etc/lucy.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/lucy/core.py b/lucy/core.py
deleted file mode 100644
index 48be1bf..0000000
--- a/lucy/core.py
+++ /dev/null
@@ -1,16 +0,0 @@
-from pymongo import Connection
-
-
-connection = Connection('localhost', 27017)
-db = connection.lucy
-config = None
-
-
-def get_config(name='default'):
-    global config
-    if config:
-        return config
-
-    from lucy.models.config import Config
-    config = Config.load(name)
-    return config
diff --git a/lucy/incoming.py b/lucy/incoming.py
index 1638a53..44efb94 100644
--- a/lucy/incoming.py
+++ b/lucy/incoming.py
@@ -1,8 +1,7 @@
-from lucy import User, Source, Machine, Binary, Job
+from lucy.orm import User, Source, Machine, Binary, Job
 from lucy.archive import move_to_pool
 
 from lucy.changes import parse_changes_file, ChangesFileException
-from lucy.core import get_config
 from lucy.utils import cd, fglob
 #from lucy.mail import send_mail
 
@@ -10,7 +9,8 @@ import os
 
 
 
-def process(config):
+def process():
+    #TODO ADD CONFIG here
     incoming = config['incoming']
     pcf = lambda x: parse_changes_file(x, incoming)
     with cd(incoming):
@@ -18,90 +18,111 @@ def process(config):
             try:
                 changes.validate()
             except ChangesFileException:
-                reject(config, changes, "invalid")
+                reject(changes, "invalid")
                 continue
-            accept(config, changes)
+            accept(changes)
 
 
-def accept(config, changes):
+def accept(changes):
     try:
         changes.validate_signature()
     except ChangesFileException:
-        return reject(config, changes, "invalid-signature")
+        return reject(changes, "invalid-signature")
 
     if changes.is_source_only_upload():
-        return accept_source(config, changes)
+        return accept_source(changes)
 
     if changes.is_binary_only_upload():
-        return accept_binary(config, changes)
+        return accept_binary(changes)
 
-    return reject(config, changes, "not-only-sourceful")
+    return reject(changes, "not-only-sourceful")
 
 
-def accept_source(config, changes):
+def accept_source(changes):
+    session = LucyDBSession()
     key = changes.validate_signature()
 
     try:
-        who = User.get_by_key(key)
-    except KeyError:
-        return reject(changes, config, 'bad-user-account')
+        owner = session.query(User).filter(User.gpg_fingerprint == key).one()
+    except NoResultFound:
+        return reject(changes, 'bad-user-account')
+
+    if changes['Distribution'] != 'unstable':
+        return reject(changes, 'source-not-unstable')
 
     dsc = os.path.basename(changes.get_dsc())
 
     group = None
     if 'X-Lucy-Group' in changes:
-        group = changes['X-Lucy-Group']
+        group = Group(name=changes['X-Lucy-Group'])
 
-    obj = Source(source=changes['source'],
-                 version=changes['version'],
-                 owner=who['_id'],
-                 group=group,
-                 dsc=dsc)
-    obj.save()
+    s = Source( name=changes['source'],
+                version=changes['version'],
+                user=owner,
+                group=group,
+                dsc=dsc)
 
-    path = move_to_pool(config, obj['_id'], changes)
+    path = move_to_pool(s, changes)
     os.unlink(changes.get_filename())
 
-    obj['path'] = path
-    obj.save()
-
-    print("ACCEPT: {source}/{version} for {owner} as {_id}".format(**obj))
     #send_mail("ACCEPTED: {source}/{version} for {owner} as {_id}".format(
     #    **obj), who['email'], "ACCEPTED!")
 
-    add_jobs(obj, 'source', config, 'source', changes)
-
-
-def add_jobs(package, package_type, config, klass, changes):
-
-    for type in config['job_classes'][klass]:
-        if klass == 'source':
-            suite = "unstable"
-            arch = "all"
-        else:
-            suite = package['suite']
-            arch = package['arch']
-
-        j = Job(package=package['_id'],
-                package_type=package_type,
-                suite=suite,
-                arch=arch,
+    #TODO ADD LOG HERE
+    logging.info("Accepted source package : %s / %s (%s/%s)",
+            s.name,
+            s.version,
+            s.suite,
+            s.arch)
+    add_jobs(s)
+
+
+def add_jobs(package):
+    #TODO ADD SESSION
+    session = LucyDBSession()
+    #TODO ADD CONFIG here
+    for type in config['job_classes'][package.type]:
+        # For source packages, use only unstable and set arch to all
+        # so that any builder arch can take jobs
+        j = Job(package=package,
+                suite=package.suite,
+                arch=package.arch,
                 type=type)
-        print("  -> Job: ", j.save(), type)
-
-    if klass == 'source':
-        # add builds
-        suite = changes['Distribution']
+        session.add(j)
+
+    #TODO ADD LOG HERE
+        logging.info("Adding job type %s,%s (id %s) for package %s (%s/%s/%s)",
+                package.type,
+                j.type,
+                j.id,
+                package.name,
+                package.version,
+                package.suite,
+                package.arch)
+
+    if package.type == 'source':
         for arch in config['arches']:
             j = Job(arch=arch,
-                    suite=suite,
+                    suite=package.suite,
                     type='build',
-                    package=package['_id'],
-                    package_type=package_type)
-            print("  -> Bin: ", j.save(), arch, suite)
+                    package=package)
+
+            logging.info("Adding job type %s/%s (id %s) for package %s (%s/%s/%s)",
+                    package.type,
+                    j.type,
+                    j.id,
+                    package.name,
+                    package.version,
+                    package.suite,
+                    package.arch)
+            session.add(j)
+    session.commit()
 
 
-def accept_binary(config, changes):
+def accept_binary(changes):
+    #TODO ADD SESSION
+    session = LucyDBSession()
+
     key = changes.validate_signature()
 
     arch = changes['Architecture']
@@ -112,7 +133,7 @@ def accept_binary(config, changes):
 
         arches = list(arches)
         if len(arches) != 1:
-            return reject(config, changes, 'too-many-arches')
+            return reject(changes, 'too-many-arches')
 
         arch = changes._data['Architecture'] = arches[0]
 
@@ -121,34 +142,45 @@ def accept_binary(config, changes):
     binaries = changes.get_files()
 
     try:
-        job = changes['x-lucy-job']
+        job_id = changes['x-lucy-job']
     except KeyError:
-        return reject(config, changes, 'no-job')
+        return reject(changes, 'no-job')
 
     try:
-        job = Job.load(job)
-    except KeyError:
-        return reject(config, changes, 'invalid-job')
+        j = session.query(Job).filter(Job.id == job).one()
+    except NoResultFound:
+        return reject(changes, 'invalid-job')
 
+    # Now find the source related to this build job
     try:
-        buildd = Machine.get_by_key(key)
-    except KeyError:
-        return reject(config, changes, 'youre-not-a-machine')
+        s = session.query(Source).join(Source.jobs).filter(Job.id == job_id).one()
+    except NoResultFound:
+        return reject(changes, 'invalid-job')
+
+    buildd = session.query(Machine).filter(Machine.key == key).first()
+    if not buildd:
+        return reject(changes, 'youre-not-a-machine')
 
-    binary = Binary(job=job['_id'],
-                    arch=arch,
-                    suite=suite,
-                    binaries=[os.path.basename(x) for x in binaries],
-                    builder=buildd['_id'])
-    binary.save()
-    add_jobs(binary, 'binary', config, 'binary', changes)
+    b = Binary( source=s,
+                name=changes['source'],
+                version=changes['version'],
+                arch=arch,
+                suite=suite,
+                files=[os.path.basename(x) for x in binaries],
+                builder=buildd)
+    session.add(b)
+    add_jobs(b)
 
-    path = move_to_pool(config, binary['source'], changes, root=arch)
+    path = move_to_pool(b, changes, root=arch)
     os.unlink(changes.get_filename())
-    print("accept binary")
+    logging.info("Accepted binary package : %s / %s (%s/%s)",
+            b.name,
+            b.version,
+            b.suite,
+            b.arch)
 
 
-def reject(config, changes, reason):
+def reject(changes, reason):
     print("reject", reason)
     # email luser with reason template
     for fpath in changes.get_files() + [changes.get_changes_file()]:
diff --git a/lucy/models/__init__.py b/lucy/models/__init__.py
deleted file mode 100644
index 22dbfac..0000000
--- a/lucy/models/__init__.py
+++ /dev/null
@@ -1,79 +0,0 @@
-import datetime as dt
-import lucy.core
-import uuid
-
-
-def _get_table(what):
-    return getattr(lucy.core.db, what)
-
-
-class LucyObject(dict):
-    _type = None
-
-    def __init__(self, **kwargs):
-        self['_type'] = self._type
-        for k, v in kwargs.items():
-            self[k] = v
-
-    def _gen_uuid(self):
-        return str(uuid.uuid1())
-
-    def save(self):
-        if self._type is None:
-            raise ValueError("You done goofed, sucka")
-
-        uuid = self.get('_id')
-        self['updated_at'] = dt.datetime.utcnow()
-        if uuid is None:
-            uuid = self['_id'] = self._gen_uuid()
-            self['created_at'] = dt.datetime.utcnow()
-        _get_table(self._type).save(self)
-        return uuid
-
-    def delete(self):
-        table = _get_table(self._type)
-        table.remove({"_id": self['_id']})
-        return uuid
-
-    @classmethod
-    def load(cls, what):
-        table = _get_table(cls._type)
-        obj = table.find_one({"_id": what})
-        if obj is None:
-            raise KeyError("No such object: `%s' found." % (what))
-        return cls.from_dict(obj)
-
-    @classmethod
-    def query(cls, what, sort=None, sort_order=1,
-              limit=None, page_count=None, page=0):
-
-        table = _get_table(cls._type)
-        pointer = table.find(what)
-        if sort:
-            pointer = pointer.sort(sort, sort_order)
-
-        if limit:
-            pointer = pointer.limit(limit)
-
-        if page and page_count:
-            offset = int(page) * int(page_count)
-            pointer = pointer.skip(offset)
-
-        if page_count:
-            pointer = pointer.limit(page_count)
-
-        for x in pointer:
-            yield cls(**x)
-
-    @classmethod
-    def from_dict(cls, what):
-        klass = cls(**what)
-        return klass
-
-    @classmethod
-    def single(cls, query):
-        os = cls.query(query)
-        try:
-            return next(os)
-        except StopIteration:
-            raise KeyError("Error. No such thing")
diff --git a/lucy/models/config.py b/lucy/models/config.py
deleted file mode 100644
index 6ab08ca..0000000
--- a/lucy/models/config.py
+++ /dev/null
@@ -1,11 +0,0 @@
-from lucy.models import LucyObject
-
-
-class Config(LucyObject):
-    _type = 'metadata'
-
-    def __init__(self, _id, incoming, pool, **kwargs):
-        super(Config, self).__init__(_id=_id,
-                                     incoming=incoming,
-                                     pool=pool,
-                                     **kwargs)
diff --git a/lucy/orm.py b/lucy/orm.py
new file mode 100644
index 0000000..ce76938
--- /dev/null
+++ b/lucy/orm.py
@@ -0,0 +1,87 @@
+from sqlalchemy.ext.declarative import declarative_base
+
+Base = declarative_base()
+
+from sqlalchemy.orm import relationship, backref
+from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
+
+import datetime as dt
+
+class User(Base):
+    __tablename__ = 'users'
+    id = Column(Integer, primary_key=True)
+    name = Column(String(100))
+    gpg_fingerprint = Column(String(100))
+
+
+class Machine(Base):
+    __tablename__ = 'machines'
+    id = Column(Integer, primary_key=True)
+    name = Column(String(100))
+    last_ping = Column(DateTime)
+    gpg_fingerprint = Column(String(100))
+    password = Column(String)
+
+    def ping(self):
+        last_ping = dt.datetime.utcnow()
+
+class Group(Base):
+    __tablename__ = 'groups'
+    id = Column(Integer, primary_key=True)
+    name = Column(String(100))
+
+class Package(Base):
+    __tablename__ = 'packages'
+    package_id = Column(Integer, primary_key=True)
+    type = Column(String(30), nullable=False)
+    __mapper_args__ = {'polymorphic_on': type}
+
+class Source(Package):
+    __tablename__ = 'sources'
+    __mapper_args__ = {'polymorphic_identity': 'source'}
+    # If package is source, we add a special job for each available arch
+    # to build the binaries that will be uploaded to lucy by ethel instances
+    suite = 'unstable'
+    arch = 'all'
+    source_id = Column(Integer, ForeignKey('packages.package_id'), primary_key=True)
+    created_at = Column(DateTime)
+    updated_at = Column(DateTime)
+    name = Column(String(100))
+    version = Column(String(20))
+    user_id = Column(Integer, ForeignKey('users.id'))
+    user = relationship("User", backref=backref('sources', order_by=name))
+    dsc = Column(String(100))
+
+class BinaryFiles(Base):
+    __tablename__ = 'binaryfiles'
+    id = Column(Integer, primary_key=True)
+    name =  Column(String(100))
+    binary_id = Column(Integer, ForeignKey('binaries.binary_id'), nullable=False)
+    binary = relationship("Binary", backref=backref('files', order_by=name))
+
+class Binary(Package):
+    __tablename__ = 'binaries'
+    __mapper_args__ = {'polymorphic_identity': 'binary'}
+    binary_id = Column(Integer, ForeignKey('packages.package_id'), primary_key=True)
+    name = Column(String(100))
+    source_id = Column(Integer, ForeignKey('sources.source_id'))
+    source = relationship("Source", backref=backref('binaries', order_by=name), foreign_keys=[source_id])
+    created_at = Column(DateTime)
+    updated_at = Column(DateTime)
+    arch = Column(String(20), nullable=False)
+    suite = Column(String(50), nullable=False)
+    
+
+class Job(Base):
+    __tablename__ = 'jobs'
+    id = Column(Integer, primary_key=True)
+    assigned_at = Column(DateTime)
+    finished_at = Column(DateTime)
+    machine_id = Column(Integer, ForeignKey('machines.id'))
+    machine = relationship("Machine", backref=backref('jobs', order_by=id), foreign_keys=[machine_id])
+    type = Column(String(50), nullable=False)
+    package_id = Column(Integer, ForeignKey('packages.package_id'), nullable=False)
+    package = relationship("Package", backref=backref('jobs', order_by=id), foreign_keys=[package_id])
+    arch = Column(String(20), nullable=False)
+    suite = Column(String(50), nullable=False)
+
diff --git a/lucy/server.py b/lucy/server.py
index b88c872..9a35d56 100644
--- a/lucy/server.py
+++ b/lucy/server.py
@@ -1,6 +1,10 @@
-from lucy import Machine, Job, Source, Binary, Report
-from lucy.archive import uuid_to_path
-from lucy.core import get_config
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker, with_polymorphic, contains_eager, joinedload
+from sqlalchemy.orm.util import aliased
+from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound
+
+from lucy.orm import Machine, Job, Source, Binary, User, Package
+from lucy.config import Config
 from lucy.mail import send_mail
 
 from SimpleXMLRPCServer import SimpleXMLRPCServer
@@ -12,9 +16,15 @@ import SocketServer
 import threading
 import os.path
 import os
+import logging
 
 NAMESPACE = threading.local()
-config = get_config()
+
+# TODO : Command line arg for location ?
+config = Config()
+
+engine = create_engine('postgresql://leo:prout@localhost/lucy', echo=True)
+Session = sessionmaker(bind=engine)
 
 
 def send_failed_email(job, package, report):
@@ -38,7 +48,7 @@ def send_failed_email(job, package, report):
 def machine_method(fn):
     def _(*args, **kwargs):
         try:
-            get_builder_id()
+            get_builder()
             return fn(*args, **kwargs)
         except KeyError:
             raise Exception("You can't do that")
@@ -48,7 +58,7 @@ def machine_method(fn):
 def user_method(fn):
     def _(*args, **kwargs):
         try:
-            get_user_id()
+            get_user()
             return fn(*args, **kwargs)
         except KeyError:
             raise Exception("You can't do that")
@@ -62,8 +72,10 @@ class LucyInterface(object):
         Get the DB entry for the source package. Return None if it doesn't
         exist.
         """
+        session = Session()
+        s = session.query(Source).filter(Source.id == source_id).one()
         try:
-            return dict(Source.load(package))
+            return dict(s)
         except KeyError:
             return None
 
@@ -72,8 +84,10 @@ class LucyInterface(object):
         Get the DB entry for the binary package. Return None if it doesn't
         exist.
         """
+        session = Session()
+        b = session.query(Binary).filter(Binary.id == binary_id).one()
         try:
-            return dict(Binary.load(package))
+            return dict(b)
         except KeyError:
             return None
 
@@ -82,77 +96,88 @@ class LucyInterface(object):
         Get the .dsc path if the package is a valid source package. Otherwise
         return None.
         """
-        public = config['public']
-        package = Source.load(package)
+        session = Session()
+        s = session.query(Source).filter(Source.id == source_id).one()
+        public = config['paths']['public']
         return "{public}/{pool}/{dsc}".format(
             public=public,
-            pool=package['path'],
-            dsc=package['dsc'],
+            pool=s.id,
+            dsc=s.dsc,
         )
 
-    def get_log_write_location(self, report):
-        report = Report.load(report)
-        path = os.path.join(config['pool'], report['log_path'])
+    def get_log_write_location(self, job):
+        path = os.path.join(config['path']['job'], job.id, 'log')
         return path
 
-    def get_firehose_write_location(self, report):
-        report = Report.load(report)
-        path = os.path.join(config['pool'], report['firehose_path'])
+    def get_firehose_write_location(self, job):
+        session = Session()
+        jobs = session.query(Job).filter(Job.machine == get_builder()).all()
+        path = os.path.join(config['path']['job'], job.id, 'firehose.xml')
         return path
 
-    def get_deb_info(self, package):
+    def get_deb_info(self, binary_id):
         """
         Get a list of .debs for the given Binary package, otherwise None.
         """
-        pkg = Binary.load(package)
-        source = pkg.get_source()
-        public = config['public']
+        session = Session()
+        b = session.query(Binary).filter(Binary.id == binary_id).one()
+        public = config['paths']['public']
 
         root = "{public}/{pool}/{arch}".format(
             public=public,
-            pool=source['path'],
-            arch=pkg['arch'],
+            pool=b.source.id,
+            arch=b.arch,
         )
 
         return {"root": root, "packages": pkg['binaries']}
 
-    #
-
     @machine_method
     def get_current_jobs(self):
         """
         Get the current job for the builder or return None.
         """
-        return list(Job.assigned_jobs(get_builder_id()))
+        session = Session()
+        jobs = session.query(Job).filter(Job.machine == get_builder()).all()
+        return jobs
 
     @machine_method
-    def forfeit_job(self, job):
-        j = Job.load(job)
-        buildd = j.get_builder()
-        if buildd['_id'] != get_builder_id():
+    def forfeit_job(self, job_id):
+        session = Session()
+        j = session.query(Job).filter(Job.id == job_id).one()
+        if j.machine != get_builder():
             return None  # meh
 
-        j['assigned_at'] = None
-        j['builder'] = None
-        return j.save()
+        j.assigned_at = None
+        j.builder = None
+        session.commit()
+        return j
 
     @machine_method
     def get_next_job(self, suites, arches, types):
         """
         Get an unassigned lint job from suite suites, arches arches
         """
-        try:
-            nj = Job.next_job(suites, arches, types)
-        except KeyError:
+        session = Session()
+    
+        j = session.query(Job).\
+                filter(Job.assigned_at == None).\
+                filter(Job.machine == None).\
+                filter(Job.type.in_(types)).\
+                filter(Job.arch.in_(arches)).\
+                filter(Job.suite.in_(suites)).\
+                first()
+
+        if j:
+            j.assigned_at = dt.datetime.utcnow()
+            j.machine = get_builder()
+        else:
             return None
-
-        nj['assigned_at'] = dt.datetime.utcnow()
-        nj['builder'] = get_builder_id()
-        nj.save()
-        return dict(nj)
+        return j
 
     @machine_method
     def submit_report(self, report, job, failed):
+        # FIXME : put here a bridge to firewose ?
+        session = Session()
         """
         Submit a report from a run.
 
@@ -160,53 +185,54 @@ class LucyInterface(object):
         job - job ID this relates to
         failed - was it able to complete properly
         """
-        job = Job.load(job)
+        j = session.query(Job).filter(Job.id == job_id).one()
         package = job.get_package()
-        report = Report(report=report,
-                        builder=get_builder_id(),
-                        package=package['_id'],
-                        package_type=job['package_type'],
-                        job=job['_id'],
-                        failed=failed)
+        #report = Report(report=report,
+        #                builder=get_builder(),
+        #                package=package['_id'],
+        #                package_type=job['package_type'],
+        #                job=job['_id'],
+        #                failed=failed)
 
-        uuid_path = uuid_to_path(job['_id'])
+        #uuid_path = uuid_to_path(job['_id'])
 
-        path = os.path.join(config['pool'], uuid_path)
-        if not os.path.exists(path):
-            os.makedirs(path)
+        #path = os.path.join(config['path']['jobs'], j.id)
+        #if not os.path.exists(path):
+        #    os.makedirs(path)
 
-        report['log_path'] = os.path.join(uuid_path, 'log')
-        report['firehose_path'] = os.path.join(uuid_path, 'firehose.xml')
-        rid = report.save()
+        #report['log_path'] = os.path.join(path, 'log')
+        #report['firehose_path'] = os.path.join(path, 'firehose.xml')
+        #rid = report.save()
 
         if failed:
             send_failed_email(job, package, report)
 
-        return rid
+        return 
+        #return rid
 
     @machine_method
-    def close_job(self, job):
+    def close_job(self, job_id):
         """
         Close a job after pushing reports / binaries up.
         """
-        j = Job.load(job)
-        j['finished_at'] = dt.datetime.utcnow()
-        return j.save()
+        j = session.query(Job).filter(Job.id == job_id).one()
+        j.finished_at = dt.datetime.utcnow()
+        session.commit()
 
 
 # =================== ok, boring shit below ===================
 
 
-def get_builder_id():
+def get_builder():
     if NAMESPACE.machine is None:
         raise KeyError("What the shit, doing something you can't do")
-    return NAMESPACE.machine['_id']
+    return NAMESPACE.machine
 
 
-def get_user_id():
+def get_user():
     if NAMESPACE.user is None:
         raise KeyError("What the shit, doing something you can't do")
-    return NAMESPACE.user['_id']
+    return NAMESPACE.user
 
 
 class LucyAuthMixIn(SimpleXMLRPCRequestHandler):
@@ -220,21 +246,29 @@ class LucyAuthMixIn(SimpleXMLRPCRequestHandler):
 
         if self.authenticate_machine(entity, password):
             return True
-        return self.authenticate_user()
+        return self.authenticate_user(entity, password)
 
-    def authenticate_user(self, user, password):
-        user = User.load(user)
-        if user.auth(password):
-            NAMESPACE.user = user
-            return True
+    def authenticate_user(self, user_name, password):
+        session = Session()
+        try:
+            user = session.query(User).filter(User.name == user_name).one()
+            if user.password == password:
+                NAMESPACE.user = user
+                return True
+        except NoResultFound, e:
+            logging.error("User claiming name %s does not exist", user_name)        
         return False
 
-    def authenticate_machine(self, machine, password):
-        machine = Machine.load(machine)
-        if machine.auth(password):
-            NAMESPACE.machine = machine
-            machine.ping()
-            return True
+    def authenticate_machine(self, machine_name, password):
+        session = Session()
+        try:
+            machine = session.query(Machine).filter(Machine.name == machine_name).one()
+            if machine.password == password:
+                NAMESPACE.machine = machine
+                machine.ping()
+                return True
+        except NoResultFound, e:
+            logging.error("Machine claiming name %s does not exist", machine_name)        
         return False
 
     def parse_request(self, *args):
@@ -261,6 +295,8 @@ def serve(server, port):
 
 
 def main():
+    logging.basicConfig(format='%(asctime)s - %(levelname)8s - [lucy] %(message)s', level=logging.DEBUG)
+    logging.info("Booting lucy daemon")
     serve("0.0.0.0", 20017)
 
 
diff --git a/lucy/tests/__init__.py b/lucy/tests/__init__.py
deleted file mode 100644
index 44473ae..0000000
--- a/lucy/tests/__init__.py
+++ /dev/null
@@ -1,25 +0,0 @@
-from pymongo import Connection
-import os
-
-from lucy.models.config import Config
-import lucy.core
-
-ROOT = "%s/../../resources/" % (os.path.dirname(__file__))
-
-
-def setup():
-    connection = Connection('localhost', 27017)
-    db = connection.lucy_test
-    lucy.core.db = db
-    for x in db.collection_names():
-        if x.startswith('system'):
-            continue
-
-        db.drop_collection(x)
-
-    name = "default"
-    incoming = "%s/incoming/" % (ROOT)
-    pool = "%s/pool/" % (ROOT)
-
-    if name != Config(_id=name, incoming=incoming, pool=pool).save():
-        raise Exception
diff --git a/lucy/tests/test_lucy_base.py b/lucy/tests/test_lucy_base.py
deleted file mode 100644
index 56862b2..0000000
--- a/lucy/tests/test_lucy_base.py
+++ /dev/null
@@ -1,41 +0,0 @@
-from lucy.models import LucyObject
-
-
-class LucyFord(LucyObject):
-    _type = 'test'
-
-
-def test_basic_actions():
-    """ Test that basic save / load works. """
-
-    lo = LucyFord()
-    lo['foo'] = 'bar'
-    uid = lo.save()
-
-    obj = LucyFord.load(uid)
-    obj.pop('updated_at')
-    obj.pop('created_at')
-    lo.pop('updated_at')
-    lo.pop('created_at')
-    assert obj == lo, "Make sure loaded object == generated object"
-    obj['bar'] = 'baz'
-    assert obj != lo, "Make sure loaded object != generated object"
-
-    obj.save()
-    lo = obj
-    obj = LucyFord.load(uid)
-
-    obj.pop('updated_at')
-    lo.pop('updated_at')
-
-    assert obj == lo, "Make sure loaded object == generated object"
-
-    assert len(list(LucyFord.query({}))) == 1, "Count sucks"
-    obj.delete()
-    assert len(list(LucyFord.query({}))) == 0, "Count sucks post remove"
-
-    try:
-        obj = LucyFord.load("INVALID")
-        assert True is False, "Invalid query went through"
-    except KeyError:
-        pass
diff --git a/lucy/tests/test_lucy_source.py b/lucy/tests/test_lucy_source.py
deleted file mode 100644
index d8c6360..0000000
--- a/lucy/tests/test_lucy_source.py
+++ /dev/null
@@ -1,25 +0,0 @@
-from lucy.models.source import Source
-from lucy.models.user import User
-
-
-def test_basic_source():
-    """ Test that source routines works """
-    User(_id='joe', name='', email='', gpg='').save()
-
-    p = Source(source='fluxbox',
-                version='1.0',
-                owner="joe")
-    p.save()
-
-    p = Source(source='fluxbox',
-                version='2.0',
-                owner="joe")
-    p.save()
-
-    p = Source(source='frucksbox',
-                version='2.0',
-                owner="joe")
-    x = p.save()
-
-    obj = Source.load(x)
-    assert obj['version'] == '2.0'
diff --git a/lucy/tests/test_lucy_user.py b/lucy/tests/test_lucy_user.py
deleted file mode 100644
index 9c15161..0000000
--- a/lucy/tests/test_lucy_user.py
+++ /dev/null
@@ -1,32 +0,0 @@
-from lucy.models.user import User
-
-
-def test_basic_user_foo():
-    """ Test that user routines works """
-
-    u = User(_id='joe',
-             name='Joe Bar',
-             gpg="8F049AD82C92066C7352D28A7B585B30807C2A87",
-             email="noreply at example.com")
-
-    assert 'joe' == u.save()
-    u.save()
-
-    joe = User.get_by_email('noreply at example.com')
-
-    joe.pop('updated_at')
-    u.pop('updated_at')
-
-    assert joe == u
-
-    joe = User.get_by_key("8F049AD82C92066C7352D28A7B585B30807C2A87")
-
-    joe.pop('updated_at')
-
-    assert joe == u
-
-    try:
-        joe = User.get_by_key("foo")
-        assert True is False, "KeyCheck failed"
-    except KeyError:
-        pass
diff --git a/scripts/lucy-processd b/scripts/lucy-processd
index 18097db..13a4a76 100755
--- a/scripts/lucy-processd
+++ b/scripts/lucy-processd
@@ -5,6 +5,6 @@ lucy-process-incoming
 #FIXME: hardcoded path :(
 inoticoming \
     --foreground \
-    /srv/lucy.pault.ag/incoming/ \
+    /tmp/incoming/ \
     --suffix .changes lucy-process-incoming \
     \;

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



More information about the Pkg-debile-commits mailing list