Exemplo n.º 1
0
Arquivo: cache.py Projeto: leeming/ybd
def update_manifest(defs, this, manifest):
    this = defs.get(this)
    with open(manifest, "a") as m:
        if manifest.endswith('text'):
            format = '%s %s %s %s %s %s\n'
            m.write(format %
                    (this['name'], this['cache'],
                     get_repo_url(this.get('repo', 'None')),
                     this.get('ref', 'None'), this.get(
                         'unpetrify-ref', 'None'), md5(get_cache(defs, this))))
            m.flush()
            return

        text = {
            'name': this['name'],
            'summary': {
                'artifact': this['cache'],
                'repo': get_repo_url(this.get('repo', None)),
                'sha': this.get('ref', None),
                'ref': this.get('unpetrify-ref', None),
                'md5': md5(get_cache(defs, this))
            }
        }
        m.write(yaml.dump(text, default_flow_style=True))
        m.flush()
Exemplo n.º 2
0
def cache_key(dn):
    if dn is None:
        app.log(dn, 'No definition found for', dn, exit=True)

    if type(dn) is not dict:
        dn = app.defs.get(dn)

    if dn.get('cache') == 'calculating':
        app.log(dn, 'Recursion loop for', dn, exit=True)

    if dn.get('cache'):
        return dn['cache']

    if dn.get('arch', app.config['arch']) != app.config['arch']:
        if 'tried' not in dn:
            dn['tried'] = True
            app.log(dn, 'No cache_key for arch %s mismatch' % dn['arch'],
                    app.config['arch'])
        return False

    dn['cache'] = 'calculating'

    key = 'no-build'
    if app.config.get('mode', 'normal') in ['keys-only', 'normal']:
        if dn.get('repo'):
            if not dn.get('tree'):
                dn['tree'], dn['sha'] = get_tree(dn)
            if not dn.get('repourl'):
                dn['repourl'] = get_repo_url(dn.get('repo'))
        factors = hash_factors(dn)
        factors = json.dumps(factors, sort_keys=True).encode('utf-8')
        key = hashlib.sha256(factors).hexdigest()

    dn['cache'] = dn['name'] + "." + key

    app.config['total'] += 1
    x = 'x'
    if not get_cache(dn):
        x = ' '
        app.config['tasks'] += 1

    if dn.get('kind', 'chunk') == 'chunk':
        app.config['chunks'] += 1
    if dn.get('kind', 'chunk') == 'stratum':
        app.config['strata'] += 1
    if dn.get('kind', 'chunk') == 'system':
        app.config['systems'] += 1

    app.log('CACHE-KEYS', '[%s]' % x, dn['cache'])
    if app.config.get('manifest', False):
        update_manifest(dn, app.config['manifest'])

    if 'keys' in app.config:
        app.config['keys'] += [dn['cache']]
    return dn['cache']
Exemplo n.º 3
0
def update_manifest(dn, manifest):
    with open(manifest, "a") as m:
        if manifest.endswith('text'):
            format = '%s %s %s %s %s %s\n'
            m.write(format % (dn['name'], dn['cache'],
                              get_repo_url(dn.get('repo', 'None')),
                              dn.get('ref', 'None'),
                              dn.get('unpetrify-ref', 'None'),
                              md5(get_cache(dn))))
            m.flush()
            return

        text = {'name': dn['name'],
                'summary': {'artifact': dn['cache'],
                            'repo': get_repo_url(dn.get('repo', None)),
                            'sha': dn.get('ref', None),
                            'ref': dn.get('unpetrify-ref', None),
                            'md5': md5(get_cache(dn))}}
        m.write(yaml.dump(text, default_flow_style=True))
        m.flush()
Exemplo n.º 4
0
def ccache_mounts(this, ccache_target):
    if app.config['no-ccache'] or 'repo' not in this:
        mounts = []
    else:
        name = os.path.basename(get_repo_url(this['repo']))

        ccache_dir = os.path.join(app.config['ccache_dir'], name)
        if not os.path.isdir(ccache_dir):
            os.mkdir(ccache_dir)

        mounts = [(ccache_dir, ccache_target, None, 'bind')]
    return mounts
