annotate treepkg/debian.py @ 561:1f7746e2288e

Fix typo
author Bjoern Ricks <bricks@intevation.de>
date Fri, 02 Sep 2011 09:43:21 +0000
parents 27eccce96949
children
rev   line source
127
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
1 # Copyright (C) 2007, 2008 by Intevation GmbH
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
2 # Authors:
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
3 # Bernhard Herzog <bh@intevation.de>
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
4 #
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
5 # This program is free software under the GPL (>=v2)
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
7
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
8 """Support code for debian packages"""
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
9
166
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
10 import os
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
11
127
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
12 from treepkg.util import extract_value_for_key
166
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
13 import treepkg.run
127
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
14
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
15
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
16 class DebianControlFile(object):
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
17
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
18 """Parses a debian/control file and makes some of it available.
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
19
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
20 Instances have the following instance variables:
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
21
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
22 packages -- A list of the names of all packages defined in the
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
23 control file
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
24
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
25 build_depends -- A list with the names of all package listed as
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
26 Build-Depends.
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
27 """
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
28
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
29 def __init__(self, filename):
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
30 """Initialize the instance from a file given by filename"""
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
31 self.packages = []
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
32 self.build_depends = []
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
33 self.parse(filename)
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
34
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
35 def parse(self, filename):
196
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
36 paragraph = []
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
37 paragraphs = [paragraph]
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
38 for lineno, line in enumerate(open(filename)):
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
39 stripped = line.strip()
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
40 if stripped.startswith("#"):
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
41 continue
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
42 if not stripped:
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
43 if paragraph:
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
44 paragraph = []
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
45 paragraphs.append(paragraph)
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
46 else:
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
47 if line[:1] in " \t":
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
48 # handle continuation line
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
49 if paragraph:
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
50 paragraph[-1] += " " + stripped
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
51 else:
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
52 raise RuntimeError("%s:%d: Continuation line without"
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
53 " preceding line"
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
54 % (filename, lineno))
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
55 else:
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
56 paragraph.append(stripped)
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
57 if not paragraphs[-1]:
86ea689eda5f Extend debian/control file parser to cope with more real-world file.
Bernhard Herzog <bh@intevation.de>
parents: 166
diff changeset
58 del paragraphs[-1]
127
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
59
163
674d14305e97 Fix spelling of the DebianControlFile.handle_source_paragraph method.
Bernhard Herzog <bh@intevation.de>
parents: 127
diff changeset
60 self.handle_source_paragraph(paragraphs[0])
127
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
61 for paragraph in paragraphs[1:]:
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
62 self.handle_package_paragraph(paragraph)
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
63
163
674d14305e97 Fix spelling of the DebianControlFile.handle_source_paragraph method.
Bernhard Herzog <bh@intevation.de>
parents: 127
diff changeset
64 def handle_source_paragraph(self, paragraph):
127
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
65 raw_deps = extract_value_for_key(paragraph, "Build-Depends:")
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
66 for dep in raw_deps.split(","):
345
27eccce96949 added sanity check if debian package description contains a dependency with a last ,
Bjoern Ricks <bricks@intevation.de>
parents: 196
diff changeset
67 # sanity check
27eccce96949 added sanity check if debian package description contains a dependency with a last ,
Bjoern Ricks <bricks@intevation.de>
parents: 196
diff changeset
68 if dep.strip() != "":
27eccce96949 added sanity check if debian package description contains a dependency with a last ,
Bjoern Ricks <bricks@intevation.de>
parents: 196
diff changeset
69 self.build_depends.append(dep.split()[0])
127
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
70
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
71 def handle_package_paragraph(self, paragraph):
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
72 package_name = extract_value_for_key(paragraph, "Package:")
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
73 arch = extract_value_for_key(paragraph, "Architecture:")
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
74 self.packages.append((package_name, arch))
e83e96ef12b1 Add treepkg/debian.py and test/test_debian.py with code and tests to
Bernhard Herzog <bh@intevation.de>
parents:
diff changeset
75
166
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
76
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
77
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
78 def sign_file(filename, keyid):
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
79 """Signs a debian .dsc or .control file"""
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
80 contents = open(filename).read()
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
81
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
82 # make sure contents ends with an empty line. The signed files have
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
83 # to have an empty line before the OpenPGP signature block
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
84 if not contents.endswith("\n"):
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
85 contents += "\n"
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
86 contents += "\n"
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
87
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
88 asc_file = filename + ".asc"
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
89 treepkg.run.call(["gpg", "--clearsign", "--armor", "--textmode",
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
90 "--local-user", keyid, "-o", asc_file, "-"],
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
91 inputdata=contents, suppress_output=True)
61fd2892b80b Add a function to sign a debian .dsc or .control file
Bernhard Herzog <bh@intevation.de>
parents: 163
diff changeset
92 os.rename(asc_file, filename)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)