2007-04-19 20:47:59 +00:00
|
|
|
"""
|
2007-04-30 20:06:09 +00:00
|
|
|
Decentralized storage grid.
|
2007-04-19 20:47:59 +00:00
|
|
|
|
|
|
|
maintainer web site: U{http://allmydata.com/}
|
|
|
|
|
|
|
|
community web site: U{http://allmydata.org/}
|
|
|
|
"""
|
|
|
|
|
2007-05-04 03:14:07 +00:00
|
|
|
__version__ = "unknown"
|
|
|
|
try:
|
2007-08-16 21:09:30 +00:00
|
|
|
from _version import __version__
|
2007-05-04 03:14:07 +00:00
|
|
|
except ImportError:
|
2008-01-22 17:22:51 +00:00
|
|
|
# We're running in a tree that hasn't run "./setup.py darcsver", and didn't
|
|
|
|
# come with a _version.py, so we don't know what our version is. This should
|
|
|
|
# not happen very often.
|
2007-05-04 03:14:07 +00:00
|
|
|
pass
|
2007-04-19 20:47:59 +00:00
|
|
|
|
2007-05-04 03:14:07 +00:00
|
|
|
hush_pyflakes = __version__
|
|
|
|
del hush_pyflakes
|
2007-04-19 20:47:59 +00:00
|
|
|
|
2008-04-30 20:22:04 +00:00
|
|
|
import _auto_deps
|
|
|
|
_auto_deps.require_auto_deps()
|
2008-01-23 00:42:54 +00:00
|
|
|
|
2008-09-22 23:53:54 +00:00
|
|
|
import platform, re, subprocess
|
2008-09-23 16:28:58 +00:00
|
|
|
_distributor_id_cmdline_re = re.compile("(?:Distributor ID)?:?\s*(.*)", re.I)
|
|
|
|
_release_cmdline_re = re.compile("(?:Release)?:?\s*(.*)", re.I)
|
|
|
|
|
|
|
|
_distributor_id_file_re = re.compile("(?:DISTRIB_ID.*=)?\s*(.*)", re.I)
|
|
|
|
_release_file_re = re.compile("(?:DISTRIB_RELEASE.*=)?\s*(.*)", re.I)
|
2008-08-28 22:04:54 +00:00
|
|
|
|
2008-09-22 23:53:54 +00:00
|
|
|
def get_linux_distro():
|
|
|
|
""" Tries to determine the name of the Linux OS distribution name.
|
|
|
|
|
|
|
|
The function tries to execute "lsb_release", as standardized in 2001:
|
|
|
|
|
|
|
|
http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
|
|
|
|
|
|
|
|
The current version of the standard is here:
|
|
|
|
|
|
|
|
http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
|
|
|
|
|
2008-09-23 15:48:20 +00:00
|
|
|
If executing "lsb_release" raises no exception, and returns exit code 0, and
|
|
|
|
both the "distributor id" and "release" results are non-empty after being
|
|
|
|
stripped of whitespace, then return a two-tuple containing the information
|
2008-09-23 16:28:58 +00:00
|
|
|
that lsb_release emitted, as strings. Why do we execute lsb_release as our
|
|
|
|
first strategy? Because it is the standard.
|
|
|
|
|
|
|
|
If executing "lsb_release" doesn't work, then try to parse a file named
|
|
|
|
/etc/lsb-release to get the same information. Why do that? Because some
|
|
|
|
distributions (at least Debian/Ubuntu) have /etc/lsb-release in the
|
|
|
|
"base-files" package (Priority: required) but /usr/bin/lsb_release in the
|
|
|
|
"lsb-release" package (Priority: important), so it is possible that
|
|
|
|
/etc/lsb-release is there even if /usr/bin/lsb_release isn't.
|
|
|
|
|
|
|
|
If that doesn't work, then invoke platform.dist() and return the first two
|
|
|
|
elements of the tuple returned by that function.
|
2008-08-28 22:04:54 +00:00
|
|
|
|
2008-09-22 23:53:54 +00:00
|
|
|
Returns a tuple (distname,version). Distname is what LSB calls a
|
|
|
|
"distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
|
|
|
|
e.g. "8.04".
|
|
|
|
|
|
|
|
A version of this has been submitted to python as a patch for the standard
|
|
|
|
library module "platform":
|
|
|
|
|
|
|
|
http://bugs.python.org/issue3937
|
|
|
|
"""
|
2008-09-23 16:28:58 +00:00
|
|
|
_distname = None
|
|
|
|
_version = None
|
2008-01-05 03:53:41 +00:00
|
|
|
try:
|
2008-09-22 23:53:54 +00:00
|
|
|
p = subprocess.Popen(["lsb_release", "--id"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
rc = p.wait()
|
|
|
|
if rc == 0:
|
2008-09-23 16:28:58 +00:00
|
|
|
m = _distributor_id_cmdline_re.search(p.stdout.read())
|
2008-09-22 23:53:54 +00:00
|
|
|
if m:
|
|
|
|
_distname = m.group(1).strip()
|
|
|
|
|
|
|
|
p = subprocess.Popen(["lsb_release", "--release"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
rc = p.wait()
|
|
|
|
if rc == 0:
|
2008-09-23 16:28:58 +00:00
|
|
|
m = _release_cmdline_re.search(p.stdout.read())
|
2008-09-22 23:53:54 +00:00
|
|
|
if m:
|
|
|
|
_version = m.group(1).strip()
|
|
|
|
except EnvironmentError:
|
2008-01-05 03:53:41 +00:00
|
|
|
pass
|
2008-09-22 23:53:54 +00:00
|
|
|
|
2008-09-23 15:48:20 +00:00
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
2008-09-23 16:28:58 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
etclsbrel = open("/etc/lsb-release", "rU")
|
2008-09-23 16:55:51 +00:00
|
|
|
for line in etclsbrel:
|
|
|
|
m = _distributor_id_file_re.search(line)
|
2008-09-23 16:28:58 +00:00
|
|
|
if m:
|
|
|
|
_distname = m.group(1).strip()
|
2008-09-23 16:55:51 +00:00
|
|
|
m = _release_file_re.search(line)
|
2008-09-23 16:28:58 +00:00
|
|
|
if m:
|
|
|
|
_version = m.group(1).strip()
|
|
|
|
except EnvironmentError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
|
|
|
|
|
|
|
return platform.dist()[:2]
|
2008-09-22 23:53:54 +00:00
|
|
|
|
|
|
|
def get_platform():
|
|
|
|
# Our version of platform.platform(), telling us both less and more than the
|
|
|
|
# Python Standard Library's version does.
|
|
|
|
# We omit details such as the Linux kernel version number, but we add a
|
|
|
|
# more detailed and correct rendition of the Linux distribution and
|
|
|
|
# distribution-version.
|
|
|
|
if "linux" in platform.system().lower():
|
|
|
|
return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
|
|
|
|
else:
|
|
|
|
return platform.platform()
|
|
|
|
|
|
|
|
def get_package_versions():
|
|
|
|
import OpenSSL, allmydata, foolscap, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec
|
|
|
|
|
2007-12-13 02:37:37 +00:00
|
|
|
return {
|
|
|
|
'pyopenssl': OpenSSL.__version__,
|
|
|
|
'allmydata': allmydata.__version__,
|
|
|
|
'foolscap': foolscap.__version__,
|
|
|
|
'nevow': nevow.__version__,
|
|
|
|
'pycryptopp': pycryptopp.__version__,
|
2008-09-22 23:53:54 +00:00
|
|
|
'setuptools': setuptools.__version__,
|
2007-12-13 02:37:37 +00:00
|
|
|
'simplejson': simplejson.__version__,
|
|
|
|
'twisted': twisted.__version__,
|
|
|
|
'zfec': zfec.__version__,
|
2008-09-22 23:53:54 +00:00
|
|
|
'python': platform.python_version(),
|
|
|
|
'platform': get_platform()
|
2007-12-13 02:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def get_package_versions_string():
|
|
|
|
versions = get_package_versions()
|
|
|
|
res = []
|
2008-09-22 23:53:54 +00:00
|
|
|
for p in ["allmydata", "foolscap", "pycryptopp", "zfec", "twisted", "nevow", "python", "platform"]:
|
2007-12-13 02:37:37 +00:00
|
|
|
if versions.has_key(p):
|
|
|
|
res.append(str(p) + ": " + str(versions[p]))
|
|
|
|
del versions[p]
|
|
|
|
else:
|
|
|
|
res.append(str(p) + ": UNKNOWN")
|
|
|
|
for p, v in versions.iteritems():
|
|
|
|
res.append(str(p) + ": " + str(v))
|
|
|
|
return ', '.join(res)
|