Support for building with local packages on Debian and Ubuntu

This commit is contained in:
David Murphy 2016-06-21 09:17:50 -06:00
parent 55c22080df
commit 82fa276141

View file

@ -15,8 +15,13 @@ from __future__ import absolute_import, print_function
import errno
import logging
import os
import sys
import tempfile
import shutil
import time
import re
import traceback
## import functools
# Import salt libs
import salt.utils
@ -316,10 +321,6 @@ def make_src_pkg(dest_dir, spec, sources, env=None, template=None, saltenv='base
shutil.copy(full, trgt)
ret.append(trgt)
trgt = os.path.join(dest_dir, os.path.basename(spec_pathfile))
shutil.copy(spec_pathfile, trgt)
ret.append(trgt)
return ret
# obtain name of 'python setup.py sdist' generated tarball, extract the version
@ -406,6 +407,12 @@ def build(runas,
log.error('Failed to make src package')
return ret
cmd = 'pbuilder --create'
__salt__['cmd.run'](cmd, runas=runas, python_shell=True)
# use default /var/cache/pbuilder/result
results_dir = '/var/cache/pbuilder/result'
# dscs should only contain salt orig and debian tarballs and dsc file
for dsc in dscs:
afile = os.path.basename(dsc)
@ -414,26 +421,31 @@ def build(runas,
if dsc.endswith('.dsc'):
dbase = os.path.dirname(dsc)
results_dir = tempfile.mkdtemp()
try:
__salt__['cmd.run']('chown {0} -R {1}'.format(runas, dbase))
__salt__['cmd.run']('chown {0} -R {1}'.format(runas, results_dir))
cmd = 'pbuilder --create'
__salt__['cmd.run'](cmd, runas=runas, python_shell=True)
cmd = 'pbuilder --build --buildresult {1} {0}'.format(
dsc, results_dir)
cmd = 'pbuilder --update --override-config'
__salt__['cmd.run'](cmd, runas=runas, python_shell=True)
cmd = 'pbuilder --build {0}'.format(dsc)
__salt__['cmd.run'](cmd, runas=runas, python_shell=True)
# ignore local deps generated package file
for bfile in os.listdir(results_dir):
full = os.path.join(results_dir, bfile)
bdist = os.path.join(dest_dir, bfile)
shutil.copy(full, bdist)
ret.setdefault('Packages', []).append(bdist)
if bfile != 'Packages':
full = os.path.join(results_dir, bfile)
bdist = os.path.join(dest_dir, bfile)
shutil.copy(full, bdist)
ret.setdefault('Packages', []).append(bdist)
except Exception as exc:
log.error('Error building from {0}: {1}'.format(dsc, exc))
finally:
shutil.rmtree(results_dir)
# remove any Packages file created for local dependency processing
for pkgzfile in os.listdir(dest_dir):
if pkgzfile == 'Packages':
pkgzabsfile = os.path.join(dest_dir, pkgzfile)
os.remove(pkgzabsfile)
shutil.rmtree(dsc_dir)
return ret
@ -612,3 +624,4 @@ def make_repo(repodir, keyid=None, env=None, use_passphrase=False, gnupghome='/e
if use_passphrase and local_keyid is not None:
cmd = '/usr/lib/gnupg2/gpg-preset-passphrase --forget {0}'.format(local_fingerprint)
__salt__['cmd.run'](cmd, runas=runas)