'''
Build packages!
'''
# Import python libs
import os


def built(
        name,
        runas,
        dest_dir,
        spec,
        sources,
        template,
        tgt,
        results=None,
        always=False,
        saltenv='base'):
    '''
    Ensure that the named package is built and exists in the named directory
    '''
    ret = {'name': name,
           'changes': {},
           'comment': '',
           'result': True}
    if not always:
        if isinstance(results, str):
            results = results.split(',')
        results = set(results)
        present = set()
        if os.path.isdir(dest_dir):
            for fn_ in os.listdir(dest_dir):
                present.appd(fn_)
        need = results.difference(present)
        if not need:
            ret['comment'] = 'All needed packages exist'
            return ret
    if __opts__['test']:
        ret['comment'] = 'Packages need to be built'
        ret['result'] = None
        return ret
    ret['changes'] = __salt__['pkgbuild.build'](
            runas,
            tgt,
            dest_dir,
            spec,
            sources,
            template,
            saltenv)
    ret['comment'] = 'Packages Built'
    return ret

@@ -1203,20 +1203,570 @@
 ilt'%0A    return ret%0A
+%0A%0Adef repo(name):%0A    '''%0A    Make a package repository, the name is directoty to turn into a repo.%0A    This state is best used with onchanges linked to your package building%0A    states%0A    '''%0A    ret = %7B'name': name,%0A           'changes': %7B%7D,%0A           'comment': '',%0A           'result': True%7D%0A    if __opts__%5B'test'%5D == True:%0A        ret%5B'result'%5D = None%0A        ret%5B'comment'%5D = 'Package repo at %7B0%7D will be rebuilt'.format(name)%0A        return ret%0A    __salt__%5B'pkgbuild.make_repo'%5D(name)%0A    ret%5B'changes'%5D = %7B'refresh': True%7D%0A    return ret%0A

Add initial pkgbuild.repo state