view treepkg/debian.py @ 570:44c0f8404983

Refactor git pull command out of update Tag MUST NOT use update because therefore it always changes the current local branch! For listing the tags it's enough to pull the latest repo changes
author Bjoern Ricks <bricks@intevation.de>
date Fri, 02 Sep 2011 11:46:29 +0000
parents 27eccce96949
children
line wrap: on
line source
# Copyright (C) 2007, 2008 by Intevation GmbH
# Authors:
# Bernhard Herzog <bh@intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with the software for details.

"""Support code for debian packages"""

import os

from treepkg.util import extract_value_for_key
import treepkg.run


class DebianControlFile(object):

    """Parses a debian/control file and makes some of it available.

    Instances have the following instance variables:

      packages -- A list of the names of all packages defined in the
                  control file

      build_depends -- A list with the names of all package listed as
                       Build-Depends.
    """

    def __init__(self, filename):
        """Initialize the instance from a file given by filename"""
        self.packages = []
        self.build_depends = []
        self.parse(filename)

    def parse(self, filename):
        paragraph = []
        paragraphs = [paragraph]
        for lineno, line in enumerate(open(filename)):
            stripped = line.strip()
            if stripped.startswith("#"):
                continue
            if not stripped:
                if paragraph:
                    paragraph = []
                    paragraphs.append(paragraph)
            else:
                if line[:1] in " \t":
                    # handle continuation line
                    if paragraph:
                        paragraph[-1] += " " + stripped
                    else:
                        raise RuntimeError("%s:%d: Continuation line without"
                                           " preceding line"
                                           % (filename, lineno))
                else:
                    paragraph.append(stripped)
        if not paragraphs[-1]:
            del paragraphs[-1]

        self.handle_source_paragraph(paragraphs[0])
        for paragraph in paragraphs[1:]:
            self.handle_package_paragraph(paragraph)

    def handle_source_paragraph(self, paragraph):
        raw_deps = extract_value_for_key(paragraph, "Build-Depends:")
        for dep in raw_deps.split(","):
            # sanity check
            if dep.strip() != "":
                self.build_depends.append(dep.split()[0])

    def handle_package_paragraph(self, paragraph):
        package_name = extract_value_for_key(paragraph, "Package:")
        arch = extract_value_for_key(paragraph, "Architecture:")
        self.packages.append((package_name, arch))



def sign_file(filename, keyid):
    """Signs a debian .dsc or .control file"""
    contents = open(filename).read()

    # make sure contents ends with an empty line.  The signed files have
    # to have an empty line before the OpenPGP signature block
    if not contents.endswith("\n"):
        contents += "\n"
    contents += "\n"

    asc_file = filename + ".asc"
    treepkg.run.call(["gpg", "--clearsign", "--armor", "--textmode",
                      "--local-user", keyid, "-o", asc_file, "-"],
                     inputdata=contents, suppress_output=True)
    os.rename(asc_file, filename)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)