1
0

build.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #! /bin/env python
  2. from __future__ import print_function
  3. import sys
  4. import os
  5. import tarfile
  6. import argparse
  7. from os.path import dirname, join, abspath
  8. from shutil import copy
  9. from subprocess import check_call
  10. parser = argparse.ArgumentParser(
  11. description='Build salt rpms',
  12. )
  13. parser.add_argument('buildid',
  14. help='The build id to use i.e. the bit after the salt version in the package name',
  15. )
  16. args = parser.parse_args()
  17. src = abspath(join(dirname(__file__), '../..'))
  18. sys.path.append(src)
  19. import salt.version
  20. salt_version = salt.version.__saltstack_version__.string
  21. rpmbuild = join(os.environ['HOME'], 'rpmbuild')
  22. copy(join(src, 'pkg/rpm/salt.spec'), join(rpmbuild, 'SPECS'))
  23. for f in os.listdir(join(src, 'pkg/rpm')):
  24. if f in ['salt.spec', 'build.py']:
  25. continue
  26. copy(join(src, 'pkg/rpm', f), join(rpmbuild, 'SOURCES'))
  27. def srcfilter(ti):
  28. if '/.git' in ti.name:
  29. return None
  30. return ti
  31. with tarfile.open(join(rpmbuild, 'SOURCES/salt-%s.tar.gz' % salt_version), 'w|gz') as tf:
  32. tf.add(src, arcname='salt-%s' % salt_version,
  33. filter=srcfilter)
  34. cmd = ['rpmbuild', '-bb',
  35. '--define=salt_version %s' % salt_version,
  36. '--define=buildid %s' % args.buildid,
  37. 'salt.spec']
  38. print('Executing: %s' % ' '.join('"%s"' % c for c in cmd))
  39. check_call(cmd, cwd=join(rpmbuild, 'SPECS'))