Example #1
0
    def buildout_view(self):
        """Return a buildout specified by buildout_id."""
        buildout_id = self.request.matchdict['buildout_id']
        buildout = DBSession.query(Buildout).filter_by(
            id=int(buildout_id)).one()

        new_buildouts = DBSession.query(Buildout).join(Buildout.host).\
            filter(Buildout.host == buildout.host,
                   Buildout.name == buildout.name,
                   Buildout.id != buildout_id,
                   Buildout.datetime > buildout.datetime).\
            order_by(Buildout.datetime).all()

        older_buildouts = DBSession.query(Buildout).join(Buildout.host).\
            filter(Buildout.host == buildout.host,
                   Buildout.name == buildout.name,
                   Buildout.datetime < buildout.datetime,
                   Buildout.id != buildout_id).\
            order_by(Buildout.datetime).all()

        try:
            config = json.loads(buildout.config)
        except TypeError:
            config = None

        return {'buildout': buildout, 'main': self.main, 'config': config,
                'older_buildouts': older_buildouts,
                'new_buildouts': new_buildouts}
Example #2
0
    def buildout_view(self):
        """Return a buildout specified by buildout_id."""
        buildout_id = self.request.matchdict['buildout_id']
        buildout = DBSession.query(Buildout).filter_by(
            id=int(buildout_id)).one()

        new_buildouts = DBSession.query(Buildout).\
            join(Buildout.host).\
            filter(Buildout.host == buildout.host,
                   Buildout.name == buildout.name,
                   Buildout.id != buildout_id,
                   Buildout.datetime > buildout.datetime).\
            order_by(Buildout.datetime).all()

        older_buildouts = DBSession.query(Buildout).join(Buildout.host).\
            filter(Buildout.host == buildout.host,
                   Buildout.name == buildout.name,
                   Buildout.datetime < buildout.datetime,
                   Buildout.id != buildout_id).\
            order_by(Buildout.datetime).all()

        try:
            config = json.loads(buildout.config)
        except TypeError:
            config = None

        return {
            'buildout': buildout,
            'main': self.main,
            'config': config,
            'older_buildouts': older_buildouts,
            'new_buildouts': new_buildouts
        }
Example #3
0
def buildout_view(request):
    main = get_renderer('whiskers:templates/master.pt').implementation()
    session = DBSession()
    buildout_id = request.matchdict['buildout_id']
    buildout = session.query(Buildout).filter_by(id=int(buildout_id)).one()
    packages = session.query(Package).join(Package.buildouts).filter(
                    Buildout.id == buildout_id).order_by(Package.name).all()
    return {'buildout': buildout, 'main': main, 'packages': packages}
 def get_buildouts(self, host_id):
     """Return list of buildouts."""
     results = DBSession.query(Buildout).\
         filter(Buildout.host_id == host_id).\
         group_by(Buildout.name).\
         order_by(Buildout.datetime.desc()).all()
     return results
    def get_unique_buildouts(self, host):
        """Return amount of buildouts (grouped by name)."""

        results = DBSession.query(Buildout).\
            filter(Buildout.host == host).\
            group_by(Buildout.name)

        return results.count()
Example #6
0
    def get_buildouts_info(self):
        """Return list of dicts containing Buildout info."""

        query = DBSession.query(Buildout).join(Buildout.host).\
            group_by(Buildout.name).order_by(Buildout.datetime).\
            all()

        return query
def add_version(package, version):
    """Add a new version and return its id"""

    existing_version = DBSession.query(Version).filter_by(version=version)

    if not existing_version.count():
        new_version = Version(version)
        DBSession.merge()
        return new_version.id
Example #8
0
    def test_it(self):
        from sqlalchemy import create_engine
        engine = create_engine('sqlite:///:memory:')
        self._callFUT(engine)
        from whiskers.models import DBSession, Buildout, Package
        self._createDummyContent(DBSession)

        buildout = DBSession.query(Buildout).one()
        self.assertEqual(buildout.name, 'buildout')
        packages = ['package1', 'package2']
        versions = ['1.0', '2.0']
        buildout_packages = [i.name for i in buildout.packages]
        buildout_versions = [i.version.version for i in buildout.packages]

        self.assertEqual(packages.sort(), buildout_packages.sort())
        self.assertEqual(versions.sort(), buildout_versions.sort())
        p1 = DBSession.query(Package).filter(Package.name == 'package2').one()
        self.assertEqual(p1.requires[0].name, 'req-package-1')
        self.assertEqual(buildout.host.name, 'localhost')
Example #9
0
    def get_buildouts_info(self):
        """Return list of dicts containing Buildout info."""

        query = DBSession.query(Buildout).\
            join(Buildout.host).\
            group_by(Buildout.name).\
            order_by(Buildout.datetime).\
            all()

        return query
def get_version(version):
    """Returns version id for package"""

    session = DBSession()
    existing_version = session.query(Version).filter_by(version=version)

    if existing_version.count():
        return existing_version.first().id
    else:
        new_version_id = add_version(version)
        return new_version_id
Example #11
0
    def hosts_info(self):
        """Return list of dicts containing Host info."""

        result_list = []

        results = DBSession.query(Host).\
            join(Buildout, Buildout.host_id == Host.id).all()

        for result in results:
            tmp = {'host': result, 'count': self.get_unique_buildouts(result)}
            result_list.append(tmp)

        return result_list
 def post(self):
     """Save settings."""
     try:
         buildouts_to_keep = int(self.request.params['buildouts_to_keep'])
         settings = DBSession.query(Settings).first()
         if not settings:
             settings = Settings(buildouts_to_keep)
         else:
             if buildouts_to_keep != settings.buildouts_to_keep:
                 settings.buildouts_to_keep = buildouts_to_keep
         DBSession.add(settings)
         return HTTPFound(location=self.request.route_url('settings'))
     except:
         pass
