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

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

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Portions Copyright Buildbot Team Members 
15  # Portions Copyright Dan Radez <dradez+buildbot@redhat.com> 
16  # Portions Copyright Steve 'Ashcrow' Milner <smilner+buildbot@redhat.com> 
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   
25 -class RpmSpec(ShellCommand):
26 """ 27 read parameters out of an rpm spec file 28 """ 29 30 #initialize spec info vars and get them from the spec file 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
49 - def load(self):
50 """ 51 call this function after the file exists to populate properties 52 """ 53 # If we are given a string, open it up else assume it's something we 54 # can call read on. 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 # Read-only properties 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