[csw-devel] SF.net SVN: gar:[13064] csw/mgar/gar/v2/lib

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Jan 23 09:03:14 CET 2011


Revision: 13064
          http://gar.svn.sourceforge.net/gar/?rev=13064&view=rev
Author:   wahwah
Date:     2011-01-23 08:03:13 +0000 (Sun, 23 Jan 2011)

Log Message:
-----------
pkgdb_web: Web access to the package database.

Server-side process, using webpy.  Serves read-only data from the checkpkg
database.

Added Paths:
-----------
    csw/mgar/gar/v2/lib/web/
    csw/mgar/gar/v2/lib/web/pkgdb_web.py
    csw/mgar/gar/v2/lib/web/templates/
    csw/mgar/gar/v2/lib/web/templates/CatalogDetail.html
    csw/mgar/gar/v2/lib/web/templates/CatalogList.html
    csw/mgar/gar/v2/lib/web/templates/ErrorTagList.html
    csw/mgar/gar/v2/lib/web/templates/MaintainerCheckpkgReport.html
    csw/mgar/gar/v2/lib/web/templates/MaintainerDetail.html
    csw/mgar/gar/v2/lib/web/templates/MaintainerList.html
    csw/mgar/gar/v2/lib/web/templates/Srv4Detail.html
    csw/mgar/gar/v2/lib/web/templates/Srv4DetailFiles.html
    csw/mgar/gar/v2/lib/web/templates/Srv4List.html
    csw/mgar/gar/v2/lib/web/templates/index.html

