view treepkg/debian.py @ 163:674d14305e97

Fix spelling of the DebianControlFile.handle_source_paragraph method.
author Bernhard Herzog <bh@intevation.de>
date Fri, 20 Jun 2008 10:19:26 +0000
parents e83e96ef12b1
children 61fd2892b80b
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"""

from treepkg.util import extract_value_for_key


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):
        lines = [line.strip() for line in open(filename).readlines()]
        paragraphs = []
        while lines:
            try:
                empty_line = lines.index("")
            except ValueError:
                empty_line = len(lines)
            paragraphs.append(lines[:empty_line])
            lines = lines[empty_line + 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(","):
            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))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)