1
2
3
4 import commands
5 import os
6
7 import distutils.version
8
9 from moap.util import log
10
11 """
12 Figure out what distribution, architecture and version the user is on.
13 """
14
16 """
17 @cvar description: a longer human-readable name for the distro
18 @type description: str
19 @cvar distributor: a short lower-case identifier for the distro
20 @type distributor: str
21 @cvar release: the version of the distro
22 @type release: str
23 @cvar arch: the architecture of the distro
24 @type arch: str
25 """
26 description = None
27 distributor = None
28 release = None
29 arch = None
30
31 - def __init__(self, description, distributor, release, arch):
36
38 """
39 @param release: release to compare with
40 @type release: str
41
42 Returns: whether the distro is at least as new as the given release,
43 taking non-numbers into account.
44 """
45 mine = distutils.version.LooseVersion(self.release)
46 theirs = distutils.version.LooseVersion(release)
47 return mine >= theirs
48
50 """
51 Get the system name. Typically the first item in the os.uname tuple.
52 """
53 return os.uname()[1]
54
56 """
57 Get the machine architecture. Typically the fifth item in os.uname.
58 """
59 return os.uname()[4]
60
62 """
63 Decide on the distro based on the presence of a distro-specific release
64 file.
65
66 rtype: L{Distro} or None.
67 """
68
69 output = commands.getoutput("lsb_release -i")
70 if output and output.startswith('Distributor ID:'):
71 distributor = output.split(':', 2)[1].strip()
72 output = commands.getoutput("lsb_release -d")
73 description = output.split(':', 2)[1].strip()
74 output = commands.getoutput("lsb_release -r")
75 release = output.split(':', 2)[1].strip()
76
77 return Distro(description, distributor, release, None)
78