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