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   
15  from buildbot.steps.shell import ShellCommand 
16   
17   
19      """ 
20      read parameters out of an rpm spec file 
21      """ 
22   
23      import re 
24      import types 
25   
26       
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   
46          """ 
47          call this function after the file exists to populate properties 
48          """ 
49           
50           
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       
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) 
 68