aboutsummaryrefslogtreecommitdiff
blob: 75d86b38a9c9f9e8ac9b1edbc75988eeada4c703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# vim: set sw=4 sts=4 et :
# Copyright: 2008 Gentoo Foundation
# Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
# License: GPL-2
#
# Immortal lh!
#

import random
from autotua import jobuild, sync

schemes = ['http', 'https', 'ftp']

def generate_stage_url(job):
    scheme, stage = job.stage.split('://', 1)
    if scheme in schemes:
        return job.stage
    else:
        job.stage = stage
    job.gen_arch = _get_arch_dir(job.arch)
    job.mirror = random.choice(const.MIRRORS[scheme])
    url = const.STAGE_URI % job.__dict__
    return url

def _get_arch_dir(arch):
    """
    Convert specific archs to generic archs
    i686 -> x86
    mips4 -> mips
    """
    for i in const.ARCHS:
        if arch in const.ARCHS[i]:
            return i
    raise Exception(const.VERRORS['invalid_arch'] % i)

def _get_deplist(atoms, rev):
    """
    Use autotua-slave to get the deplist 
    from the root jobuild atom

    Support multiple atoms for the multiple-save case
    """
    # FIXME: Re-implement using git-fuse?
    jobtagedir = '%s/jobtage-%s' % (const.TMPDIR, random.randint(0, 99999))
    sync.Syncer(scheme='git-export', uri=const.JOBTAGE, destdir=jobtagedir).sync()

    deplist = []
    for atom in atoms:
        resolver = jobuild.Resolver(jobuild.Jobuild(jobtagedir, atom))
        deplist.extend(resolver.resolve())
    # jobuild.Resolver._unique() reverses the list; hence reverse in advance
    deplist.reverse()
    return jobuild.Resolver(None)._unique(deplist) # Fake jobuild.Resolver to get at _unique ;p