Added: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,185 @@
+#!/opt/csw/bin/python2.6
+
+# A webpy application to allow HTTP access to the checkpkg database.
+
+import web
+import sqlobject
+import json
+from lib.python import models
+from lib.python import configuration
+from lib.python import pkgdb
+from lib.python import checkpkg_lib
+import datetime
+
+urls = (
+  r'/', 'index',
+  r'/srv4/', 'Srv4List',
+  r'/srv4/([0-9a-f]{32})/', 'Srv4Detail',
+  r'/srv4/([0-9a-f]{32})/files/', 'Srv4DetailFiles',
+  r'/catalogs/', 'CatalogList',
+  r'/catalogs/([^-]+)-([^-]+)-([^-]+)/', 'CatalogDetail',
+  r'/maintainers/', 'MaintainerList',
+  r'/maintainers/(\d+)/', 'MaintainerDetail',
+  r'/maintainers/(\d+)/checkpkg/', 'MaintainerCheckpkgReport',
+  r'/error-tags/', 'ErrorTagList',
+  r'/rest/catalogs/([^/]+)/([^/]+)/([^/]+)/pkgname-by-filename', 'PkgnameByFilename',
+)
+
+# render = web.template.render('templates/')
+render = web.template.render('/home/maciej/src/pkgdb_web/templates/')
+
+def ConnectToDatabase():
+  configuration.SetUpSqlobjectConnection()
+
+class index(object):
+  def GET(self):
+    return render.index()
+
+class Srv4List(object):
+  def GET(self):
+    ConnectToDatabase()
+    pkgs = models.Srv4FileStats.select().orderBy('-mtime')[:30]
+    now = datetime.datetime.now()
+    def Ago(timedelta):
+      # Not sure why there is a time difference between mysql and the datetime
+      # module.
+      timezone_diff = 1.0
+      return "%.1fh" % (timedelta.seconds / 60.0 / 60.0 - timezone_diff)
+    pkgs_ago = [(x, Ago(now - x.mtime)) for x in pkgs]
+    return render.Srv4List(pkgs_ago)
+
+class Srv4Detail(object):
+  def GET(self, md5_sum):
+    ConnectToDatabase()
+    try:
+      pkg = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
+      overrides = pkg.GetOverridesResult()
+      tags_by_cat = {}
+      tags_and_catalogs = []
+      arch = pkg.arch
+      osrels = models.OsRelease.select()
+      catrels = models.CatalogRelease.select()
+      all_tags = list(models.CheckpkgErrorTag.selectBy(srv4_file=pkg))
+      for catrel in catrels:
+        for osrel in osrels:
+          tags = pkg.GetErrorTagsResult(osrel, arch, catrel)
+          key = (osrel, arch, catrel)
+          tags = list(tags)
+          tags_by_cat[key] = tags
+          tags_and_catalogs.append((osrel, arch, catrel, tags))
+      return render.Srv4Detail(pkg, overrides, tags_by_cat, all_tags,
+          tags_and_catalogs)
+    except sqlobject.main.SQLObjectNotFound, e:
+      raise web.notfound()
+
+
+class Srv4DetailFiles(object):
+  def GET(self, md5_sum):
+    ConnectToDatabase()
+    srv4 = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
+    files = models.CswFile.selectBy(srv4_file=srv4)
+    return render.Srv4DetailFiles(srv4, files)
+
+
+class CatalogList(object):
+  def GET(self):
+    ConnectToDatabase()
+    archs = models.Architecture.select()
+    osrels = models.OsRelease.select()
+    catrels = models.CatalogRelease.select()
+    catalogs = []
+    for catrel in catrels:
+      for arch in archs:
+        if arch.name in ('all'): continue
+        for osrel in osrels:
+          if osrel.full_name == 'unspecified': continue
+          # tags = pkg.GetErrorTagsResult(osrel, arch, catrel)
+          key = (osrel, arch, catrel)
+          # tags_by_cat[key] = list(tags)
+          catalogs.append(key)
+    return render.CatalogList(catalogs)
+
+class CatalogDetail(object):
+  def GET(self, catrel_name, arch_name, osrel_name):
+    ConnectToDatabase()
+    cat_name = " ".join((catrel_name, arch_name, osrel_name))
+    sqo_osrel, sqo_arch, sqo_catrel = pkgdb.GetSqoTriad(
+        osrel_name, arch_name, catrel_name)
+    pkgs = pkgdb.GetCatPackagesResult(sqo_osrel, sqo_arch, sqo_catrel)
+    return render.CatalogDetail(cat_name, pkgs)
+
+class MaintainerList(object):
+  def GET(self):
+    ConnectToDatabase()
+    maintainers = models.Maintainer.select().orderBy('email')
+    names = [tuple(x.email.split("@") + [x]) for x in maintainers]
+    return render.MaintainerList(names)
+
+class MaintainerDetail(object):
+  def GET(self, id):
+    ConnectToDatabase()
+    maintainer = models.Maintainer.selectBy(id=id).getOne()
+    pkgs = models.Srv4FileStats.select(
+        sqlobject.AND(
+          models.Srv4FileStats.q.maintainer==maintainer,
+          models.Srv4FileStats.q.registered==True,
+        ),
+    ).orderBy('basename')
+    return render.MaintainerDetail(maintainer, pkgs)
+
+class MaintainerCheckpkgReport(object):
+  def GET(self, id):
+    ConnectToDatabase()
+    maintainer = models.Maintainer.selectBy(id=id).getOne()
+    pkgs = models.Srv4FileStats.select(
+        sqlobject.AND(
+          models.Srv4FileStats.q.maintainer==maintainer,
+          models.Srv4FileStats.q.registered==True,
+        ),
+    ).orderBy('basename')
+    tags_by_md5 = {}
+    pkgs = list(pkgs)
+    for pkg in pkgs:
+      tags = list(models.CheckpkgErrorTag.selectBy(srv4_file=pkg))
+      tags_by_md5.setdefault(pkg.md5_sum, tags)
+    return render.MaintainerCheckpkgReport(maintainer, pkgs, tags_by_md5)
+
+class ErrorTagList(object):
+  def GET(self):
+    ConnectToDatabase()
+    # Find all tag names
+    # tag_names = models.CheckpkgErrorTag.select().distinct()
+    tag_names = ['foo']
+    return render.ErrorTagList(tag_names)
+
+
+class PkgnameByFilename(object):
+  def GET(self, catrel, arch, osrel):
+    ConnectToDatabase()
+    user_data = web.input()
+    filename = user_data.filename
+    send_filename = (
+        '%s-%s-%s-%s-packages.txt'
+        % (catrel, arch, osrel, filename.replace('/', '-')))
+    db_catalog = checkpkg_lib.Catalog()
+    try:
+      pkgs = db_catalog.GetPkgByPath(filename, osrel, arch, catrel)
+      web.header('Content-type', 'application/x-vnd.opencsw.pkg;type=pkg-list')
+      web.header('X-Rest-Info', 'I could tell you about the format, but I won\'t')
+      web.header('Content-Disposition',
+                 'attachment; filename=%s' % send_filename)
+      return json.dumps(sorted(pkgs))
+    except sqlobject.main.SQLObjectNotFound, e:
+      raise web.notfound()
+
+
+web.webapi.internalerror = web.debugerror
+
+# app = web.application(urls, globals())
+# web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
+app = web.application(urls, globals(), autoreload=False)
+main = app.wsgifunc()
+
+
+if __name__ == "__main__":
+  app.run()


Property changes on: csw/mgar/gar/v2/lib/web/pkgdb_web.py
___________________________________________________________________
Added: svn:executable
   + *

