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 global _distname,_version
35 def get_linux_distro():
36 """ Tries to determine the name of the Linux OS distribution name.
38 First, try to parse a file named "/etc/lsb-release". If it exists, and
39 contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
40 the strings parsed from that file.
42 If that doesn't work, then invoke platform.dist().
44 If that doesn't work, then try to execute "lsb_release", as standardized in
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 that lsb_release emitted, as strings.
55 Returns a tuple (distname,version). Distname is what LSB calls a
56 "distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
59 A version of this has been submitted to python as a patch for the standard
60 library module "platform":
62 http://bugs.python.org/issue3937
64 global _distname,_version
65 if _distname and _version:
66 return (_distname, _version)
69 etclsbrel = open("/etc/lsb-release", "rU")
70 for line in etclsbrel:
71 m = _distributor_id_file_re.search(line)
73 _distname = m.group(1).strip()
74 if _distname and _version:
75 return (_distname, _version)
76 m = _release_file_re.search(line)
78 _version = m.group(1).strip()
79 if _distname and _version:
80 return (_distname, _version)
81 except EnvironmentError:
84 (_distname, _version) = platform.dist()[:2]
85 if _distname and _version:
86 return (_distname, _version)
89 p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
92 for line in p.stdout.readlines():
93 m = _distributor_id_cmdline_re.search(line)
95 _distname = m.group(1).strip()
96 if _distname and _version:
97 return (_distname, _version)
99 m = _release_cmdline_re.search(p.stdout.read())
101 _version = m.group(1).strip()
102 if _distname and _version:
103 return (_distname, _version)
104 except EnvironmentError:
107 return (_distname,_version)
110 # Our version of platform.platform(), telling us both less and more than the
111 # Python Standard Library's version does.
112 # We omit details such as the Linux kernel version number, but we add a
113 # more detailed and correct rendition of the Linux distribution and
114 # distribution-version.
115 if "linux" in platform.system().lower():
116 return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
118 return platform.platform()
120 def get_package_versions():
121 import OpenSSL, allmydata, foolscap, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec
124 'pyopenssl': OpenSSL.__version__,
125 'allmydata': allmydata.__version__,
126 'foolscap': foolscap.__version__,
127 'nevow': nevow.__version__,
128 'pycryptopp': pycryptopp.__version__,
129 'setuptools': setuptools.__version__,
130 'simplejson': simplejson.__version__,
131 'twisted': twisted.__version__,
132 'zfec': zfec.__version__,
133 'python': platform.python_version(),
134 'platform': get_platform()
137 def get_package_versions_string():
138 versions = get_package_versions()
140 for p in ["allmydata", "foolscap", "pycryptopp", "zfec", "twisted", "nevow", "python", "platform"]:
141 if versions.has_key(p):
142 res.append(str(p) + ": " + str(versions[p]))
145 res.append(str(p) + ": UNKNOWN")
146 for p, v in versions.iteritems():
147 res.append(str(p) + ": " + str(v))
148 return ', '.join(res)