2 Decentralized storage grid.
4 maintainer web site: U{http://allmydata.com/}
6 community web site: U{http://allmydata.org/}
9 # This is just to suppress DeprecationWarnings from nevow and twisted.
10 # See http://allmydata.org/trac/tahoe/ticket/859 and
11 # http://divmod.org/trac/ticket/2994 .
13 warnings.filterwarnings("ignore", category=DeprecationWarning,
14 message="object.__new__\(\) takes no parameters",
16 warnings.filterwarnings("ignore", category=DeprecationWarning,
17 message="The popen2 module is deprecated. Use the subprocess module.",
19 warnings.filterwarnings("ignore", category=DeprecationWarning,
20 message="the md5 module is deprecated; use hashlib instead",
22 warnings.filterwarnings("ignore", category=DeprecationWarning,
23 message="the sha module is deprecated; use the hashlib module instead",
25 warnings.filterwarnings("ignore", category=DeprecationWarning,
26 message="twisted.web.error.NoResource is deprecated since Twisted 9.0. See twisted.web.resource.NoResource.",
30 from twisted.persisted import sob
31 from twisted.python import filepath
32 hush_pyflakes = (nevow, sob, filepath)
35 warnings.filters.pop()
36 warnings.filters.pop()
37 warnings.filters.pop()
38 warnings.filters.pop()
40 __version__ = "unknown"
42 from _version import __version__
44 # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
45 # come with a _version.py, so we don't know what our version is. This should
46 # not happen very often.
49 __appname__ = "unknown"
51 from _appname import __appname__
53 # We're running in a tree that hasn't run "./setup.py". This shouldn't happen.
56 # __full_version__ is the one that you ought to use when identifying yourself in the
57 # "application" part of the Tahoe versioning scheme:
58 # http://allmydata.org/trac/tahoe/wiki/Versioning
59 __full_version__ = __appname__ + '/' + str(__version__)
62 _auto_deps.require_auto_deps()
64 import os, platform, re, subprocess, sys
65 _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
66 _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
68 _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
69 _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
71 global _distname,_version
75 def get_linux_distro():
76 """ Tries to determine the name of the Linux OS distribution name.
78 First, try to parse a file named "/etc/lsb-release". If it exists, and
79 contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
80 the strings parsed from that file.
82 If that doesn't work, then invoke platform.dist().
84 If that doesn't work, then try to execute "lsb_release", as standardized in
87 http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
89 The current version of the standard is here:
91 http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
93 that lsb_release emitted, as strings.
95 Returns a tuple (distname,version). Distname is what LSB calls a
96 "distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
99 A version of this has been submitted to python as a patch for the standard
100 library module "platform":
102 http://bugs.python.org/issue3937
104 global _distname,_version
105 if _distname and _version:
106 return (_distname, _version)
109 etclsbrel = open("/etc/lsb-release", "rU")
110 for line in etclsbrel:
111 m = _distributor_id_file_re.search(line)
113 _distname = m.group(1).strip()
114 if _distname and _version:
115 return (_distname, _version)
116 m = _release_file_re.search(line)
118 _version = m.group(1).strip()
119 if _distname and _version:
120 return (_distname, _version)
121 except EnvironmentError:
124 (_distname, _version) = platform.dist()[:2]
125 if _distname and _version:
126 return (_distname, _version)
129 p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
132 for line in p.stdout.readlines():
133 m = _distributor_id_cmdline_re.search(line)
135 _distname = m.group(1).strip()
136 if _distname and _version:
137 return (_distname, _version)
139 m = _release_cmdline_re.search(p.stdout.read())
141 _version = m.group(1).strip()
142 if _distname and _version:
143 return (_distname, _version)
144 except EnvironmentError:
147 if os.path.exists("/etc/arch-release"):
148 return ("Arch_Linux", "")
150 return (_distname,_version)
153 # Our version of platform.platform(), telling us both less and more than the
154 # Python Standard Library's version does.
155 # We omit details such as the Linux kernel version number, but we add a
156 # more detailed and correct rendition of the Linux distribution and
157 # distribution-version.
158 if "linux" in platform.system().lower():
159 return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
161 return platform.platform()
163 def get_package_versions_and_locations():
164 # because there are a few dependencies that are outside setuptools's ken
165 # (Python and platform, and sqlite3 if you are on Python >= 2.5), and
166 # because setuptools might fail to find something even though import
168 import OpenSSL, allmydata, foolscap.api, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec, zope.interface
176 from pysqlite2 import dbapi2
180 pysqlitever = dbapi2.version
181 pysqlitefile = os.path.dirname(dbapi2.__file__)
182 sqlitever = dbapi2.sqlite_version
184 pysqlitever = sqlite3.version
185 pysqlitefile = os.path.dirname(sqlite3.__file__)
186 sqlitever = sqlite3.sqlite_version
189 'pyOpenSSL': (OpenSSL.__version__, os.path.dirname(OpenSSL.__file__)),
190 'allmydata-tahoe': (allmydata.__version__, os.path.dirname(allmydata.__file__)),
191 'foolscap': (foolscap.api.__version__, os.path.dirname(foolscap.__file__)),
192 'Nevow': (nevow.__version__, os.path.dirname(nevow.__file__)),
193 'pycryptopp': (pycryptopp.__version__, os.path.dirname(pycryptopp.__file__)),
194 'setuptools': (setuptools.__version__, os.path.dirname(setuptools.__file__)),
195 'simplejson': (simplejson.__version__, os.path.dirname(simplejson.__file__)),
196 'pysqlite': (pysqlitever, pysqlitefile),
197 'sqlite': (sqlitever, 'unknown'),
198 'zope.interface': ('unknown', os.path.dirname(zope.interface.__file__)),
199 'Twisted': (twisted.__version__, os.path.dirname(twisted.__file__)),
200 'zfec': (zfec.__version__, os.path.dirname(zfec.__file__)),
201 'python': (platform.python_version(), sys.executable),
202 'platform': (get_platform(), None),
205 # But we prefer to get all the dependencies as known by setuptools:
208 d2 = _auto_deps.get_package_versions_from_setuptools()
209 except pkg_resources.DistributionNotFound:
210 # See docstring in _auto_deps.require_auto_deps() to explain why it makes sense to ignore this exception.
217 def get_package_versions():
218 return dict([(k, v) for k, (v, l) in get_package_versions_and_locations().iteritems()])
220 def get_package_locations():
221 return dict([(k, l) for k, (v, l) in get_package_versions_and_locations().iteritems()])
223 def get_package_versions_string(show_paths=False):
224 vers_and_locs = get_package_versions_and_locations()
226 for p in ["allmydata-tahoe", "foolscap", "pycryptopp", "zfec", "Twisted", "Nevow", "zope.interface", "python", "platform"]:
227 (ver, loc) = vers_and_locs.get(p, ('UNKNOWN', 'UNKNOWN'))
228 info = str(p) + ": " + str(ver)
230 info = info + " (%s)" % str(loc)
232 if vers_and_locs.has_key(p):
235 for p, (v, loc) in vers_and_locs.iteritems():
236 info = str(p) + ": " + str(v)
238 info = info + " (%s)" % str(loc)
240 return ', '.join(res)