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, PyRex, and possibly other packages,
39 # but can happen at any time, not only when they are imported. See
40 # http://tahoe-lafs.org/trac/tahoe-lafs/ticket/1129 .
41 warnings.filterwarnings("ignore", category=DeprecationWarning,
42 message="BaseException.message has been deprecated as of Python 2.6",
45 __version__ = "unknown"
47 from allmydata._version import __version__
49 # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
50 # come with a _version.py, so we don't know what our version is. This should
51 # not happen very often.
54 __appname__ = "unknown"
56 from allmydata._appname import __appname__
58 # We're running in a tree that hasn't run "./setup.py". This shouldn't happen.
61 # __full_version__ is the one that you ought to use when identifying yourself in the
62 # "application" part of the Tahoe versioning scheme:
63 # http://allmydata.org/trac/tahoe/wiki/Versioning
64 __full_version__ = __appname__ + '/' + str(__version__)
66 from allmydata import _auto_deps
67 _auto_deps.require_auto_deps()
69 import os, platform, re, subprocess, sys
70 _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
71 _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
73 _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
74 _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
76 global _distname,_version
80 def get_linux_distro():
81 """ Tries to determine the name of the Linux OS distribution name.
83 First, try to parse a file named "/etc/lsb-release". If it exists, and
84 contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
85 the strings parsed from that file.
87 If that doesn't work, then invoke platform.dist().
89 If that doesn't work, then try to execute "lsb_release", as standardized in
92 http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
94 The current version of the standard is here:
96 http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
98 that lsb_release emitted, as strings.
100 Returns a tuple (distname,version). Distname is what LSB calls a
101 "distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
104 A version of this has been submitted to python as a patch for the standard
105 library module "platform":
107 http://bugs.python.org/issue3937
109 global _distname,_version
110 if _distname and _version:
111 return (_distname, _version)
114 etclsbrel = open("/etc/lsb-release", "rU")
115 for line in etclsbrel:
116 m = _distributor_id_file_re.search(line)
118 _distname = m.group(1).strip()
119 if _distname and _version:
120 return (_distname, _version)
121 m = _release_file_re.search(line)
123 _version = m.group(1).strip()
124 if _distname and _version:
125 return (_distname, _version)
126 except EnvironmentError:
129 (_distname, _version) = platform.dist()[:2]
130 if _distname and _version:
131 return (_distname, _version)
134 p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
137 for line in p.stdout.readlines():
138 m = _distributor_id_cmdline_re.search(line)
140 _distname = m.group(1).strip()
141 if _distname and _version:
142 return (_distname, _version)
144 m = _release_cmdline_re.search(p.stdout.read())
146 _version = m.group(1).strip()
147 if _distname and _version:
148 return (_distname, _version)
149 except EnvironmentError:
152 if os.path.exists("/etc/arch-release"):
153 return ("Arch_Linux", "")
155 return (_distname,_version)
158 # Our version of platform.platform(), telling us both less and more than the
159 # Python Standard Library's version does.
160 # We omit details such as the Linux kernel version number, but we add a
161 # more detailed and correct rendition of the Linux distribution and
162 # distribution-version.
163 if "linux" in platform.system().lower():
164 return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
166 return platform.platform()
168 def get_package_versions_from_setuptools():
170 return dict([(p.project_name, (p.version, p.location)) for p in pkg_resources.require(__appname__)])
172 def package_dir(srcfile):
173 return os.path.dirname(os.path.dirname(os.path.realpath(srcfile)))
175 def get_package_versions_and_locations():
176 # because there are a few dependencies that are outside setuptools's ken
177 # (Python and platform, and sqlite3 if you are on Python >= 2.5), and
178 # because setuptools might fail to find something even though import
180 import OpenSSL, allmydata, foolscap.api, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec, zope.interface
188 from pysqlite2 import dbapi2
192 pysqlitever = dbapi2.version
193 pysqlitefile = package_dir(dbapi2.__file__)
194 sqlitever = dbapi2.sqlite_version
196 pysqlitever = sqlite3.version
197 pysqlitefile = package_dir(sqlite3.__file__)
198 sqlitever = sqlite3.sqlite_version
201 'pyOpenSSL': (OpenSSL.__version__, package_dir(OpenSSL.__file__)),
202 __appname__: (allmydata.__version__, package_dir(allmydata.__file__)),
203 'foolscap': (foolscap.api.__version__, package_dir(foolscap.__file__)),
204 'Nevow': (nevow.__version__, package_dir(nevow.__file__)),
205 'pycryptopp': (pycryptopp.__version__, package_dir(pycryptopp.__file__)),
206 'setuptools': (setuptools.__version__, package_dir(setuptools.__file__)),
207 'simplejson': (simplejson.__version__, package_dir(simplejson.__file__)),
208 'pysqlite': (pysqlitever, pysqlitefile),
209 'sqlite': (sqlitever, 'unknown'),
210 'zope.interface': ('unknown', package_dir(zope.interface.__file__)),
211 'Twisted': (twisted.__version__, package_dir(twisted.__file__)),
212 'zfec': (zfec.__version__, package_dir(zfec.__file__)),
213 'python': (platform.python_version(), sys.executable),
214 'platform': (get_platform(), None),
217 # But we prefer to get all the dependencies as known by setuptools:
220 d2 = get_package_versions_from_setuptools()
221 except pkg_resources.DistributionNotFound:
222 # See docstring in _auto_deps.require_auto_deps() to explain why it makes sense to ignore this exception.
229 def get_package_versions():
230 return dict([(k, v) for k, (v, l) in get_package_versions_and_locations().iteritems()])
232 def get_package_locations():
233 return dict([(k, l) for k, (v, l) in get_package_versions_and_locations().iteritems()])
235 def get_package_versions_string(show_paths=False):
236 vers_and_locs = get_package_versions_and_locations()
238 for p in [__appname__, "foolscap", "pycryptopp", "zfec", "Twisted", "Nevow", "zope.interface", "python", "platform"]:
239 (ver, loc) = vers_and_locs.get(p, ('UNKNOWN', 'UNKNOWN'))
240 info = str(p) + ": " + str(ver)
242 info = info + " (%s)" % str(loc)
244 if vers_and_locs.has_key(p):
247 for p, (v, loc) in vers_and_locs.iteritems():
248 info = str(p) + ": " + str(v)
250 info = info + " (%s)" % str(loc)
252 return ', '.join(res)