2 Decentralized storage grid.
4 community web site: U{http://tahoe-lafs.org/}
7 # We want to call require_auto_deps() before other imports, because the setuptools
8 # docs claim that if a distribution is installed with --multi-version, it might not
9 # be importable until after pkg_resources.require() has been called for it. We don't
10 # have an example of this happening at this time. It is possible that require() isn't
11 # actually needed because we set __requires__ in the generated startup script, but
12 # that would be an undocumented property of the setuptools implementation.
14 from allmydata import _auto_deps
15 _auto_deps.require_auto_deps()
17 # This is just to suppress DeprecationWarnings from nevow and twisted.
18 # See http://allmydata.org/trac/tahoe/ticket/859 and
19 # http://divmod.org/trac/ticket/2994 .
21 warnings.filterwarnings("ignore", category=DeprecationWarning,
22 message="the sha module is deprecated; use the hashlib module instead",
24 warnings.filterwarnings("ignore", category=DeprecationWarning,
25 message="object.__new__\(\) takes no parameters",
27 warnings.filterwarnings("ignore", category=DeprecationWarning,
28 message="The popen2 module is deprecated. Use the subprocess module.",
30 warnings.filterwarnings("ignore", category=DeprecationWarning,
31 message="the md5 module is deprecated; use hashlib instead",
33 warnings.filterwarnings("ignore", category=DeprecationWarning,
34 message="twisted.web.error.NoResource is deprecated since Twisted 9.0. See twisted.web.resource.NoResource.",
38 from twisted.persisted import sob
39 from twisted.python import filepath
40 hush_pyflakes = (nevow, sob, filepath)
43 warnings.filters.pop()
44 warnings.filters.pop()
45 warnings.filters.pop()
46 warnings.filters.pop()
47 # Don't pop the filter for the sha module warning because it is also generated
48 # by pycrypto (which we don't want to import unless needed).
49 # warnings.filters.pop()
51 # This warning is generated by twisted, PyRex, and possibly other packages,
52 # but can happen at any time, not only when they are imported. See
53 # http://tahoe-lafs.org/trac/tahoe-lafs/ticket/1129 .
54 warnings.filterwarnings("ignore", category=DeprecationWarning,
55 message="BaseException.message has been deprecated as of Python 2.6",
58 __version__ = "unknown"
60 from allmydata._version import __version__
62 # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
63 # come with a _version.py, so we don't know what our version is. This should
64 # not happen very often.
67 __appname__ = "unknown"
69 from allmydata._appname import __appname__
71 # We're running in a tree that hasn't run "./setup.py". This shouldn't happen.
74 # __full_version__ is the one that you ought to use when identifying yourself in the
75 # "application" part of the Tahoe versioning scheme:
76 # http://allmydata.org/trac/tahoe/wiki/Versioning
77 __full_version__ = __appname__ + '/' + str(__version__)
79 import os, platform, re, subprocess, sys
80 _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
81 _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
83 _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
84 _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
86 global _distname,_version
90 def get_linux_distro():
91 """ Tries to determine the name of the Linux OS distribution name.
93 First, try to parse a file named "/etc/lsb-release". If it exists, and
94 contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
95 the strings parsed from that file.
97 If that doesn't work, then invoke platform.dist().
99 If that doesn't work, then try to execute "lsb_release", as standardized in
102 http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
104 The current version of the standard is here:
106 http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
108 that lsb_release emitted, as strings.
110 Returns a tuple (distname,version). Distname is what LSB calls a
111 "distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
114 A version of this has been submitted to python as a patch for the standard
115 library module "platform":
117 http://bugs.python.org/issue3937
119 global _distname,_version
120 if _distname and _version:
121 return (_distname, _version)
124 etclsbrel = open("/etc/lsb-release", "rU")
125 for line in etclsbrel:
126 m = _distributor_id_file_re.search(line)
128 _distname = m.group(1).strip()
129 if _distname and _version:
130 return (_distname, _version)
131 m = _release_file_re.search(line)
133 _version = m.group(1).strip()
134 if _distname and _version:
135 return (_distname, _version)
136 except EnvironmentError:
139 (_distname, _version) = platform.dist()[:2]
140 if _distname and _version:
141 return (_distname, _version)
144 p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
147 for line in p.stdout.readlines():
148 m = _distributor_id_cmdline_re.search(line)
150 _distname = m.group(1).strip()
151 if _distname and _version:
152 return (_distname, _version)
154 m = _release_cmdline_re.search(p.stdout.read())
156 _version = m.group(1).strip()
157 if _distname and _version:
158 return (_distname, _version)
159 except EnvironmentError:
162 if os.path.exists("/etc/arch-release"):
163 return ("Arch_Linux", "")
165 return (_distname,_version)
168 # Our version of platform.platform(), telling us both less and more than the
169 # Python Standard Library's version does.
170 # We omit details such as the Linux kernel version number, but we add a
171 # more detailed and correct rendition of the Linux distribution and
172 # distribution-version.
173 if "linux" in platform.system().lower():
174 return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
176 return platform.platform()
178 def get_package_versions_from_setuptools():
180 return dict([(p.project_name, (p.version, p.location)) for p in pkg_resources.require(__appname__)])
182 def package_dir(srcfile):
183 return os.path.dirname(os.path.dirname(os.path.normcase(os.path.realpath(srcfile))))
185 def get_package_versions_and_locations():
186 # because there are a few dependencies that are outside setuptools's ken
187 # (Python and platform, and sqlite3 if you are on Python >= 2.5), and
188 # because setuptools might fail to find something even though import
190 import OpenSSL, allmydata, foolscap.api, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec, zope.interface
198 from pysqlite2 import dbapi2
202 pysqlitever = dbapi2.version
203 pysqlitefile = package_dir(dbapi2.__file__)
204 sqlitever = dbapi2.sqlite_version
206 pysqlitever = sqlite3.version
207 pysqlitefile = package_dir(sqlite3.__file__)
208 sqlitever = sqlite3.sqlite_version
211 'pyOpenSSL': (OpenSSL.__version__, package_dir(OpenSSL.__file__)),
212 __appname__: (allmydata.__version__, package_dir(allmydata.__file__)),
213 'foolscap': (foolscap.api.__version__, package_dir(foolscap.__file__)),
214 'Nevow': (nevow.__version__, package_dir(nevow.__file__)),
215 'pycryptopp': (pycryptopp.__version__, package_dir(pycryptopp.__file__)),
216 'setuptools': (setuptools.__version__, package_dir(setuptools.__file__)),
217 'simplejson': (simplejson.__version__, package_dir(simplejson.__file__)),
218 'pysqlite': (pysqlitever, pysqlitefile),
219 'sqlite': (sqlitever, 'unknown'),
220 'zope.interface': ('unknown', package_dir(zope.interface.__file__)),
221 'Twisted': (twisted.__version__, package_dir(twisted.__file__)),
222 'zfec': (zfec.__version__, package_dir(zfec.__file__)),
223 'python': (platform.python_version(), sys.executable),
224 'platform': (get_platform(), None),
227 # But we prefer to get all the dependencies as known by setuptools:
230 d2 = get_package_versions_from_setuptools()
231 except pkg_resources.DistributionNotFound:
232 # See docstring in _auto_deps.require_auto_deps() to explain why it makes sense to ignore this exception.
239 def get_package_versions():
240 return dict([(k, v) for k, (v, l) in get_package_versions_and_locations().iteritems()])
242 def get_package_locations():
243 return dict([(k, l) for k, (v, l) in get_package_versions_and_locations().iteritems()])
245 def get_package_versions_string(show_paths=False):
246 vers_and_locs = get_package_versions_and_locations()
248 for p in [__appname__, "foolscap", "pycryptopp", "zfec", "Twisted", "Nevow", "zope.interface", "python", "platform"]:
249 (ver, loc) = vers_and_locs.get(p, ('UNKNOWN', 'UNKNOWN'))
250 info = str(p) + ": " + str(ver)
252 info = info + " (%s)" % str(loc)
254 if vers_and_locs.has_key(p):
257 for p, (v, loc) in vers_and_locs.iteritems():
258 info = str(p) + ": " + str(v)
260 info = info + " (%s)" % str(loc)
262 return ', '.join(res)