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="the sha module is deprecated; use the hashlib module instead",
14 warnings.filterwarnings("ignore", category=DeprecationWarning,
15 message="object.__new__\(\) takes no parameters",
17 warnings.filterwarnings("ignore", category=DeprecationWarning,
18 message="The popen2 module is deprecated. Use the subprocess module.",
20 warnings.filterwarnings("ignore", category=DeprecationWarning,
21 message="the md5 module is deprecated; use hashlib 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()
37 # Don't pop the filter for the sha module warning because it is also generated
38 # by pycrypto (which we don't want to import unless needed).
39 # warnings.filters.pop()
41 # This warning is generated by twisted, PyRex, and possibly other packages,
42 # but can happen at any time, not only when they are imported. See
43 # http://tahoe-lafs.org/trac/tahoe-lafs/ticket/1129 .
44 warnings.filterwarnings("ignore", category=DeprecationWarning,
45 message="BaseException.message has been deprecated as of Python 2.6",
48 __version__ = "unknown"
50 from allmydata._version import __version__
52 # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
53 # come with a _version.py, so we don't know what our version is. This should
54 # not happen very often.
57 __appname__ = "unknown"
59 from allmydata._appname import __appname__
61 # We're running in a tree that hasn't run "./setup.py". This shouldn't happen.
64 # __full_version__ is the one that you ought to use when identifying yourself in the
65 # "application" part of the Tahoe versioning scheme:
66 # http://allmydata.org/trac/tahoe/wiki/Versioning
67 __full_version__ = __appname__ + '/' + str(__version__)
69 # Ideally we would call require_auto_deps() before importing nevow and twisted, but
70 # that causes midnightmagic's NetBSD buildslave to be unable to import allmydata.test,
71 # for reasons that are not understood. We want to call require_auto_deps() before other
72 # imports because the setuptools docs claim that if a distribution is installed with
73 # --multi-version, it might not importable until after pkg_resources.require()
74 # has been called for it. We don't have an example of this happening at this time.
75 # It is possible that require() isn't actually needed because we set __requires__
76 # in the generated startup script, but that would be an undocumented property of the
77 # setuptools implementation.
79 from allmydata import _auto_deps
80 _auto_deps.require_auto_deps()
82 import os, platform, re, subprocess, sys
83 _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
84 _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
86 _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
87 _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
89 global _distname,_version
93 def get_linux_distro():
94 """ Tries to determine the name of the Linux OS distribution name.
96 First, try to parse a file named "/etc/lsb-release". If it exists, and
97 contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
98 the strings parsed from that file.
100 If that doesn't work, then invoke platform.dist().
102 If that doesn't work, then try to execute "lsb_release", as standardized in
105 http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
107 The current version of the standard is here:
109 http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
111 that lsb_release emitted, as strings.
113 Returns a tuple (distname,version). Distname is what LSB calls a
114 "distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
117 A version of this has been submitted to python as a patch for the standard
118 library module "platform":
120 http://bugs.python.org/issue3937
122 global _distname,_version
123 if _distname and _version:
124 return (_distname, _version)
127 etclsbrel = open("/etc/lsb-release", "rU")
128 for line in etclsbrel:
129 m = _distributor_id_file_re.search(line)
131 _distname = m.group(1).strip()
132 if _distname and _version:
133 return (_distname, _version)
134 m = _release_file_re.search(line)
136 _version = m.group(1).strip()
137 if _distname and _version:
138 return (_distname, _version)
139 except EnvironmentError:
142 (_distname, _version) = platform.dist()[:2]
143 if _distname and _version:
144 return (_distname, _version)
147 p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
150 for line in p.stdout.readlines():
151 m = _distributor_id_cmdline_re.search(line)
153 _distname = m.group(1).strip()
154 if _distname and _version:
155 return (_distname, _version)
157 m = _release_cmdline_re.search(p.stdout.read())
159 _version = m.group(1).strip()
160 if _distname and _version:
161 return (_distname, _version)
162 except EnvironmentError:
165 if os.path.exists("/etc/arch-release"):
166 return ("Arch_Linux", "")
168 return (_distname,_version)
171 # Our version of platform.platform(), telling us both less and more than the
172 # Python Standard Library's version does.
173 # We omit details such as the Linux kernel version number, but we add a
174 # more detailed and correct rendition of the Linux distribution and
175 # distribution-version.
176 if "linux" in platform.system().lower():
177 return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
179 return platform.platform()
181 def get_package_versions_from_setuptools():
183 return dict([(p.project_name, (p.version, p.location)) for p in pkg_resources.require(__appname__)])
185 def package_dir(srcfile):
186 return os.path.dirname(os.path.dirname(os.path.normcase(os.path.realpath(srcfile))))
188 def get_package_versions_and_locations():
189 # because there are a few dependencies that are outside setuptools's ken
190 # (Python and platform, and sqlite3 if you are on Python >= 2.5), and
191 # because setuptools might fail to find something even though import
193 import OpenSSL, allmydata, foolscap.api, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec, zope.interface
201 from pysqlite2 import dbapi2
205 pysqlitever = dbapi2.version
206 pysqlitefile = package_dir(dbapi2.__file__)
207 sqlitever = dbapi2.sqlite_version
209 pysqlitever = sqlite3.version
210 pysqlitefile = package_dir(sqlite3.__file__)
211 sqlitever = sqlite3.sqlite_version
214 'pyOpenSSL': (OpenSSL.__version__, package_dir(OpenSSL.__file__)),
215 __appname__: (allmydata.__version__, package_dir(allmydata.__file__)),
216 'foolscap': (foolscap.api.__version__, package_dir(foolscap.__file__)),
217 'Nevow': (nevow.__version__, package_dir(nevow.__file__)),
218 'pycryptopp': (pycryptopp.__version__, package_dir(pycryptopp.__file__)),
219 'setuptools': (setuptools.__version__, package_dir(setuptools.__file__)),
220 'simplejson': (simplejson.__version__, package_dir(simplejson.__file__)),
221 'pysqlite': (pysqlitever, pysqlitefile),
222 'sqlite': (sqlitever, 'unknown'),
223 'zope.interface': ('unknown', package_dir(zope.interface.__file__)),
224 'Twisted': (twisted.__version__, package_dir(twisted.__file__)),
225 'zfec': (zfec.__version__, package_dir(zfec.__file__)),
226 'python': (platform.python_version(), sys.executable),
227 'platform': (get_platform(), None),
230 # But we prefer to get all the dependencies as known by setuptools:
233 d2 = get_package_versions_from_setuptools()
234 except pkg_resources.DistributionNotFound:
235 # See docstring in _auto_deps.require_auto_deps() to explain why it makes sense to ignore this exception.
242 def get_package_versions():
243 return dict([(k, v) for k, (v, l) in get_package_versions_and_locations().iteritems()])
245 def get_package_locations():
246 return dict([(k, l) for k, (v, l) in get_package_versions_and_locations().iteritems()])
248 def get_package_versions_string(show_paths=False):
249 vers_and_locs = get_package_versions_and_locations()
251 for p in [__appname__, "foolscap", "pycryptopp", "zfec", "Twisted", "Nevow", "zope.interface", "python", "platform"]:
252 (ver, loc) = vers_and_locs.get(p, ('UNKNOWN', 'UNKNOWN'))
253 info = str(p) + ": " + str(ver)
255 info = info + " (%s)" % str(loc)
257 if vers_and_locs.has_key(p):
260 for p, (v, loc) in vers_and_locs.iteritems():
261 info = str(p) + ": " + str(v)
263 info = info + " (%s)" % str(loc)
265 return ', '.join(res)