aboutsummaryrefslogtreecommitdiff
blob: 913265a695b740d2efca3d19229ad6279263101a (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
import logging
import os
import platform
import portage
from _emerge.actions import relative_profile_path

class Environment(object):
    """
    A class encapsulating all environment and portage variable providers
    """

    def __init__(self):
        """
        Initialize the class and portdir
        """
        self.portdir = portage.settings['PORTDIR']

    def getVar(self, myvar):
        """
        Return the value of a portage variable
        """
        return portage.settings[myvar]

    def getPlatform(self):
        """
        Return host platform
        """
        return platform.platform(aliased=1)

    def getLastSync(self):
        """
        Return portage tree last sync time
        """
        lastsync = None
        try:
            lastsync = portage.grabfile(os.path.join(self.portdir, 'metadata', 'timestamp.chk'))
        except portage.exception.PortageException:
            pass
        if not lastsync or lastsync is None:
            return 'Unknown'
        return lastsync[0]

    def getProfile(self):
        """
        Return selected portage profile
        """
        profilever = None
        profile = portage.settings.profile_path
        if profile:
            profilever = relative_profile_path(self.portdir, profile)
            if profilever is None:
                try:
                    for parent in portage.grabfile(os.path.join(profile, 'parent')):
                        profilever = relative_profile_path(self.portdir, os.path.join(profile, parent))
                        if profilever is not None:
                            break
                except portage.exception.PortageException:
                    pass

                if profilever is None:
                    try:
                        profilever = '!' + os.readlink(profile)
                    except (OSError):
                        pass

        if profilever is None:
            profilever = 'Unknown'

        return profilever