salt/pkg/rpm/build.py

51 lines
1.3 KiB
Python
Raw Normal View History

#! /bin/env python
import sys
import os
import tarfile
2013-11-13 14:49:20 +00:00
import argparse
from os.path import dirname, join, abspath
from shutil import copy
from subprocess import check_call
2013-11-13 14:49:20 +00:00
parser = argparse.ArgumentParser(
2013-12-03 22:54:38 +00:00
description='Build salt rpms',
2013-11-13 14:49:20 +00:00
)
parser.add_argument('buildid',
help='The build id to use i.e. the bit after the salt version in the package name',
2013-11-13 14:49:20 +00:00
)
args = parser.parse_args()
src = abspath(join(dirname(__file__), '../..'))
sys.path.append(src)
import salt.version
salt_version = '.'.join(map(str, salt.version.__version_info__[0:3]))
rpmbuild = join(os.environ['HOME'], 'rpmbuild')
copy(join(src, 'pkg/rpm/salt.spec'), join(rpmbuild, 'SPECS'))
for f in os.listdir(join(src, 'pkg/rpm')):
if f in ['salt.spec', 'build']:
continue
copy(join(src, 'pkg/rpm', f), join(rpmbuild, 'SOURCES'))
def srcfilter(ti):
2013-11-13 14:49:20 +00:00
if '/.git' in ti.name:
return None
return ti
with tarfile.open(join(rpmbuild, 'SOURCES/salt-%s.tar.gz' % salt_version), 'w|gz') as tf:
2013-12-03 22:54:38 +00:00
tf.add(src, arcname='salt-%s' % salt_version,
filter=srcfilter)
cmd = ['rpmbuild', '-bb',
'--define=salt_version %s' % salt_version,
2013-11-13 14:49:20 +00:00
'--define=buildid %s' % args.buildid,
'salt.spec']
print('Executing: %s' % ' '.join('"%s"' % c for c in cmd))
2013-12-03 22:54:38 +00:00
check_call(cmd, cwd=join(rpmbuild, 'SPECS'))