Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added cornice for REST services.

  • Loading branch information...
commit 5dcd6b61c8e64904019ce9ca15a5d04703e3bd97 1 parent ee35a2e
Jukka Ojaniemi authored
View
3  TODO.rst
@@ -14,3 +14,6 @@ Tasks to do before releasing new version (not priorized in any way):
http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html)
* Not whiskers related, but still important - support for zc.buildout 2.x in
buildout.sendpickedversions.
+ * Settings for how many buildout versions we store.
+ * Buildouts view should show only one buildout version - there's room for
+ loading history via some ajaxy magic.
View
1  development.ini
@@ -14,6 +14,7 @@ pyramid.default_locale_name = en
pyramid.includes =
pyramid_debugtoolbar
pyramid_tm
+ cornice
sqlalchemy.url = sqlite:///%(here)s/whiskers.sqlite
View
2  setup.py
@@ -14,6 +14,8 @@
'pyramid_debugtoolbar',
'zope.sqlalchemy',
'waitress',
+ 'cornice',
+ 'Sphinx'
]
setup(name='whiskers',
View
1  whiskers/__init__.py
@@ -59,4 +59,5 @@ def main(global_config, **settings):
config.add_view(HostsView, route_name='host', attr="host_view",
renderer='views/templates/host.pt')
+ config.scan("whiskers.views.api")
return config.make_wsgi_app()
View
89 whiskers/views/api.py
@@ -0,0 +1,89 @@
+from cornice import Service
+from whiskers.models import (
+ Package,
+ Buildout,
+ Host,
+ Version,
+ DBSession)
+
+
+package_info = Service(name='package_info',
+ path='/api/package/{package}/{version}',
+ description="Package info.")
+
+
+@package_info.get()
+def get_package_info(request):
+ """Returns the information about package."""
+ package = request.matchdict['package']
+ version = request.matchdict['version']
+
+ result = DBSession.query(Package).\
+ outerjoin(Version, Package.version_id == Version.id).\
+ filter(Package.name == package,
+ Version.version == version).first()
+
+ buildouts = [buildout.name for buildout in result.buildouts]
+ buildouts = tuple(set(buildouts))
+
+ result_dict = {'package': result.name,
+ 'version': result.version.version,
+ 'buildouts': list(buildouts)}
+
+ if result.required_by:
+ result_dict['required_by'] = [
+ {'name': package.name,
+ 'version': package.version.version,
+ 'id': package.id} for package in result.required_by]
+
+ if result.requires:
+ result_dict['requires'] = [
+ {'name': package.name,
+ 'version': package.version.version,
+ 'id': package.id} for package in result.requires]
+
+ return result_dict
+
+
+host_info = Service(name='host_info',
+ path='/api/host/{host}',
+ description="Host info.")
+
+
+@host_info.get()
+def get_host_info(request):
+ """Return information about the host."""
+ host = request.matchdict['host']
+
+ result = DBSession.query(Host).\
+ filter(Host.name == host).first()
+ result_dict = {'host': result.name}
+
+ buildouts = set([buildout.name for buildout in result.buildouts])
+ result_dict['buildouts'] = list(buildouts)
+ return result_dict
+
+
+buildout_info = Service(name='buildout_info',
+ path='/api/buildout/{buildout}',
+ description="Buildout info.")
+
+
+@buildout_info.get()
+def get_buildout_info(request):
+ """Return information about the latest buildout."""
+ buildout = request.matchdict['buildout']
+
+ result = DBSession.query(Buildout).filter(Buildout.name == buildout).\
+ order_by(Buildout.datetime).first()
+ result_dict = {'name': result.name,
+ 'updated': result.datetime.isoformat(),
+ 'id': result.id}
+
+ if result.packages:
+ packages = [{'name': package.name,
+ 'version': package.version.version,
+ 'id': package.id} for package in result.packages]
+ result_dict['packages'] = packages
+
+ return result_dict
Please sign in to comment.
Something went wrong with that request. Please try again.