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

class Environment(object):

    def __init__(self):
        self.portdir = portage.settings['PORTDIR']

    def getVar(self, myvar):
        return portage.settings[myvar]

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

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

    def getProfile(self):
        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