OLD | NEW |
| (Empty) |
1 # Dan Radez <dradez+buildbot@redhat.com> | |
2 # Steve 'Ashcrow' Milner <smilner+buildbot@redhat.com> | |
3 # | |
4 # This software may be freely redistributed under the terms of the GNU | |
5 # general public license. | |
6 # | |
7 # You should have received a copy of the GNU General Public License | |
8 # along with this program; if not, write to the Free Software | |
9 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
10 """ | |
11 library to populate parameters from and rpmspec file into a memory structure | |
12 """ | |
13 | |
14 | |
15 from buildbot.steps.shell import ShellCommand | |
16 | |
17 | |
18 class RpmSpec(ShellCommand): | |
19 """ | |
20 read parameters out of an rpm spec file | |
21 """ | |
22 | |
23 import re | |
24 import types | |
25 | |
26 #initialize spec info vars and get them from the spec file | |
27 n_regex = re.compile('^Name:[ ]*([^\s]*)') | |
28 v_regex = re.compile('^Version:[ ]*([0-9\.]*)') | |
29 | |
30 def __init__(self, specfile=None, **kwargs): | |
31 """ | |
32 Creates the RpmSpec object. | |
33 | |
34 @type specfile: str | |
35 @param specfile: the name of the specfile to get the package | |
36 name and version from | |
37 @type kwargs: dict | |
38 @param kwargs: All further keyword arguments. | |
39 """ | |
40 self.specfile = specfile | |
41 self._pkg_name = None | |
42 self._pkg_version = None | |
43 self._loaded = False | |
44 | |
45 def load(self): | |
46 """ | |
47 call this function after the file exists to populate properties | |
48 """ | |
49 # If we are given a string, open it up else assume it's something we | |
50 # can call read on. | |
51 if type(self.specfile) == self.types.StringType: | |
52 f = open(self.specfile, 'r') | |
53 else: | |
54 f = self.specfile | |
55 | |
56 for line in f: | |
57 if self.v_regex.match(line): | |
58 self._pkg_version = self.v_regex.match(line).group(1) | |
59 if self.n_regex.match(line): | |
60 self._pkg_name = self.n_regex.match(line).group(1) | |
61 f.close() | |
62 self._loaded = True | |
63 | |
64 # Read-only properties | |
65 loaded = property(lambda self: self._loaded) | |
66 pkg_name = property(lambda self: self._pkg_name) | |
67 pkg_version = property(lambda self: self._pkg_version) | |
OLD | NEW |