2 Decentralized storage grid.
4 community web site: U{http://tahoe-lafs.org/}
7 # This is just to suppress DeprecationWarnings from nevow and twisted.
8 # See http://allmydata.org/trac/tahoe/ticket/859 and
9 # http://divmod.org/trac/ticket/2994 .
11 warnings.filterwarnings("ignore", category=DeprecationWarning,
12 message="object.__new__\(\) takes no parameters",
14 warnings.filterwarnings("ignore", category=DeprecationWarning,
15 message="The popen2 module is deprecated. Use the subprocess module.",
17 warnings.filterwarnings("ignore", category=DeprecationWarning,
18 message="the md5 module is deprecated; use hashlib instead",
20 warnings.filterwarnings("ignore", category=DeprecationWarning,
21 message="the sha module is deprecated; use the hashlib module instead",
23 warnings.filterwarnings("ignore", category=DeprecationWarning,
24 message="twisted.web.error.NoResource is deprecated since Twisted 9.0. See twisted.web.resource.NoResource.",
28 from twisted.persisted import sob
29 from twisted.python import filepath
30 hush_pyflakes = (nevow, sob, filepath)
33 warnings.filters.pop()
34 warnings.filters.pop()
35 warnings.filters.pop()
36 warnings.filters.pop()
38 # This warning is generated by twisted, but not when it is imported, only on an error.
39 warnings.filterwarnings("ignore", category=DeprecationWarning,
40 message="BaseException.message has been deprecated as of Python 2.6",
41 module=".*twisted.*", append=True)
43 __version__ = "unknown"
45 from allmydata._version import __version__
47 # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
48 # come with a _version.py, so we don't know what our version is. This should
49 # not happen very often.
52 __appname__ = "unknown"
54 from allmydata._appname import __appname__
56 # We're running in a tree that hasn't run "./setup.py". This shouldn't happen.
59 # __full_version__ is the one that you ought to use when identifying yourself in the
60 # "application" part of the Tahoe versioning scheme:
61 # http://allmydata.org/trac/tahoe/wiki/Versioning
62 __full_version__ = __appname__ + '/' + str(__version__)
64 from allmydata import _auto_deps
65 _auto_deps.require_auto_deps()
67 import os, platform, re, subprocess, sys
68 _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
69 _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
71 _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
72 _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
74 global _distname,_version
78 def get_linux_distro():
79 """ Tries to determine the name of the Linux OS distribution name.
81 First, try to parse a file named "/etc/lsb-release". If it exists, and
82 contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
83 the strings parsed from that file.
85 If that doesn't work, then invoke platform.dist().
87 If that doesn't work, then try to execute "lsb_release", as standardized in
90 http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
92 The current version of the standard is here:
94 http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
96 that lsb_release emitted, as strings.
98 Returns a tuple (distname,version). Distname is what LSB calls a
99 "distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
102 A version of this has been submitted to python as a patch for the standard
103 library module "platform":
105 http://bugs.python.org/issue3937
107 global _distname,_version
108 if _distname and _version:
109 return (_distname, _version)
112 etclsbrel = open("/etc/lsb-release", "rU")
113 for line in etclsbrel:
114 m = _distributor_id_file_re.search(line)
116 _distname = m.group(1).strip()
117 if _distname and _version:
118 return (_distname, _version)
119 m = _release_file_re.search(line)
121 _version = m.group(1).strip()
122 if _distname and _version:
123 return (_distname, _version)
124 except EnvironmentError:
127 (_distname, _version) = platform.dist()[:2]
128 if _distname and _version:
129 return (_distname, _version)
132 p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
135 for line in p.stdout.readlines():
136 m = _distributor_id_cmdline_re.search(line)
138 _distname = m.group(1).strip()
139 if _distname and _version:
140 return (_distname, _version)
142 m = _release_cmdline_re.search(p.stdout.read())
144 _version = m.group(1).strip()
145 if _distname and _version:
146 return (_distname, _version)
147 except EnvironmentError:
150 if os.path.exists("/etc/arch-release"):
151 return ("Arch_Linux", "")
153 return (_distname,_version)
156 # Our version of platform.platform(), telling us both less and more than the
157 # Python Standard Library's version does.
158 # We omit details such as the Linux kernel version number, but we add a
159 # more detailed and correct rendition of the Linux distribution and
160 # distribution-version.
161 if "linux" in platform.system().lower():
162 return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
164 return platform.platform()
166 def get_package_versions_and_locations():
167 # because there are a few dependencies that are outside setuptools's ken
168 # (Python and platform, and sqlite3 if you are on Python >= 2.5), and
169 # because setuptools might fail to find something even though import
171 import OpenSSL, allmydata, foolscap.api, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec, zope.interface
179 from pysqlite2 import dbapi2
183 pysqlitever = dbapi2.version
184 pysqlitefile = os.path.dirname(dbapi2.__file__)
185 sqlitever = dbapi2.sqlite_version
187 pysqlitever = sqlite3.version
188 pysqlitefile = os.path.dirname(sqlite3.__file__)
189 sqlitever = sqlite3.sqlite_version
192 'pyOpenSSL': (OpenSSL.__version__, os.path.dirname(OpenSSL.__file__)),
193 'allmydata-tahoe': (allmydata.__version__, os.path.dirname(allmydata.__file__)),
194 'foolscap': (foolscap.api.__version__, os.path.dirname(foolscap.__file__)),
195 'Nevow': (nevow.__version__, os.path.dirname(nevow.__file__)),
196 'pycryptopp': (pycryptopp.__version__, os.path.dirname(pycryptopp.__file__)),
197 'setuptools': (setuptools.__version__, os.path.dirname(setuptools.__file__)),
198 'simplejson': (simplejson.__version__, os.path.dirname(simplejson.__file__)),
199 'pysqlite': (pysqlitever, pysqlitefile),
200 'sqlite': (sqlitever, 'unknown'),
201 'zope.interface': ('unknown', os.path.dirname(zope.interface.__file__)),
202 'Twisted': (twisted.__version__, os.path.dirname(twisted.__file__)),
203 'zfec': (zfec.__version__, os.path.dirname(zfec.__file__)),
204 'python': (platform.python_version(), sys.executable),
205 'platform': (get_platform(), None),
208 # But we prefer to get all the dependencies as known by setuptools:
211 d2 = _auto_deps.get_package_versions_from_setuptools()
212 except pkg_resources.DistributionNotFound:
213 # See docstring in _auto_deps.require_auto_deps() to explain why it makes sense to ignore this exception.
220 def get_package_versions():
221 return dict([(k, v) for k, (v, l) in get_package_versions_and_locations().iteritems()])
223 def get_package_locations():
224 return dict([(k, l) for k, (v, l) in get_package_versions_and_locations().iteritems()])
226 def get_package_versions_string(show_paths=False):
227 vers_and_locs = get_package_versions_and_locations()
229 for p in ["allmydata-tahoe", "foolscap", "pycryptopp", "zfec", "Twisted", "Nevow", "zope.interface", "python", "platform"]:
230 (ver, loc) = vers_and_locs.get(p, ('UNKNOWN', 'UNKNOWN'))
231 info = str(p) + ": " + str(ver)
233 info = info + " (%s)" % str(loc)
235 if vers_and_locs.has_key(p):
238 for p, (v, loc) in vers_and_locs.iteritems():
239 info = str(p) + ": " + str(v)
241 info = info + " (%s)" % str(loc)
243 return ', '.join(res)