1
2
3
4
5
6
7
8
9
10 """
11 library to populate parameters from and rpmspec file into a memory structure
12 """
13
14 import re
15 from buildbot.steps.shell import ShellCommand
16
17
19 """
20 read parameters out of an rpm spec file
21 """
22
23
24 n_regex = re.compile('^Name:[ ]*([^\s]*)')
25 v_regex = re.compile('^Version:[ ]*([0-9\.]*)')
26
27 - def __init__(self, specfile=None, **kwargs):
28 """
29 Creates the RpmSpec object.
30
31 @type specfile: str
32 @param specfile: the name of the specfile to get the package
33 name and version from
34 @type kwargs: dict
35 @param kwargs: All further keyword arguments.
36 """
37 self.specfile = specfile
38 self._pkg_name = None
39 self._pkg_version = None
40 self._loaded = False
41
43 """
44 call this function after the file exists to populate properties
45 """
46
47
48 if isinstance(self.specfile, str):
49 f = open(self.specfile, 'r')
50 else:
51 f = self.specfile
52
53 for line in f:
54 if self.v_regex.match(line):
55 self._pkg_version = self.v_regex.match(line).group(1)
56 if self.n_regex.match(line):
57 self._pkg_name = self.n_regex.match(line).group(1)
58 f.close()
59 self._loaded = True
60
61
62 loaded = property(lambda self: self._loaded)
63 pkg_name = property(lambda self: self._pkg_name)
64 pkg_version = property(lambda self: self._pkg_version)
65