2 Decentralized storage grid.
4 maintainer web site: U{http://allmydata.com/}
6 community web site: U{http://allmydata.org/}
9 __version__ = "unknown"
11 from _version import __version__
13 # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
14 # come with a _version.py, so we don't know what our version is. This should
15 # not happen very often.
18 hush_pyflakes = __version__
22 _auto_deps.require_auto_deps()
24 import platform, re, subprocess
25 _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
26 _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
28 _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
29 _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
31 def get_linux_distro():
32 """ Tries to determine the name of the Linux OS distribution name.
34 First, try to parse a file named "/etc/lsb-release". If it exists, and
35 contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
36 the strings parsed from that file. The reason we try this first is because
37 it is faster than the official method of invoking "lsb_release" (which takes
38 half a second on my high-performance Athlon64 Ubuntu workstation). Also
39 because some distributions (at least Debian/Ubuntu) have /etc/lsb-release in
40 the "base-files" package (Priority: required) but /usr/bin/lsb_release in
41 the "lsb-release" package (Priority: important), so it is possible that
42 /etc/lsb-release is there even if /usr/bin/lsb_release isn't.
44 If parsing /etc/lsb-release doesn't work, then try to execute "lsb_release",
45 as standardized in 2001:
47 http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
49 The current version of the standard is here:
51 http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
53 If executing "lsb_release" raises no exception, and returns exit code 0, and
54 both the "distributor id" and "release" results are non-empty after being
55 stripped of whitespace, then return a two-tuple containing the information
56 that lsb_release emitted, as strings.
58 If that doesn't work, then invoke platform.dist() and return the first two
59 elements of the tuple returned by that function.
61 Returns a tuple (distname,version). Distname is what LSB calls a
62 "distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
65 A version of this has been submitted to python as a patch for the standard
66 library module "platform":
68 http://bugs.python.org/issue3937
74 etclsbrel = open("/etc/lsb-release", "rU")
75 for line in etclsbrel:
76 m = _distributor_id_file_re.search(line)
78 _distname = m.group(1).strip()
79 if _distname and _version:
80 return (_distname, _version)
81 m = _release_file_re.search(line)
83 _version = m.group(1).strip()
84 if _distname and _version:
85 return (_distname, _version)
86 except EnvironmentError:
90 p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
93 for line in p.stdout.readlines():
94 m = _distributor_id_cmdline_re.search(line)
96 _distname = m.group(1).strip()
97 if _distname and _version:
98 return (_distname, _version)
100 m = _release_cmdline_re.search(p.stdout.read())
102 _version = m.group(1).strip()
103 if _distname and _version:
104 return (_distname, _version)
105 except EnvironmentError:
108 return platform.dist()[:2]
111 # Our version of platform.platform(), telling us both less and more than the
112 # Python Standard Library's version does.
113 # We omit details such as the Linux kernel version number, but we add a
114 # more detailed and correct rendition of the Linux distribution and
115 # distribution-version.
116 if "linux" in platform.system().lower():
117 return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
119 return platform.platform()
121 def get_package_versions():
122 import OpenSSL, allmydata, foolscap, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec
125 'pyopenssl': OpenSSL.__version__,
126 'allmydata': allmydata.__version__,
127 'foolscap': foolscap.__version__,
128 'nevow': nevow.__version__,
129 'pycryptopp': pycryptopp.__version__,
130 'setuptools': setuptools.__version__,
131 'simplejson': simplejson.__version__,
132 'twisted': twisted.__version__,
133 'zfec': zfec.__version__,
134 'python': platform.python_version(),
135 'platform': get_platform()
138 def get_package_versions_string():
139 versions = get_package_versions()
141 for p in ["allmydata", "foolscap", "pycryptopp", "zfec", "twisted", "nevow", "python", "platform"]:
142 if versions.has_key(p):
143 res.append(str(p) + ": " + str(versions[p]))
146 res.append(str(p) + ": UNKNOWN")
147 for p, v in versions.iteritems():
148 res.append(str(p) + ": " + str(v))
149 return ', '.join(res)