aboutsummaryrefslogtreecommitdiff
blob: 6eb934c98a53f9aadd8727821a9423b3b8a0656e (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
# 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(**kwargs):
    scheme = kwargs['stage'].split('://', 1)[0]
    if scheme in schemes:
        return kwargs['stage']
    kwargs['gen_arch'] = _get_arch_dir(kwargs['arch'])
    kwargs['mirror'] = random.choice(const.MIRRORS[scheme])
    url = const.STAGE_URI % kwargs
    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.ARCHSs[i]:
            return i
    raise ValidationError(const.VERRORS['invalid_arch'] % i)