Added: csw/mgar/gar/v2/lib/web/templates/CatalogDetail.html
===================================================================
--- csw/mgar/gar/v2/lib/web/templates/CatalogDetail.html	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/templates/CatalogDetail.html	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,20 @@
+$def with (cat_name, pkgs)
+<html>
+  <head>
+    <title>
+      Recently built and checked packages
+    </title>
+  </head>
+  <body>
+    <h3>$cat_name</h3>
+    <p>$pkgs.count() packages</p>
+    <ul>
+$for pkg in pkgs:
+  <li>
+  <a href="../../srv4/$pkg.md5_sum/">
+  $pkg
+  </a>
+  </li>
+</ul>
+</body>
+</html>

Added: csw/mgar/gar/v2/lib/web/templates/CatalogList.html
===================================================================
--- csw/mgar/gar/v2/lib/web/templates/CatalogList.html	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/templates/CatalogList.html	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,18 @@
+$def with (keys)
+<html>
+  <head>
+    <title>
+      Recently built and checked packages
+    </title>
+  </head>
+  <body>
+    <ul>
+$for osrel, arch, catrel in keys:
+  <li>
+  <a href="$catrel.name-$arch.name-$osrel.short_name/">
+  $catrel.name-$arch.name-$osrel.short_name
+  </a>
+  </li>
+</ul>
+</body>
+</html>

Added: csw/mgar/gar/v2/lib/web/templates/ErrorTagList.html
===================================================================
--- csw/mgar/gar/v2/lib/web/templates/ErrorTagList.html	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/templates/ErrorTagList.html	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,18 @@
+$def with (tags)
+<html>
+  <head>
+    <title>
+      OpenCSW Maintainers
+    </title>
+  </head>
+  <body>
+    <ul>
+$for tag_name in tags:
+  <li>
+  <a href="$tag_name/">
+    $tag_name
+  </a>
+  </li>
+</ul>
+</body>
+</html>

Added: csw/mgar/gar/v2/lib/web/templates/MaintainerCheckpkgReport.html
===================================================================
--- csw/mgar/gar/v2/lib/web/templates/MaintainerCheckpkgReport.html	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/templates/MaintainerCheckpkgReport.html	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,28 @@
+$def with (maintainer, pkgs, tags_by_md5)
+<html>
+  <head>
+    <title>
+      $maintainer
+    </title>
+  </head>
+  <body>
+    <h2>$maintainer</h2>
+    <h2>Packages</h2>
+    <ul>
+$for pkg in pkgs: 
+  <li>
+  <a href="../../../srv4/$pkg.md5_sum/">
+  $pkg
+  </a>
+
+  $if tags_by_md5[pkg.md5_sum]:
+    <ul>
+    $for tag in tags_by_md5[pkg.md5_sum]:
+      <li>
+      $tag
+      </li>
+    </ul>
+  </li>
+</ul>
+</body>
+</html>

Added: csw/mgar/gar/v2/lib/web/templates/MaintainerDetail.html
===================================================================
--- csw/mgar/gar/v2/lib/web/templates/MaintainerDetail.html	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/templates/MaintainerDetail.html	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,21 @@
+$def with (maintainer, pkgs)
+<html>
+  <head>
+    <title>
+      $maintainer
+    </title>
+  </head>
+  <body>
+    <h2>$maintainer</h2>
+    <p><a href="checkpkg/">Checkpkg report</a></p>
+    <h2>Packages</h2>
+    <ul>
+$for pkg in pkgs: 
+  <li>
+  <a href="../../srv4/$pkg.md5_sum/">
+  $pkg
+  </a>
+  </li>
+</ul>
+</body>
+</html>

Added: csw/mgar/gar/v2/lib/web/templates/MaintainerList.html
===================================================================
--- csw/mgar/gar/v2/lib/web/templates/MaintainerList.html	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/templates/MaintainerList.html	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,21 @@
+$def with (maintainers)
+<html>
+  <head>
+    <title>
+      OpenCSW Maintainers
+    </title>
+  </head>
+  <body>
+    <ul>
+$for username, domain, maintainer in maintainers
+  <li>
+  <a href="$maintainer.id/">
+    $username
+  </a>
+  ($domain.replace(".", "!"))
+  $if maintainer.full_name:
+    $maintainer.full_name
+  </li>
+</ul>
+</body>
+</html>

