Changeset 250 for trunk/moap/util/distro.py
- Timestamp:
- 25-05-07 15:27:31 (6 years ago)
- File:
-
- 1 edited
-
trunk/moap/util/distro.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/moap/util/distro.py
r231 r250 2 2 # vi:si:et:sw=4:sts=4:ts=4 3 3 4 import commands 4 5 import os 5 import re6 6 7 7 import distutils.version … … 15 15 class Distro: 16 16 """ 17 @cvar tag: a short lower-case identifierfor the distro18 @type tag:str19 @cvar name: a longer human-readable namefor the distro20 @type name:str21 @cvar version:the version of the distro22 @type version:str23 @cvar arch: the architecture of the distro24 @type arch: str17 @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 25 """ 26 tag= None27 name= None28 version= None26 description = None 27 distributor = None 28 release = None 29 29 arch = None 30 30 31 def __init__(self, tag, name, version, arch):32 self. tag = tag33 self. name = name34 self. version = version31 def __init__(self, description, distributor, release, arch): 32 self.description = description 33 self.distributor = distributor 34 self.release = release 35 35 self.arch = arch 36 36 37 def atLeast(self, version):37 def atLeast(self, release): 38 38 """ 39 @param version: versionto compare with40 @type version: str39 @param release: release to compare with 40 @type release: str 41 41 42 Returns: whether the distro is at least as new as the given version,42 Returns: whether the distro is at least as new as the given release, 43 43 taking non-numbers into account. 44 44 """ 45 mine = distutils.version.LooseVersion(self. version)46 theirs = distutils.version.LooseVersion( version)45 mine = distutils.version.LooseVersion(self.release) 46 theirs = distutils.version.LooseVersion(release) 47 47 return mine >= theirs 48 48 … … 66 66 rtype: L{Distro} or None. 67 67 """ 68 # note: keep redhat-release towards the end, since mandrake has it too (sic) 69 # it's a tuple of tuples so we conserve the order 70 mappings = ( 71 ('/etc/fedora-release', 'fedora'), 72 ('/etc/mandrake-release', 'mandriva'), 73 ('/etc/mandriva-release', 'mandriva'), 74 ('/etc/mandrakelinux-release', 'mandriva'), 75 ('/etc/SuSE-release', 'suse'), 76 ('/etc/novell-release', 'suse'), 77 ('/etc/redhat-release', 'redhat'), 78 ('/etc/debian_version', 'debian'), 79 ('/etc/netware-release', 'netware'), 80 ('/etc/slackware-version', 'slackware'), 81 ('/etc/yellowdog-release', 'yellowdog'), 82 ) 68 # start with lsb_release 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() 83 76 84 for path, distro in mappings: 85 if os.path.exists(path): 86 log.debug('distro', "Found release file %s" % path) 87 h = open(path) 88 contents = h.read() 89 h.close() 90 version = None 91 f = '_%s_getNameVersionFromRelease' % distro 92 if f in globals().keys(): 93 log.debug('distro', "Found version function %r" % f) 94 name, version = globals()[f](contents) 95 return Distro(distro, name, version, None) 96 97 return None 98 99 # distro-specific name and version getters 100 # each getter should return a list of [full name, version] 101 def _fedora_getNameVersionFromRelease(contents): 102 matcher = re.compile("^(Fedora Core) release (\d+) .*") 103 m = matcher.search(contents) 104 if m: 105 log.debug('distro', "Found fedora version") 106 return (m.expand("\\1"), m.expand("\\2")) 107 108 log.debug('distro', "Did not find fedora version") 109 return None 77 return Distro(description, distributor, release, None)
Note: See TracChangeset
for help on using the changeset viewer.
