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
|
|
|
|
2009-01-19 22:04:35 +00:00
|
|
|
import os, platform, re, subprocess, sys
|
2008-09-23 17:14:31 +00:00
|
|
|
_distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
|
|
|
|
_release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
|
2008-09-23 16:28:58 +00:00
|
|
|
|
2008-09-23 17:14:31 +00:00
|
|
|
_distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
|
|
|
|
_release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
|
2008-08-28 22:04:54 +00:00
|
|
|
|
2008-09-24 18:09:22 +00:00
|
|
|
global _distname,_version
|
|
|
|
_distname = None
|
|
|
|
_version = None
|
|
|
|
|
2008-09-22 23:53:54 +00:00
|
|
|
def get_linux_distro():
|
|
|
|
""" Tries to determine the name of the Linux OS distribution name.
|
|
|
|
|
2008-09-23 17:14:31 +00:00
|
|
|
First, try to parse a file named "/etc/lsb-release". If it exists, and
|
|
|
|
contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
|
2008-09-24 18:09:22 +00:00
|
|
|
the strings parsed from that file.
|
|
|
|
|
|
|
|
If that doesn't work, then invoke platform.dist().
|
2008-09-23 17:14:31 +00:00
|
|
|
|
2008-09-24 18:09:22 +00:00
|
|
|
If that doesn't work, then try to execute "lsb_release", as standardized in
|
|
|
|
2001:
|
2008-09-22 23:53:54 +00:00
|
|
|
|
|
|
|
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 17:14:31 +00:00
|
|
|
that lsb_release emitted, as strings.
|
2008-09-23 16:28:58 +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-24 18:09:22 +00:00
|
|
|
global _distname,_version
|
|
|
|
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 17:14:31 +00:00
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
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()
|
2008-09-23 17:14:31 +00:00
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
2008-09-23 16:28:58 +00:00
|
|
|
except EnvironmentError:
|
|
|
|
pass
|
|
|
|
|
2008-09-24 18:09:22 +00:00
|
|
|
(_distname, _version) = platform.dist()[:2]
|
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
|
|
|
|
2008-09-23 17:14:31 +00:00
|
|
|
try:
|
|
|
|
p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
rc = p.wait()
|
|
|
|
if rc == 0:
|
|
|
|
for line in p.stdout.readlines():
|
|
|
|
m = _distributor_id_cmdline_re.search(line)
|
|
|
|
if m:
|
|
|
|
_distname = m.group(1).strip()
|
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
|
|
|
|
|
|
|
m = _release_cmdline_re.search(p.stdout.read())
|
|
|
|
if m:
|
|
|
|
_version = m.group(1).strip()
|
|
|
|
if _distname and _version:
|
|
|
|
return (_distname, _version)
|
|
|
|
except EnvironmentError:
|
|
|
|
pass
|
2008-09-23 16:28:58 +00:00
|
|
|
|
2008-11-25 16:51:18 +00:00
|
|
|
if os.path.exists("/etc/arch-release"):
|
|
|
|
return ("Arch_Linux", "")
|
|
|
|
|
2008-09-24 18:09:22 +00:00
|
|
|
return (_distname,_version)
|
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()
|
|
|
|
|
2009-01-19 22:04:35 +00:00
|
|
|
def get_package_versions_and_locations():
|
|
|
|
# because there are a few dependencies that are outside setuptools's ken (Python and
|
|
|
|
# platform), and because setuptools might fail to find something even though import finds
|
|
|
|
# it:
|
|
|
|
import OpenSSL, allmydata, foolscap, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec, zope.interface
|
|
|
|
|
|
|
|
d1 = {
|
|
|
|
'pyOpenSSL': (OpenSSL.__version__, os.path.dirname(OpenSSL.__file__)),
|
|
|
|
'allmydata-tahoe': (allmydata.__version__, os.path.dirname(allmydata.__file__)),
|
|
|
|
'foolscap': (foolscap.__version__, os.path.dirname(foolscap.__file__)),
|
|
|
|
'Nevow': (nevow.__version__, os.path.dirname(nevow.__file__)),
|
|
|
|
'pycryptopp': (pycryptopp.__version__, os.path.dirname(pycryptopp.__file__)),
|
|
|
|
'setuptools': (setuptools.__version__, os.path.dirname(setuptools.__file__)),
|
|
|
|
'simplejson': (simplejson.__version__, os.path.dirname(simplejson.__file__)),
|
|
|
|
'zope.interface': ('unknown', os.path.dirname(zope.interface.__file__)),
|
|
|
|
'Twisted': (twisted.__version__, os.path.dirname(twisted.__file__)),
|
|
|
|
'zfec': (zfec.__version__, os.path.dirname(zfec.__file__)),
|
|
|
|
'python': (platform.python_version(), sys.executable),
|
|
|
|
'platform': (get_platform(), None),
|
2007-12-13 02:37:37 +00:00
|
|
|
}
|
|
|
|
|
2009-01-19 22:04:35 +00:00
|
|
|
# But we prefer to get all the dependencies as known by setuptools:
|
|
|
|
import pkg_resources
|
|
|
|
try:
|
|
|
|
d2 = _auto_deps.get_package_versions_from_setuptools()
|
|
|
|
except pkg_resources.DistributionNotFound:
|
|
|
|
# See docstring in _auto_deps.require_auto_deps() to explain why it makes sense to ignore this exception.
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
d1.update(d2)
|
|
|
|
|
|
|
|
return d1
|
|
|
|
|
|
|
|
def get_package_versions():
|
|
|
|
return dict([(k, v) for k, (v, l) in get_package_versions_and_locations().iteritems()])
|
|
|
|
|
2009-01-16 19:47:51 +00:00
|
|
|
def get_package_locations():
|
2009-01-19 22:04:35 +00:00
|
|
|
return dict([(k, l) for k, (v, l) in get_package_versions_and_locations().iteritems()])
|
2009-01-16 19:47:51 +00:00
|
|
|
|
|
|
|
def get_package_versions_string(show_paths=False):
|
2009-01-19 22:04:35 +00:00
|
|
|
vers_and_locs = get_package_versions_and_locations()
|
2007-12-13 02:37:37 +00:00
|
|
|
res = []
|
2009-01-19 22:04:35 +00:00
|
|
|
for p in ["allmydata-tahoe", "foolscap", "pycryptopp", "zfec", "Twisted", "Nevow", "zope.interface", "python", "platform"]:
|
|
|
|
(ver, loc) = vers_and_locs.get(p, ('UNKNOWN', 'UNKNOWN'))
|
|
|
|
info = str(p) + ": " + str(ver)
|
2009-01-16 19:47:51 +00:00
|
|
|
if show_paths:
|
2009-01-19 22:04:35 +00:00
|
|
|
info = info + " (%s)" % str(loc)
|
2009-01-16 19:47:51 +00:00
|
|
|
res.append(info)
|
2009-01-19 22:04:35 +00:00
|
|
|
if vers_and_locs.has_key(p):
|
|
|
|
del vers_and_locs[p]
|
2009-01-16 19:47:51 +00:00
|
|
|
|
2009-01-19 22:04:35 +00:00
|
|
|
for p, (v, loc) in vers_and_locs.iteritems():
|
|
|
|
info = str(p) + ": " + str(v)
|
|
|
|
if show_paths:
|
|
|
|
info = info + " (%s)" % str(loc)
|
|
|
|
res.append(info)
|
2007-12-13 02:37:37 +00:00
|
|
|
return ', '.join(res)
|