Permalink
Browse files

Added started, finished and ipv4.

 * Host has now ipv4 field for ip-address.
 * Buildout has now started and finished fields.
 * Updated jsonwrapper to handle above.
 * Some minor pep8 fixes.
  • Loading branch information...
1 parent 0f1fd69 commit db3eecc42483367301c8cde425292da9cf750d2a Jukka Ojaniemi committed Mar 20, 2013
Showing with 81 additions and 29 deletions.
  1. +24 −9 whiskers/jsonwrapper.py
  2. +52 −16 whiskers/models.py
  3. +5 −4 whiskers/views/buildouts.py
View
@@ -1,24 +1,42 @@
import json
+import dateutil.parser
class JsonDataWrapper(object):
"""Wrapper for json-data."""
def __init__(self, data):
self.data = json.loads(data)
+ self.buildout = self.data.get('buildout_config')
@property
def hostname(self):
return self.data.get('hostname', None)
@property
+ def ipv4(self):
+ return self.data.get('ipv4', None)
+
+ @property
+ def started(self):
+ date = self.data.get('started', None)
+ parsed = dateutil.parser.parse(date)
+ return parsed
+
+ @property
+ def finished(self):
+ date = self.data.get('finished', None)
+ parsed = dateutil.parser.parse(date)
+ return parsed
+
+ @property
def name(self):
- return self.data.get('buildoutname', None) or\
+ return self.buildout.get('buildoutname', None) or\
self.path.rsplit('/', 1)[-1]
@property
def path(self):
- return self.data.get('directory', None)
+ return self.buildout.get('directory', None)
@property
def packages(self):
@@ -31,26 +49,23 @@ def packages(self):
@property
def executable(self):
- return self.data.get('executable', None)
+ return self.buildout.get('executable', None)
@property
def allow_picked_versions(self):
- return self.data.get('allow_picked_versions', None)
+ return self.buildout.get('allow_picked_versions', None)
@property
def newest(self):
- return self.data.get('newest', None)
+ return self.buildout.get('newest', None)
@property
def versionmap(self):
return self.data.get('versionmap', None)
@property
def config(self):
- tmp = self.data.copy()
- tmp.pop('packages')
- tmp.pop('versionmap')
- return json.dumps(tmp)
+ return json.dumps(self.buildout)
def get_package_version(self, package):
"""Return package version."""
View
@@ -7,7 +7,8 @@
DateTime,
Unicode,
ForeignKey,
- Table)
+ Table
+)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.exc import NoResultFound
@@ -16,7 +17,8 @@
scoped_session,
sessionmaker,
relationship,
- backref)
+ backref
+)
from zope.sqlalchemy import ZopeTransactionExtension
from zope.interface import implementer
@@ -44,30 +46,49 @@
@implementer(interfaces.IBuildout)
class Buildout(Base):
+ """
+ Buildout contains the model and classmethods for storing
+ and querying buildout information.
+ """
__tablename__ = 'buildout'
id = Column(Integer, primary_key=True)
name = Column(Unicode(255))
datetime = Column(DateTime)
+ started = Column(DateTime)
+ finished = Column(DateTime)
checksum = Column(Integer, unique=True)
host_id = Column(Integer, ForeignKey('host.id'))
- host = relationship("Host",
- backref=backref('buildouts',
- order_by=datetime.desc()))
- packages = relationship("Package", secondary=buildoutpackage_table,
- backref=backref('buildouts', order_by=name))
config = Column(Text)
- def __init__(self, name, host, checksum, packages=None, config=None):
+ # Many to many relationship to Host
+ host = relationship(
+ "Host",
+ backref=backref('buildouts', order_by=datetime.desc())
+ )
+ # Many to many relationship to Package
+ packages = relationship(
+ "Package",
+ secondary=buildoutpackage_table,
+ backref=backref('buildouts', order_by=name),
+ order_by="Package.name"
+ )
+
+ def __init__(self, name, host, checksum, started=None, finished=None,
+ packages=None, config=None):
self.name = name
self.host = host
+ self.datetime = datetime.now()
+ self.checksum = checksum
+ if started:
+ self.started = started
+ if finished:
+ self.finished = finished
if packages:
self.packages = packages
if config:
self.config = config
- self.datetime = datetime.now()
- self.checksum = checksum
@classmethod
def get_by_checksum(klass, checksum):
@@ -93,9 +114,11 @@ class Host(Base):
id = Column(Integer, primary_key=True)
name = Column(Unicode(25), unique=True)
+ ipv4 = Column(Text(15))
- def __init__(self, name):
+ def __init__(self, name, ipv4):
self.name = name
+ self.ipv4 = ipv4
@classmethod
def all_by_name(klass):
@@ -119,25 +142,29 @@ def get_by_id(klass, id):
return host.one()
@classmethod
- def add(klass, hostname):
- host = klass(hostname)
+ def add(klass, hostname, ipv4):
+ """Add a new host object to DB."""
+ host = klass(hostname, ipv4)
DBSession.add(host)
return host
@implementer(interfaces.IPackage)
class Package(Base):
"""
+ Package contains information about the specific package (name, version
+ requirements).
+
Each package is contained zero or many buildouts.
Each Package contains one version.
"""
__tablename__ = 'package'
id = Column(Integer, primary_key=True)
+ name = Column(Unicode(255))
version_id = Column(Integer, ForeignKey("version.id"))
version = relationship("Version", backref="packages")
- name = Column(Unicode(255))
requires = relationship(
"Package",
secondary=packagerequires_table,
@@ -178,6 +205,7 @@ def by_name(klass):
@classmethod
def get_by_nameversion(klass, name, version=None):
+ """Return package filtered by name and version."""
query = DBSession.query(klass).join(klass.version).\
filter(klass.name == name)
if version:
@@ -186,29 +214,37 @@ def get_by_nameversion(klass, name, version=None):
@classmethod
def get_by_id(klass, id):
+ """Return package id."""
package = DBSession.query(klass).filter_by(id)
if package.count():
return package.first().id
@classmethod
def add(klass, name, version=None, requires=None):
+ """Add a new package to DB."""
package = klass(name, version=version, requires=requires)
DBSession.add(package)
return package
@implementer(interfaces.IVersion)
class Version(Base):
- """Each version is contained in zero or many packages"""
+ """
+ Version contains information and classmethods for storing and
+ querying package versions.
+
+ Each version is contained in zero or many packages.
+ """
__tablename__ = 'version'
id = Column(Integer, primary_key=True)
version = Column(Unicode(20), unique=True)
+ final_version = Column(Unicode(20), unique=True)
equation = Column(Unicode(2))
- def __init__(self, version, equation=None):
+ def __init__(self, version, equation=None, final_version=None):
self.version = version
if equation:
self.equation = equation
@@ -64,11 +64,11 @@ def post(self):
host = Host.get_by_name(jsondata.hostname)
if not host:
- host = Host.add(jsondata.hostname)
+ host = Host.add(jsondata.hostname, jsondata.ipv4)
self.add_buildout(jsondata, host, checksum)
- return Response('Added buildout info to Whiskers.')
+ return Response('Added buildout information to Whiskers.')
def add_buildout(self, data, host, checksum):
packages = []
@@ -88,8 +88,9 @@ def add_buildout(self, data, host, checksum):
packages.append(package)
- buildout = Buildout(data.name, host, checksum, packages,
- data.config)
+ buildout = Buildout(data.name, host, checksum, started=data.started,
+ finished=data.finished, packages=packages,
+ config=data.config)
DBSession.add(buildout)
return buildout

0 comments on commit db3eecc

Please sign in to comment.