~lidaobing/ubuntu-tweak/ubuntu-ubuntu-tweak

« back to all changes in this revision

Viewing changes to ubuntutweak/common/systeminfo.py

  • Committer: LI Daobing
  • Date: 2010-07-31 10:10:26 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: lidaobing@gmail.com-20100731101026-9o3m59258q5perbo
Tags: upstream-0.5.5
ImportĀ upstreamĀ versionĀ 0.5.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
# Ubuntu Tweak - PyGTK based desktop configure tool
 
3
# Ubuntu Tweak - PyGTK based desktop configuration tool
4
4
#
5
5
# Copyright (C) 2007-2008 TualatriX <tualatrix@gmail.com>
6
6
#
33
33
    description = "GNOME %s.%s.%s (%s %s)" % (platform, minor, micro, distributor, date)
34
34
 
35
35
def parse_codename():
36
 
    data = open('/etc/lsb-release').read()
37
 
    dict = {}
38
 
    for line in data.split('\n'):
39
 
        try:
40
 
            key, value = line.split('=')
41
 
            dict[key] = value
42
 
        except:
43
 
            pass
44
 
    return dict['DISTRIB_CODENAME']
 
36
    try:
 
37
        codename = os.popen('lsb_release -cs').read().strip()
 
38
        if codename in ['karmic', 'helena', 'Helena']:
 
39
            return 'karmic'
 
40
        elif codename in ['lucid', 'isadora', 'Isadora']:
 
41
            return 'lucid'
 
42
        elif codename in ['maverick']:
 
43
            return 'maverick'
 
44
    except:
 
45
        pass
 
46
    return ''
45
47
 
46
48
def parse_distro():
47
49
    return file('/etc/issue.net').readline()[:-1]
60
62
    distro = DistroInfo.distro
61
63
 
62
64
class module_check:
 
65
    codename = DistroInfo.codename
 
66
    distribution = DistroInfo.distro
 
67
 
63
68
    @classmethod
64
69
    def has_apt(cls):
65
70
        try:
73
78
        try:
74
79
            import ccm
75
80
            return True
76
 
        except ImportError:
 
81
        except:
77
82
            return False
78
83
 
79
84
    @classmethod
97
102
        return int(GnomeVersion.minor)
98
103
 
99
104
    @classmethod
100
 
    def is_ubuntu(cls):
101
 
        return cls.is_karmic()
102
 
 
103
 
    @classmethod
104
105
    def is_supported_ubuntu(cls):
105
 
        return cls.is_karmic()
 
106
        return cls.codename in ['karmic', 'lucid', 'maverick']
106
107
 
107
108
    @classmethod
108
109
    def get_supported_ubuntu(cls):
109
 
        return ['karmic', 'helena', 'Helena']
110
 
 
111
 
    @classmethod
112
 
    def is_karmic(cls):
113
 
        return DistroInfo.codename in ['karmic']
 
110
        return ['karmic', 'lucid', 'maverick']
114
111
 
115
112
    @classmethod
116
113
    def get_codename(cls):
117
 
        '''Return the unique code name, e.g. no matter hardy or elyssa, return hardy'''
118
 
        if cls.is_karmic():
119
 
            return 'karmic'
 
114
        return cls.codename
 
115
 
 
116
    @classmethod
 
117
    def is_ubuntu(cls, distro):
 
118
        if type(distro) == list:
 
119
            for dis in distro:
 
120
                if dis in cls.get_supported_ubuntu():
 
121
                    return True
 
122
                return False
120
123
        else:
121
 
            return ''
 
124
            if distro in cls.get_supported_ubuntu():
 
125
                return True
 
126
            return False
122
127
 
123
 
    @classmethod
124
 
    def is_gnome(cls):
125
 
        return os.getenv('GDMSESSION') and os.getenv('GDM_LANG')
126
 
            
127
128
if __name__ == "__main__":
128
129
    print SystemInfo.distro
129
130
    print 'has pat', module_check.has_apt()