blog post about python-debian dependency parsing support
authorStefano Zacchiroli <zack@upsilon.cc>
Tue, 1 Jul 2008 19:41:44 +0000 (21:41 +0200)
committerStefano Zacchiroli <zack@upsilon.cc>
Tue, 1 Jul 2008 19:41:44 +0000 (21:41 +0200)
blog/archives/2008/07.mdwn [new file with mode: 0644]
blog/posts/2008/07.mdwn [new file with mode: 0644]
blog/posts/2008/07/python-debian_w_dependency_parsing.mdwn [new file with mode: 0644]

diff --git a/blog/archives/2008/07.mdwn b/blog/archives/2008/07.mdwn
new file mode 100644 (file)
index 0000000..156214b
--- /dev/null
@@ -0,0 +1 @@
+[[template id=archive_month year="2008" month="07"]]
diff --git a/blog/posts/2008/07.mdwn b/blog/posts/2008/07.mdwn
new file mode 100644 (file)
index 0000000..41e4a90
--- /dev/null
@@ -0,0 +1 @@
+[[meta redir=archives/2008/07]]
diff --git a/blog/posts/2008/07/python-debian_w_dependency_parsing.mdwn b/blog/posts/2008/07/python-debian_w_dependency_parsing.mdwn
new file mode 100644 (file)
index 0000000..c21db14
--- /dev/null
@@ -0,0 +1,53 @@
+# New python-debian feature: Dependency Parsing
+
+Since [my merge
+commit](http://git.debian.org/?p=pkg-python-debian/python-debian.git;a=commit;h=77ba208864dc17ea0253026ebf073886c5cc97d5)
+of this afternoon `python-debian` has grown **dependency parsing support**.
+
+<small>(But first things first: you know about
+[python-debian](http://packages.debian.org/sid/python-debian), don't you? If you
+don't, and you always wanted to program with Debian-related files with Python,
+then shame on you!)</small>
+
+Thus far, playing with `Packages`-like files using dictionary-like objects was
+already as simple as (quoting from
+`/usr/share/doc/python-debian/examples/deb822/grep-maintainer`):
+
+    for pkg in deb822.Packages.iter_paragraphs(file('/var/lib/dpkg/status')):
+        if pkg.has_key('Maintainer') and maint_RE.search(pkg['maintainer']):
+            print pkg['package']
+
+However, it was a bit unfortunate that `Depends`-like fields were only returned
+as strings. Now each package (as iterated upon in the above snippet) is equipped
+with a `.relations` property returning a dictionary of inter-package
+relationship fields. Looking up keys like `"depends"` you will get back a
+conjunctive normal form *(CNF) representation of dependencies*, together with
+parsed *constraints on version or architectures*, if any.
+
+A simple example is shipped as
+`/usr/share/doc/python-debian/examples/deb822/depgraph`, which outputs a labeled
+Graphviz script of all inter-package dependencies extracted from a Packages
+file. Here is its most relevant snippet:
+
+    name = pkg['package']
+    rels = pkg.relations
+    for deps in rels['depends']:
+        if len(deps) == 1:
+            emit_arc(name, deps[0]['name'])
+        else:   # output an OR node
+            or_node = get_id()
+            emit_arc(name, or_node)
+            emit_node(or_node, 'OR')
+            for dep in deps:
+                emit_arc(or_node, dep['name'].lower())
+
+The appropriate *sub-classes of `Deb822`* have been customized with the
+knowledge of which inter-package relationship fields are supported in their
+stanzas (e.g. `Build-Depends` are supported by `Sources`, but not by `Packages`;
+the other way around for `Recommends`).
+
+Testing from the [git
+repo](http://git.debian.org/?p=pkg-python-debian/python-debian.git) is more than
+welcome.
+
+[[tag lang/english planet/debian debian python]]