make the spec file fragment a Cheetah template

This commit is contained in:
Mike Bonnet 2008-01-31 19:06:37 -05:00
parent 436efabf21
commit d79fb78a99
3 changed files with 17 additions and 24 deletions

View file

@ -50,6 +50,7 @@ import traceback
import urllib2
import urlparse
import xmlrpclib
import Cheetah.Template
from ConfigParser import ConfigParser
from fnmatch import fnmatch
from optparse import OptionParser
@ -2031,40 +2032,30 @@ class JarWrapperRPMTask(BaseTaskHandler):
koji.ensuredir(scmdir)
specdir = scm.checkout(scmdir, self.getUploadDir(), logfile, use_common=False)
specfile = None
spec_template = None
for path, dir, files in os.walk(specdir):
files.sort()
for filename in files:
if filename.endswith('.spec'):
specfile = os.path.join(path, filename)
if filename.endswith('.spec.tmpl'):
spec_template = os.path.join(path, filename)
break
if not specfile:
raise koji.BuildError, 'no spec file found at URL: %s' % spec_url
if not spec_template:
raise koji.BuildError, 'no spec file template found at URL: %s' % spec_url
jardir = os.path.join(self.workdir, 'jars')
koji.ensuredir(jardir)
sourcelist = ''
installlist = ''
filelist = ''
i = 0
for jarpath in jars:
shutil.copy(jarpath, jardir)
jarname = os.path.basename(jarpath)
# sourcelist += jarname += '\n'
sourcelist += 'Source%i: %s\n' % (i, jarname)
installlist += '/usr/bin/install -m 644 %%{SOURCE%i} $RPM_BUILD_ROOT/usr/share/java\n' % i
filelist += '/usr/share/java/' + jarname + '\n'
i += 1
values = {'sourcelist': sourcelist,
'installlist': installlist,
'filelist': filelist}
values = {'jars': [os.path.basename(jarpath) for jarpath in jars]}
values.update((build or task))
specfd = file(specfile, 'r+')
contents = specfd.read()
contents = contents % values
specfd.seek(0)
contents = Cheetah.Template.Template(file=spec_template, searchList=[values],
filter='EncodeUnicode').respond()
specfile = spec_template[:-5]
specfd = file(specfile, 'w')
specfd.write(contents)
specfd.close()

View file

@ -4674,7 +4674,7 @@ class RootExports(object):
def downloadTaskOutput(self, taskID, fileName, offset=0, size=-1):
"""Download the file with the given name, generated by the task with the
given ID."""
if '..' in fileName or '/' in fileName:
if '..' in fileName:
raise koji.GenericError, 'Invalid file name: %s' % fileName
filePath = '%s/tasks/%i/%s' % (koji.pathinfo.work(), taskID, fileName)
filePath = os.path.normpath(filePath)
@ -6839,8 +6839,9 @@ class HostExports(object):
add_rpm_sig(rpminfo['id'], koji.rip_rpm_sighdr(rpmpath))
for log in logs:
# assume we're only importing noarch packages
import_build_log('%s/tasks/%i/%s' % (koji.pathinfo.work(), wrapper_task_id, log),
build, subdir='wrapper')
build, subdir='noarch')
def failBuild(self, task_id, build_id):
"""Mark the build as failed. If the current state is not

View file

@ -53,6 +53,7 @@ Requires: /usr/bin/svn
Requires: /usr/bin/git
Requires: rpm-build
Requires: redhat-rpm-config
Requires: python-cheetah
%if 0%{?rhel} >= 5
Requires: createrepo >= 0.4.11-2
%endif