2 Decentralized storage grid.
4 community web site: U{http://tahoe-lafs.org/}
7 # temporary hack to debug failure on midnightmagic's buildslave:
10 from allmydata import _auto_deps
11 _auto_deps.require_auto_deps()
13 # This is just to suppress DeprecationWarnings from nevow and twisted.
14 # See http://allmydata.org/trac/tahoe/ticket/859 and
15 # http://divmod.org/trac/ticket/2994 .
17 warnings.filterwarnings("ignore", category=DeprecationWarning,
18 message="object.__new__\(\) takes no parameters",
20 warnings.filterwarnings("ignore", category=DeprecationWarning,
21 message="The popen2 module is deprecated. Use the subprocess module.",
23 warnings.filterwarnings("ignore", category=DeprecationWarning,
24 message="the md5 module is deprecated; use hashlib instead",
26 warnings.filterwarnings("ignore", category=DeprecationWarning,
27 message="the sha module is deprecated; use the hashlib module instead",
29 warnings.filterwarnings("ignore", category=DeprecationWarning,
30 message="twisted.web.error.NoResource is deprecated since Twisted 9.0. See twisted.web.resource.NoResource.",
34 from twisted.persisted import sob
35 from twisted.python import filepath
36 hush_pyflakes = (nevow, sob, filepath)
39 warnings.filters.pop()
40 warnings.filters.pop()
41 warnings.filters.pop()
42 warnings.filters.pop()
44 # This warning is generated by twisted, PyRex, and possibly other packages,
45 # but can happen at any time, not only when they are imported. See
46 # http://tahoe-lafs.org/trac/tahoe-lafs/ticket/1129 .
47 warnings.filterwarnings("ignore", category=DeprecationWarning,
48 message="BaseException.message has been deprecated as of Python 2.6",
51 __version__ = "unknown"
53 from allmydata._version import __version__
55 # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
56 # come with a _version.py, so we don't know what our version is. This should
57 # not happen very often.
60 __appname__ = "unknown"
62 from allmydata._appname import __appname__
64 # We're running in a tree that hasn't run "./setup.py". This shouldn't happen.
67 # __full_version__ is the one that you ought to use when identifying yourself in the
68 # "application" part of the Tahoe versioning scheme:
69 # http://allmydata.org/trac/tahoe/wiki/Versioning
70 __full_version__ = __appname__ + '/' + str(__version__)
72 import os, platform, re, subprocess, sys
73 _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
74 _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
76 _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
77 _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
79 global _distname,_version
83 def get_linux_distro():
84 """ Tries to determine the name of the Linux OS distribution name.
86 First, try to parse a file named "/etc/lsb-release". If it exists, and
87 contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
88 the strings parsed from that file.
90 If that doesn't work, then invoke platform.dist().
92 If that doesn't work, then try to execute "lsb_release", as standardized in
95 http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
97 The current version of the standard is here:
99 http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
101 that lsb_release emitted, as strings.
103 Returns a tuple (distname,version). Distname is what LSB calls a
104 "distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
107 A version of this has been submitted to python as a patch for the standard
108 library module "platform":
110 http://bugs.python.org/issue3937
112 global _distname,_version
113 if _distname and _version:
114 return (_distname, _version)
117 etclsbrel = open("/etc/lsb-release", "rU")
118 for line in etclsbrel:
119 m = _distributor_id_file_re.search(line)
121 _distname = m.group(1).strip()
122 if _distname and _version:
123 return (_distname, _version)
124 m = _release_file_re.search(line)
126 _version = m.group(1).strip()
127 if _distname and _version:
128 return (_distname, _version)
129 except EnvironmentError:
132 (_distname, _version) = platform.dist()[:2]
133 if _distname and _version:
134 return (_distname, _version)
137 p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
140 for line in p.stdout.readlines():
141 m = _distributor_id_cmdline_re.search(line)
143 _distname = m.group(1).strip()
144 if _distname and _version:
145 return (_distname, _version)
147 m = _release_cmdline_re.search(p.stdout.read())
149 _version = m.group(1).strip()
150 if _distname and _version:
151 return (_distname, _version)
152 except EnvironmentError:
155 if os.path.exists("/etc/arch-release"):
156 return ("Arch_Linux", "")
158 return (_distname,_version)
161 # Our version of platform.platform(), telling us both less and more than the
162 # Python Standard Library's version does.
163 # We omit details such as the Linux kernel version number, but we add a
164 # more detailed and correct rendition of the Linux distribution and
165 # distribution-version.
166 if "linux" in platform.system().lower():
167 return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
169 return platform.platform()
171 def get_package_versions_from_setuptools():
173 return dict([(p.project_name, (p.version, p.location)) for p in pkg_resources.require(__appname__)])
175 def package_dir(srcfile):
176 return os.path.dirname(os.path.dirname(os.path.normcase(os.path.realpath(srcfile))))
178 def get_package_versions_and_locations():
179 # because there are a few dependencies that are outside setuptools's ken
180 # (Python and platform, and sqlite3 if you are on Python >= 2.5), and
181 # because setuptools might fail to find something even though import
183 import OpenSSL, allmydata, foolscap.api, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec, zope.interface
191 from pysqlite2 import dbapi2
195 pysqlitever = dbapi2.version
196 pysqlitefile = package_dir(dbapi2.__file__)
197 sqlitever = dbapi2.sqlite_version
199 pysqlitever = sqlite3.version
200 pysqlitefile = package_dir(sqlite3.__file__)
201 sqlitever = sqlite3.sqlite_version
204 'pyOpenSSL': (OpenSSL.__version__, package_dir(OpenSSL.__file__)),
205 __appname__: (allmydata.__version__, package_dir(allmydata.__file__)),
206 'foolscap': (foolscap.api.__version__, package_dir(foolscap.__file__)),
207 'Nevow': (nevow.__version__, package_dir(nevow.__file__)),
208 'pycryptopp': (pycryptopp.__version__, package_dir(pycryptopp.__file__)),
209 'setuptools': (setuptools.__version__, package_dir(setuptools.__file__)),
210 'simplejson': (simplejson.__version__, package_dir(simplejson.__file__)),
211 'pysqlite': (pysqlitever, pysqlitefile),
212 'sqlite': (sqlitever, 'unknown'),
213 'zope.interface': ('unknown', package_dir(zope.interface.__file__)),
214 'Twisted': (twisted.__version__, package_dir(twisted.__file__)),
215 'zfec': (zfec.__version__, package_dir(zfec.__file__)),
216 'python': (platform.python_version(), sys.executable),
217 'platform': (get_platform(), None),
220 # But we prefer to get all the dependencies as known by setuptools:
223 d2 = get_package_versions_from_setuptools()
224 except pkg_resources.DistributionNotFound:
225 # See docstring in _auto_deps.require_auto_deps() to explain why it makes sense to ignore this exception.
232 def get_package_versions():
233 return dict([(k, v) for k, (v, l) in get_package_versions_and_locations().iteritems()])
235 def get_package_locations():
236 return dict([(k, l) for k, (v, l) in get_package_versions_and_locations().iteritems()])
238 def get_package_versions_string(show_paths=False):
239 vers_and_locs = get_package_versions_and_locations()
241 for p in [__appname__, "foolscap", "pycryptopp", "zfec", "Twisted", "Nevow", "zope.interface", "python", "platform"]:
242 (ver, loc) = vers_and_locs.get(p, ('UNKNOWN', 'UNKNOWN'))
243 info = str(p) + ": " + str(ver)
245 info = info + " (%s)" % str(loc)
247 if vers_and_locs.has_key(p):
250 for p, (v, loc) in vers_and_locs.iteritems():
251 info = str(p) + ": " + str(v)
253 info = info + " (%s)" % str(loc)
255 return ', '.join(res)