Guido Günther <[email protected]> writes:

> Hi,

Here is a new version.

Regards.

The following changes since commit 1ea487e43721cfb1609926dfe1e987faea0193ac:

  Don't explicitly refer to lenny-backports (2012-05-20 12:55:04 +0200)

are available in the git repository at:

  git://git.baby-gnu.net/git-buildpackage 
tags/dad/add-minimalist-control-object/rebased/on-1ea487e

for you to fetch changes up to a1d649451c7ccd7f16addf486978e0c21f373d49:

  Add minimalist debian/control object. (2012-05-20 17:30:58 +0200)

----------------------------------------------------------------
Add parsing a string as arguments and add test cases.

Note that the parsing of the git-buildpackage debian/control stops at
the non aligned "#" in the Build-Depends.

----------------------------------------------------------------
Daniel Dehennin (1):
      Add minimalist debian/control object.

 gbp/deb/control.py    |   78 +++++++++++++++++++++++++++++++++++++++++++
 tests/test_Control.py |   89 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 167 insertions(+)
 create mode 100644 gbp/deb/control.py
 create mode 100644 tests/test_Control.py

From a1d649451c7ccd7f16addf486978e0c21f373d49 Mon Sep 17 00:00:00 2001
From: Daniel Dehennin <[email protected]>
Date: Fri, 18 May 2012 19:42:16 +0200
Subject: [PATCH] Add minimalist debian/control object.

As it use an email parser, it stops after the first empty line.

* tests/test_Control.py: Test cases for the new gbp.deb.control.Control
  object.

* gbp/deb/control.py: New class Control with "name", "section" and
  "priority" properties.
---
 gbp/deb/control.py    |   78 +++++++++++++++++++++++++++++++++++++++++++
 tests/test_Control.py |   89 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 167 insertions(+)
 create mode 100644 gbp/deb/control.py
 create mode 100644 tests/test_Control.py

diff --git a/gbp/deb/control.py b/gbp/deb/control.py
new file mode 100644
index 0000000..da01ebe
--- /dev/null
+++ b/gbp/deb/control.py
@@ -0,0 +1,78 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2012 Daniel Dehennin <[email protected]>
+#    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 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+"""A Debian Control"""
+
+import email
+import os
+
+class NoControlError(Exception):
+    """No control found"""
+    pass
+
+class ParseControlError(Exception):
+    """Problem parsing control"""
+    pass
+
+class Control(object):
+    """A Debian control"""
+
+    def __init__(self, contents=None, filename="debian/control"):
+        """
+        Parse an existing control file.
+
+        @param contents: content of a control file
+        @type contents: C{str}
+        @param filename: name of the control file
+        @type filename: C{str}
+        @return: Control object
+        @rtype: C{gbp.deb.conrol.Control} object
+        """
+        if contents:
+            control = email.message_from_string(contents)
+        else:
+            if not os.access(filename, os.F_OK):
+                raise NoControlError("Control file %s does not exist" % 
filename)
+
+            with file(filename) as f:
+                control = email.message_from_file(f)
+
+        if not control.items():
+            raise ParseControlError("Empty or invalid control file or 
contents")
+
+        self._control = control
+        self.filename = filename
+
+    def __getitem__(self, item):
+        return self._control[item]
+
+    def __setitem__(self, item, value):
+        self._control[item] = value
+
+    @property
+    def name(self):
+        """The packges name"""
+        return self._control['Source']
+
+    @property
+    def section(self):
+        """The packges section"""
+        return self._control['Section']
+
+    @property
+    def priority(self):
+        """The packges priority"""
+        return self._control['Priority']
diff --git a/tests/test_Control.py b/tests/test_Control.py
new file mode 100644
index 0000000..0fdeb91
--- /dev/null
+++ b/tests/test_Control.py
@@ -0,0 +1,89 @@
+# vim: set fileencoding=utf-8 :
+
+"""
+Test L{gbp.deb.control.Control}
+"""
+
+cl_debian = """Source: git-buildpackage
+Section: vcs
+Priority: optional
+Maintainer: Guido Günther <[email protected]>
+Build-Depends: debhelper (>= 7.0.50~), python (>> 2.6.6-3~),
+ pychecker, gtk-doc-tools, sgml2x, docbook-utils, jade, python-dateutil, 
python-nose,
+ bash-completion, perl, python-epydoc, python-coverage, python-setuptools,
+ # For the testsuite
+ git (>= 1:1.7.9.1-1~), bzip2, unzip, pristine-tar
+Standards-Version: 3.9.3
+Vcs-Git: git://honk.sigxcpu.org/git/git-buildpackage.git
+Vcs-Browser: http://git.debian.org/?p=users/agx/git-buildpackage.git
+Homepage: https://honk.sigxcpu.org/piki/projects/git-buildpackage/
+X-Python-Version: >= 2.6
+
+Package: git-buildpackage
+Architecture: all
+Depends: ${python:Depends}, ${shlibs:Depends}, ${misc:Depends}, devscripts (>= 
2.10.66~),
+ git (>= 1:1.7.9.1-1~), python-dateutil
+Recommends: pristine-tar (>= 0.5), cowbuilder
+Suggests: python-notify, unzip
+Description: Suite to help with Debian packages in Git repositories
+ This package contains the following tools:
+  * git-import-{dsc,dscs}: import existing Debian source packages into a git
+    repository
+  * git-import-orig: import a new upstream version into the git repository
+  * git-buildpackage: build a package out of a git repository, check for local
+    modifications and tag appropriately
+  * git-dch: generate Debian changelog entries from Git commit messages
+  * gbp-{pull,clone}: clone and pull from remote repos
+  * gbp-pq: manage debian/patches easily
+  * gbp-create-remote-repo: create remote repositories
+"""
+
+def test_parse_control():
+    """
+    Parse a the control of debian package
+
+    Methods tested:
+         - L{gbp.deb.control.Control.__init__}
+
+    Properties tested:
+         - L{gbp.deb.control.Control.name}
+         - L{gbp.deb.control.Control.section}
+         - L{gbp.deb.control.Control.priority}
+
+    >>> import gbp.deb.control
+    >>> cl = gbp.deb.control.Control(cl_debian)
+    >>> cl.name
+    'git-buildpackage'
+    >>> cl.name == cl['Source']
+    True
+    >>> cl.section
+    'vcs'
+    >>> cl.section == cl['Section']
+    True
+    >>> cl.priority
+    'optional'
+    >>> cl.priority == cl['Priority']
+    True
+    >>> cl['Standards-Version']
+    '3.9.3'
+    >>> cl['Package']
+
+    """
+
+def test_no_control_error():
+    """
+    Raise an error if no control file exist or is empty
+
+    Methods tested:
+         - L{gbp.deb.control.Control.__init__}
+
+    >>> import gbp.deb.control
+    >>> cl = gbp.deb.control.Control(filename="doesnotexist")
+    Traceback (most recent call last):
+    ...
+    NoControlError: Control file doesnotexist does not exist
+    >>> cl = gbp.deb.control.Control("notparsable")
+    Traceback (most recent call last):
+    ...
+    ParseControlError: Empty or invalid control file or contents
+    """
-- 
1.7.10


-- 
Daniel Dehennin
Récupérer ma clef GPG:
gpg --keyserver pgp.mit.edu --recv-keys 0x7A6FE2DF

Attachment: pgpZ2VdsliMsy.pgp
Description: PGP signature

Reply via email to