aboutsummaryrefslogtreecommitdiff
blob: 72c8fe3dc9fca5f17ed9a68ad6a15690980680c1 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 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 os, sys
import os.path as osp
from autotua import fetch, const, sync

class Jobs:
    """Interface to jobs on the master server that we can do"""

    def __init__(self):
        self.pubkey = ''

    def getjobs(self):
        """
        Get a list of jobs
        (skeleton code atm)
        """
        jobs = []
        for job_data in const.job_list:
            jobs.append(Job(job_data))
        return jobs

class Job:
    """A Job."""

    def __init__(self, job_data):
        self.name = job_data['name']
        self.stage = self._stage_fetchable(job_data)
        # This should probably job_data['maintainer']/self.name or something
        # need to quantify the uniqueness of job_data['name']
        self.jobtagedir = osp.join(const.JOBTAGE_DIR, self.name)
        self.jobtagerev = job_data['jobtagerev']
        self.jobuilds = job_data['jobuilds']

    def __repr__(self):
        return '<%s: %s>' % (self.name, 'Job object')

    def __str__(self):
        return '%s object' % self.name

    def _generic_arch(self, arch):
        """
        Convert specific archs to generic archs
        i686 -> x86
        mips4 -> mips
        """
        if arch in ['alpha', 'amd64', 'ia64', 'x86']:
            return arch

        if arch == 'i686':
            return 'x86'
        elif arch == 'sparc64':
            return 'sparc'
        elif arch in ['hppa1.1', 'hppa2.0']:
            return 'hppa'
        elif arch.startswith('mips'):
            return 'mips'
        else:
            sys.exit('Invalid arch: '+arch+'\n')

    def _stage_fetchable(self, job_data):
        stage = job_data['stage']
        if stage.startswith('gentoo://'):
            job_data['stage'] = stage[9:]
            mirrors = const.GENTOO_MIRRORS
        else:
            # Assume it's a proper URL
            return fetch.Fetchable(osp.basename(stage), [stage])

        job_data['gen_arch'] = self._generic_arch(job_data['arch'])
        filename = const.STAGE_FILENAME % job_data
        uri = []
        for mirror in mirrors:
            mirror += "/" + const.STAGE_MIRROR_PATH % job_data
            mirror += "/" + filename
            uri.append(mirror)
        stage = fetch.Fetchable(filename, uri=uri)
        return stage

    # - Get jobuild SRC_URI -> tarball dir
    def fetch(self):
        # Job metadata stuff
        ## Get stage3 (if required)
        fetcher = fetch.Fetcher(const.STAGE_DIR)
        result = fetcher.fetch(self.stage)
        # Sync jobtage tree
        sync.Syncer().sync()
        # Branch local jobtage tree
        sync.Syncer(uri=const.MAIN_JOBTAGE_DIR, destdir=self.jobtagedir, rev=self.jobtagerev).sync()
        ## Read config, get portage snapshot if required
        #self._fetch_portage_snapshot()
        # Jobuild-specific stuff
        ## Get jobuild PORTCONF_URI -> workdir
        #self._fetch_portconf()
        #self._fetch_srcuri()

    def prepare(self):
        pass

    def run(self):
        print "Rheeet, it's running!~ NOT."