def build(runas,
          tgt,
          dest_dir,
          spec,
          sources,
          deps,
          env,
          template,
          saltenv='base',
          log_dir='/var/log/salt/pkgbuild'):  # pylint: disable=unused-argument
    '''
    Given the package destination directory, the tarball containing debian files (e.g. control)
    and package sources, use pbuilder to safely build the platform package

    CLI Example:

    Debian
        salt '*' pkgbuild.make_src_pkg deb-8-x86_64 /var/www/html https://raw.githubusercontent.com/saltstack/libnacl/master/pkg/deb/python-libnacl.control https://pypi.python.org/packages/source/l/libnacl/libnacl-1.3.5.tar.gz

    This example command should build the libnacl package for Debian using pbuilder
    and place it in /var/www/html/ on the minion
    '''
    ret = {}
    try:
        os.makedirs(dest_dir)
    except __HOLE__ as exc:
        if exc.errno != errno.EEXIST:
            raise
    dsc_dir = tempfile.mkdtemp()
    try:
        dscs = make_src_pkg(dsc_dir, spec, sources, env, template, saltenv)
    except Exception as exc:
        shutil.rmtree(dsc_dir)
        log.error('Failed to make src package')
        return ret

    # dscs should only contain salt orig and debian tarballs and dsc file
    for dsc in dscs:
        afile = os.path.basename(dsc)
        adist = os.path.join(dest_dir, afile)
        shutil.copy(dsc, adist)

        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)
                __salt__['cmd.run'](cmd, runas=runas, python_shell=True)

                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)
            except Exception as exc:
                log.error('Error building from {0}: {1}'.format(dsc, exc))
            finally:
                shutil.rmtree(results_dir)
    shutil.rmtree(dsc_dir)
    return ret
dataset/ETHPy150Open saltstack/salt/salt/modules/debbuild.py/build