aboutsummaryrefslogtreecommitdiff
blob: aad5d204724c5d921ed7db118f5e93634c112e22 (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
#!/usr/bin/env python

import glob
import os
import re
import shutil
import urllib.request

from grs.Constants import CONST
from grs.Execute import Execute
from grs.Rotator import Rotator


class Seed(Rotator):
    """ doc here
        more doc
    """

    def __init__(self, stage_uri, tmpdir = CONST.TMPDIR, portage_configroot = \
            CONST.PORTAGE_CONFIGROOT, package = CONST.PACKAGE, logfile = CONST.LOGFILE):
        """ doc here
            more doc
        """
        self.stage_uri = stage_uri
        self.portage_configroot = portage_configroot
        self.package = package
        filename = os.path.basename(stage_uri)
        self.filepath = os.path.join(tmpdir, filename)
        self.logfile = logfile


    def seed(self):
        """ doc here
            more doc
        """
        # Rotate the old portage_configroot and package out of the way
        for directory in [self.portage_configroot, self.package]:
            self.rotate(directory)
            if os.path.isdir(directory):
                shutil.move(directory, '%s.0' % directory)
            os.makedirs(directory, mode=0o755, exist_ok=False)

        # Download a stage tarball if we don't have one
        if not os.path.isfile(self.filepath):
            request = urllib.request.urlopen(self.stage_uri)
            with open(self.filepath, 'wb') as f:
                shutil.copyfileobj(request, f)

        # Because python's tarfile sucks
        cmd = 'tar --xattrs -xf %s -C %s' % (self.filepath, self.portage_configroot)
        Execute(cmd, timeout=120, logfile=self.logfile)
        #os.unlink(self.filepath)