Exemplo n.º 5
0
def ccache_mounts(this, ccache_target):
    if app.config["no-ccache"] or "repo" not in this:
        mounts = []
    else:
        name = os.path.basename(get_repo_url(this["repo"]))

        ccache_dir = os.path.join(app.config["ccache_dir"], name)
        if not os.path.isdir(ccache_dir):
            os.mkdir(ccache_dir)

        mounts = [(ccache_dir, ccache_target, None, "bind")]
    return mounts
Exemplo n.º 6
0
def ccache_mounts(this, ccache_target):
    if app.config['no-ccache'] or 'repo' not in this:
        mounts = []
    else:
        name = os.path.basename(get_repo_url(this['repo']))

        ccache_dir = os.path.join(app.config['ccache_dir'], name)
        if not os.path.isdir(ccache_dir):
            os.mkdir(ccache_dir)

        mounts = [(ccache_dir, ccache_target, None, 'bind')]
    return mounts
Exemplo n.º 7
0
def ccache_mounts(dn, ccache_target):
    if app.config['no-ccache'] or 'repo' not in dn:
        mounts = []
    else:
        name = os.path.basename(get_repo_url(dn['repo']))
        if name.endswith('.git'):
            name = name[:-4]
        ccache_dir = os.path.join(app.config['ccache_dir'], name)
        if not os.path.isdir(ccache_dir):
            os.mkdir(ccache_dir)

        mounts = [(ccache_dir, ccache_target, None, 'bind')]
    return mounts
Exemplo n.º 8
0
def ccache_mounts(dn, ccache_target):
    if app.config['no-ccache'] or 'repo' not in dn:
        mounts = []
    else:
        name = os.path.basename(get_repo_url(dn['repo']))
        if name.endswith('.git'):
            name = name[:-4]
        ccache_dir = os.path.join(app.config['ccache_dir'], name)
        if not os.path.isdir(ccache_dir):
            os.mkdir(ccache_dir)

        mounts = [(ccache_dir, ccache_target, None, 'bind')]
    return mounts
Exemplo n.º 9
0
def inputs(defs, target):
    resources = []
    target = defs.get(target)
    for it in target.get('contents', []) + target.get('build-depends', []):
        resource = {}
        component = defs.get(it)
        resource['name'] = component['name']
        if component.get('repo'):
            resource['type'] = 'git'
            uri = repos.get_repo_url(component['repo'])
            source = dict(uri=uri, branch=component['ref'])
            source = dict(uri=uri, branch='master')
            resource['source'] = source
        resources += [resource]
    return resources
Exemplo n.º 10
0
def get_binds(this):
    if app.settings['no-ccache']:
        binds = ()
    else:
        name = os.path.basename(get_repo_url(this['repo']))
        ccache_dir = os.path.join(app.settings['ccache_dir'], name)
        ccache_target = os.path.join(this['assembly'],
                                     os.environ['CCACHE_DIR'].lstrip('/'))
        if not os.path.isdir(ccache_dir):
            os.mkdir(ccache_dir)
        if not os.path.isdir(ccache_target):
            os.mkdir(ccache_target)
        binds = ((ccache_dir, ccache_target),)

    return binds
Exemplo n.º 11
0
def inputs(defs, target):
    target = defs.get(target)
    resources = []
    for it in target.get('contents', []) + target.get('build-depends', []):
        component = defs.get(it)
        if component.get('repo'):
            resource = {'name': component['name'],
                        'type': 'git',
                        'source': {'uri': get_repo_url(component['repo']),
                                   'branch': component['ref']}}
        else:
            resource = {'name': component['name'], 'type': 'foo'}

        resources += [resource]
    return resources
Exemplo n.º 12
0
def inputs(defs, target):
    target = defs.get(target)
    resources = []
    for it in target.get('contents', []) + target.get('build-depends', []):
        component = defs.get(it)
        if component.get('repo'):
            resource = {
                'name': component['name'],
                'type': 'git',
                'source': {
                    'uri': get_repo_url(component['repo']),
                    'branch': component['ref']
                }
            }
        else:
            resource = {'name': component['name'], 'type': 'foo'}

        resources += [resource]
    return resources