aboutsummaryrefslogtreecommitdiff
blob: 2997d7d1c587ed6b5bb8006cdc7383d29443f086 (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
# 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 django.core.validators import ValidationError
import const, validate

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 ValidationError(const.VERRORS['invalid_arch'] % i)