Package buildbot :: Package steps :: Package package :: Package rpm :: Module rpmspec
[frames] | no frames]

Source Code for Module buildbot.steps.package.rpm.rpmspec

 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  import re 
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 #initialize spec info vars and get them from the spec file 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
42 - def load(self):
43 """ 44 call this function after the file exists to populate properties 45 """ 46 # If we are given a string, open it up else assume it's something we 47 # can call read on. 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 # Read-only properties 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