1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# Fedora Developer Shell
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Authors: Yaakov M. Nemoy <ynemoy@redhat.com>
#
from __future__ import with_statement
from os.path import split
from base.base import log
from base.exceptions import ExecutionException
from base.util import pwd, copy, move
from base.profiles import ver_rel, name
from modules.directory import Directory
class Package(Directory):
_type = 'package'
# These two methods are here as examples.
def load_dir(self, dir):
super(Package, self).load_dir(dir)
def make_dir(self, dir):
super(Package, self).make_dir(dir)
def add_spec(self, spec_file):
log.debug('spec_file is %s' % spec_file)
log.debug('spec_file_name is %s' % self.name + '.spec')
#TODO: get the spec file name, copy
# Then get the actual package name and set pkg_name to the right one
spec_fname = split(spec_file)[1]
with pwd(self.code_dir):
try:
copy(spec_file, spec_fname)
self.cfg['pkg_name'] = name(spec_fname)
if not spec_fname == self.spec_file:
mv(spec_fname, self.spec_file)
except IOError, e:
log.error(str(e))
raise ExecutionException(e, 'spec-file could not be added')
@property
def spec_file(self):
return self.pkg_name + '.spec'
@property
def code_dir(self):
# this is a hack for some refactoring backwards compatibility
#TODO: replace code_dir with just dir
return self.cfg['dir']
@property
def pkg_dir(self):
return self.cfg['pkg_dir']
def get_srpm_name(self, profile):
with pwd(self.code_dir):
ver, rel = ver_rel(self.spec_file, profile.dist_defines())
return '%s-%s-%s.src.rpm' % (self.pkg_name, ver, rel)
def ver(self, profile):
with pwd(self.dir):
ver, rel = ver_rel(self.spec_file, profile.dist_defines() if profile else '')
return ver
def source_dir(self, *args):
raise NotImplementedError
__all__ = ['Package']
|