Example #13
0
 def post(self):
     """Save settings."""
     try:
         buildouts_to_keep = int(self.request.params['buildouts_to_keep'])
         settings = DBSession.query(Settings).first()
         if not settings:
             settings = Settings(buildouts_to_keep)
         else:
             if buildouts_to_keep != settings.buildouts_to_keep:
                 settings.buildouts_to_keep = buildouts_to_keep
         DBSession.add(settings)
         return HTTPFound(location=self.request.route_url('settings'))
     except:
         pass
Example #14
0
    def get_hosts_info(self):
        """Return list of dicts containing Host info."""

        result_list = []

        results = DBSession.query(Host).\
            join(Buildout, Buildout.host_id == Host.id).all()

        for result in results:
            tmp = {}
            tmp['host'] = result
            tmp['count'] = len(result.buildouts)
            result_list.append(tmp)

        return result_list
Example #15
0
    def test_it(self):
        from sqlalchemy import create_engine

        engine = create_engine("sqlite:///:memory:")
        self._callFUT(engine)
        from whiskers.models import DBSession, Buildout

        self._createDummyContent(DBSession)
        buildout = DBSession.query(Buildout).one()
        self.assertEqual(buildout.name, "buildout")
        packages = [u"package1", u"package2"]
        versions = [u"1.0", u"1.1"]
        buildout_packages = [i.name for i in buildout.packages]
        buildout_versions = [i.version for i in buildout.packages]
        self.assertEqual(packages.sort(), buildout_packages.sort())
        self.assertEqual(versions.sort(), buildout_versions.sort())
Example #16
0
def add_buildout_view(request):
    try:
        data = json.loads(request.params['data'])
    except KeyError:
        return Response('No data. Nothing added.')

    session = DBSession()
    buildoutname = data['buildoutname']
    packages = data['packages']
    prepared_packages = prepare_packages(session, packages)
    buildout = session.query(Buildout).filter_by(name=buildoutname)

    if not buildout.count():
        buildout = Buildout(name=buildoutname, packages=prepared_packages)
    else:
        buildout = buildout[0]
        buildout.packages = prepared_packages
    session.merge(buildout)
    transaction.commit()
    return Response('OK')
Example #17
0
def package_view(request):
    main = get_renderer('whiskers:templates/master.pt').implementation()
    session = DBSession()
    package_name = request.matchdict['package_name']
    package_id = request.matchdict['id']

    results = session.query(Package).filter(
        Package.name == package_name)
    packages = results.all()
    packages = sort_versionnumbers(packages)

    if len(package_id) > 0:
        package = results.filter_by(id=int(package_id[0])).first()
    else:
        package = None
    if results.count() > 1:
        other_versions = True
    else:
        other_versions = False

    return {'packages': packages, 'package': package,
            'package_name': package_name, 'main': main,
            'other_versions': other_versions}
Example #18
0
 def collection_get(self):
     """Return all hosts as json."""
     results = DBSession.query(Host).order_by(Host.name).all()
     results = [host.get_as_dict() for host in results]
     return {'hosts': results}
Example #19
0
 def collection_get(self):
     """Return all buildouts as json."""
     results = DBSession.query(Buildout).order_by(Buildout.name).all()
     results = [buildout.get_as_dict() for buildout in results]
     return {'buildouts': results}
Example #20
0
 def delete_package(self):
     """Delete unused package."""
     package_id = self.request.matchdict.get("id", None)
     package = DBSession.query(Package).filter(Package.id == package_id).first()
     DBSession.delete(package)
     return json.dumps(dict(result="OK"))
Example #21
0
 def collection_get(self):
     """Return all hosts as json."""
     results = DBSession.query(Host).order_by(Host.name).all()
     results = [host.get_as_dict() for host in results]
     return {'hosts': results}
 def collection_get(self):
     """Return all packages as json."""
     results = DBSession.query(Package).order_by(Package.name).all()
     results = [package.get_as_dict() for package in results]
     return {'packages': results}
 def delete_package(self):
     """Delete unused package."""
     package_id = self.request.matchdict.get('id', None)
     package = DBSession.query(Package).filter(Package.id == package_id).first()
     DBSession.delete(package)
     return json.dumps(dict(result="OK"))
Example #24
0
def buildouts_view(request):
    main = get_renderer('whiskers:templates/master.pt').implementation()
    session = DBSession()
    buildouts = session.query(Buildout).order_by(Buildout.name).all()
    return {'buildouts': buildouts, 'project': 'whiskers', 'main': main}
Example #25
0
def packages_view(request):
    main = get_renderer('whiskers:templates/master.pt').implementation()
    session = DBSession()
    packages = session.query(Package).group_by(Package.name).all()
    return {'packages': packages, 'project': 'whiskers', 'main': main}
def version_view(request):
    main = get_renderer('whiskers:views/templates/master.pt').implementation()
    session = DBSession()
    version_id = request.matchdict['version_id']
    version = session.query(Version).filter_by(id=int(version_id)).one()
    return {'version': version, 'main': main}
 def collection_get(self):
     """Return all buildouts as json."""
     results = DBSession.query(Buildout).order_by(Buildout.name).all()
     results = [buildout.get_as_dict() for buildout in results]
     return {'buildouts': results}