Added: csw/mgar/gar/v2/lib/web/templates/Srv4Detail.html
===================================================================
--- csw/mgar/gar/v2/lib/web/templates/Srv4Detail.html	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/templates/Srv4Detail.html	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,83 @@
+$def with (pkg, overrides, tags_by_cat, tags, tags_and_catalogs)
+<html>
+  <head>
+    <title>
+      $pkg.basename
+    </title>
+  </head>
+  <body>
+
+<h3>Basic information</h3>
+
+    <ul>
+      <li><tt>$pkg.md5_sum</tt></li>
+      <li>$pkg.basename</li>
+      <li>$pkg.pkginst.pkgname</li>
+      <li>$pkg.catalogname</li>
+      <li>$pkg.version_string</li>
+      <li>Filename $pkg.filename_arch</li>
+      <li>Pkginfo $pkg.arch</li>
+      <li><a href="../../maintainers/$pkg.maintainer.id/">$pkg.maintainer</a></li>
+
+$if pkg.in_catalogs:
+  <li>The package is in catalogs:
+  <ul>
+  $for fic in pkg.in_catalogs:
+    <li>
+    <a href="../../catalogs/$fic.catrel.name-$fic.arch.name-$fic.osrel.short_name/">
+    $fic
+    </a>
+    </li>
+
+
+  </ul>
+  </li>
+
+<li>Size: $pkg.size bytes</li>
+<li>Registered: $pkg.registered</li>
+
+$if pkg.registered:
+  <li><a href="files/">Files of $pkg.basename</a></li>
+
+<li>Use to generate catalogs: $pkg.use_to_generate_catalogs</li>
+
+</ul>
+
+$if overrides:
+  <h3>Overrides</h3>
+  <ul>
+  $for override in overrides:
+    <li>
+    $override
+    </li>
+  </ul>
+$else:
+  <p>No overrides.</p>
+
+<h3>Error tags</h3>
+
+<ul>
+$for osrel, arch, catrel, tags_in_cat in tags_and_catalogs:
+  $if tags_in_cat:
+    <li>
+    $catrel.name
+    $arch.name
+    $osrel.short_name
+    <ul>
+    $for tag in tags_in_cat:
+      <li>$tag</li>
+    </ul>
+    </li>
+</ul>
+<ul>
+$for tag in tags:
+  <li>
+  $tag
+  ($tag.catrel.name
+  $tag.arch.name
+  $tag.os_rel.short_name)
+  </li>
+</ul>
+
+</body>
+</html>

Added: csw/mgar/gar/v2/lib/web/templates/Srv4DetailFiles.html
===================================================================
--- csw/mgar/gar/v2/lib/web/templates/Srv4DetailFiles.html	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/templates/Srv4DetailFiles.html	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,24 @@
+$def with (srv4, files)
+<html>
+  <head>
+    <title>
+      files of
+      $srv4.basename
+    </title>
+  </head>
+  <body>
+
+<h2>
+  files of $srv4.catalogname $srv4.version_string
+</h2>
+
+<ul>
+$for file in files:
+  <li>
+  $file
+  </li>
+
+</ul>
+
+</body>
+</html>

Added: csw/mgar/gar/v2/lib/web/templates/Srv4List.html
===================================================================
--- csw/mgar/gar/v2/lib/web/templates/Srv4List.html	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/templates/Srv4List.html	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,19 @@
+$def with (pkgs)
+<html>
+  <head>
+    <title>
+      Recently built and checked packages
+    </title>
+  </head>
+  <body>
+    <table>
+$for pkg, ago in pkgs:
+  <tr>
+  <td><a href="$pkg.md5_sum/">$pkg.basename</a></td>
+  <td><a href="../maintainers/$pkg.maintainer.id/">$pkg.maintainer.email.split("@")[0]</a></td>
+  <td>$ago ago</td>
+  <td>$pkg.mtime</td>
+  </tr>
+</ul>
+</body>
+</html>

Added: csw/mgar/gar/v2/lib/web/templates/index.html
===================================================================
--- csw/mgar/gar/v2/lib/web/templates/index.html	                        (rev 0)
+++ csw/mgar/gar/v2/lib/web/templates/index.html	2011-01-23 08:03:13 UTC (rev 13064)
@@ -0,0 +1,22 @@
+<html>
+  <head>
+    <title>
+      checkpkg database experimental web app
+    </title>
+  </head>
+  <body>
+    <h1>checkpkg database experimental web app</h1>
+    <ul>
+      <li>
+        <a href="srv4/">Recently checked packages</a>
+      </li>
+      <li>
+        <a href="catalogs/">Catalog list</a>
+      </li>
+      <li>
+        <a href="maintainers/">Maintainer list</a>
+      </li>
+    </ul>
+  </body>
+</html>
+


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list