[Pkg-ocaml-maint-commits] r3978 - in /trunk/tools/ocaml-debian-status: ./ debian-ocaml-status.py retrieve-data.sh

zack at users.alioth.debian.org zack at users.alioth.debian.org
Wed Jul 11 22:50:05 UTC 2007


Author: zack
Date: Wed Jul 11 22:50:05 2007
New Revision: 3978

URL: http://svn.debian.org/wsvn/?sc=1&rev=3978
Log:
First checkin of the script for generating gnome-like status pages.
The logics it's working, but the HTML rendering (which is intended to be based
on Genshi) is completely missing, now just a textual representation is dumped
to stdout.

Added:
    trunk/tools/ocaml-debian-status/
    trunk/tools/ocaml-debian-status/debian-ocaml-status.py   (with props)
    trunk/tools/ocaml-debian-status/retrieve-data.sh   (with props)

Added: trunk/tools/ocaml-debian-status/debian-ocaml-status.py
URL: http://svn.debian.org/wsvn/trunk/tools/ocaml-debian-status/debian-ocaml-status.py?rev=3978&op=file
==============================================================================
--- trunk/tools/ocaml-debian-status/debian-ocaml-status.py (added)
+++ trunk/tools/ocaml-debian-status/debian-ocaml-status.py Wed Jul 11 22:50:05 2007
@@ -1,0 +1,121 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2007, Stefano Zacchiroli <zack at debian.org>
+#
+# Created: Thu, 12 Jul 2007 00:44:10 +0200 zack
+# Last Modified: $Date$
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+
+import bz2
+import gzip
+import os
+import re
+import string
+import sys
+from debian_bundle import debian_support
+
+ocaml_dep_RE = re.compile(r'\bocaml(-nox)?\b')
+ocaml_virtdep_RE = re.compile(r'\bocaml(-nox)?-(?P<version>\d+(\.\d+)*)\b')
+
+def patch_pkg_dict(entry):
+    if not isinstance(entry, dict): # backward compatibility for debian_support
+        entry = dict(map(lambda (x, y): (x.lower(), y), entry))
+    return entry
+
+def smart_open(fname):
+    """Transparently open a compressed (or not) file."""
+
+    f = None
+    if fname.endswith('.gz'):
+        f = gzip.GzipFile(fname)
+    elif fname.endswith('.bz2'):
+        f = bz2.BZ2File(fname)
+    else:
+        f = open(fname)
+    return f
+
+def grep_sources(sources):
+    """Given a list of Sources files (encoded as PackageFile objects), yields
+    all the "relevant" source package names.
+    
+    'sources' arg is a PackageFile object built from a 'Sources' file."""
+
+    for src in sources:
+        src = patch_pkg_dict(src)
+        if src['package'] == 'ocaml':
+            yield src['package']
+        elif src.has_key('build-depends') and \
+                ocaml_dep_RE.search(src['build-depends']):
+            yield src['package']
+        elif src.has_key('build-depends-indep') and \
+                ocaml_dep_RE.search(src['build-depends-indep']):
+            yield src['package']
+
+def eval_status(pkg):
+    status = None
+    if pkg.has_key('depends'):
+        match = ocaml_virtdep_RE.search(pkg['depends'])
+        if match:   # triples: <src_name, src_version, ocaml_version>
+            status = (pkg['source'], pkg['version'],
+                    match.groupdict()['version'])
+    return status
+
+def ocaml_summary(files):
+    sources = filter(lambda fname: re.search(r'-Sources\b', fname), files)
+    packages = filter(lambda fname: re.search(r'-Packages\b', fname), files)
+    distro_of_fname = lambda fname: os.path.basename(fname).split('-')[0]
+
+# STEP 1: find names of source packages we are interested in
+
+    relevant_sources = set()
+    for fname in sources:
+        print fname, '...'
+        f = smart_open(fname)
+        srcfile = debian_support.PackageFile('', fileObj=f)
+        relevant_sources = relevant_sources.union(set(grep_sources(srcfile)))
+        f.close()
+
+# STEP 2: classify packages
+
+    # nested dictionary structure:
+    #  src_name -> (ocaml_version -> list of pairs (distro, src_version))
+    status = {}
+    for fname in packages:
+        print fname, '...'
+        f = smart_open(fname)
+        pkgfile = debian_support.PackageFile('', fileObj=f)
+        for pkg in pkgfile:
+            pkg = patch_pkg_dict(pkg)
+            if not pkg.has_key('source'):
+                pkg['source'] = pkg['package']
+            if pkg['source'] in relevant_sources:
+                pkg_status = eval_status(pkg)
+                if pkg_status:
+                    src_name, src_version, ocaml_version = pkg_status
+                    if not status.has_key(src_name):
+                        status[src_name] = {}
+                    if not status[src_name].has_key(ocaml_version):
+                        status[src_name][ocaml_version] = []
+                    entry = (distro_of_fname(fname), src_version)
+                    if not entry in status[src_name][ocaml_version]:
+                        status[src_name][ocaml_version].append(entry)
+        f.close()
+
+    return status
+
+# TODO
+def render_status(status):
+    out = ''
+    for src_name in status.iterkeys():
+        out += src_name + ' ' + str(status[src_name]) + '\n'
+    return out
+
+if __name__ == '__main__':
+    status = ocaml_summary(sys.argv[1:])
+    out = render_status(status)
+    print out
+

Propchange: trunk/tools/ocaml-debian-status/debian-ocaml-status.py
------------------------------------------------------------------------------
    svn:executable = *

Propchange: trunk/tools/ocaml-debian-status/debian-ocaml-status.py
------------------------------------------------------------------------------
    svn:keywords = Date

Added: trunk/tools/ocaml-debian-status/retrieve-data.sh
URL: http://svn.debian.org/wsvn/trunk/tools/ocaml-debian-status/retrieve-data.sh?rev=3978&op=file
==============================================================================
--- trunk/tools/ocaml-debian-status/retrieve-data.sh (added)
+++ trunk/tools/ocaml-debian-status/retrieve-data.sh Wed Jul 11 22:50:05 2007
@@ -1,0 +1,18 @@
+#!/bin/sh
+mirror="http://ftp.it.debian.org/debian"
+distributions="unstable experimental"
+components="main contrib"
+architectures="i386"
+
+base="$mirror/dists"
+test -d data/ || mkdir data/
+cd data/
+for distro in $distributions ; do
+  for comp in $components ; do
+    wget -O $distro-$comp-Sources.bz2 $base/$distro/$comp/source/Sources.bz2
+    for arch in $architectures ; do
+      fname="$distro-$comp-binary-$arch-Packages.bz2"
+      wget -O $fname $base/$distro/$comp/binary-$arch/Packages.bz2
+    done
+  done
+done

Propchange: trunk/tools/ocaml-debian-status/retrieve-data.sh
------------------------------------------------------------------------------
    svn:executable = *




More information about the Pkg-ocaml-maint-commits mailing list