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",
27 from twisted.persisted import sob
28 from twisted.python import filepath
29 hush_pyflakes = (nevow, sob, filepath)
32 warnings.filters.pop()
33 warnings.filters.pop()
34 warnings.filters.pop()
35 warnings.filters.pop()
37 __version__ = "unknown"
39 from _version import __version__
41 # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
42 # come with a _version.py, so we don't know what our version is. This should
43 # not happen very often.
46 __appname__ = "unknown"
48 from _appname import __appname__
50 # We're running in a tree that hasn't run "./setup.py". This shouldn't happen.
53 # __full_version__ is the one that you ought to use when identifying yourself in the
54 # "application" part of the Tahoe versioning scheme:
55 # http://allmydata.org/trac/tahoe/wiki/Versioning
56 __full_version__ = __appname__ + '/' + str(__version__)
59 _auto_deps.require_auto_deps()
61 import os, platform, re, subprocess, sys
62 _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
63 _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
65 _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
66 _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
68 global _distname,_version
72 def get_linux_distro():
73 """ Tries to determine the name of the Linux OS distribution name.
75 First, try to parse a file named "/etc/lsb-release". If it exists, and
76 contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
77 the strings parsed from that file.
79 If that doesn't work, then invoke platform.dist().
81 If that doesn't work, then try to execute "lsb_release", as standardized in
84 http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
86 The current version of the standard is here:
88 http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
90 that lsb_release emitted, as strings.
92 Returns a tuple (distname,version). Distname is what LSB calls a
93 "distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
96 A version of this has been submitted to python as a patch for the standard
97 library module "platform":
99 http://bugs.python.org/issue3937
101 global _distname,_version
102 if _distname and _version:
103 return (_distname, _version)
106 etclsbrel = open("/etc/lsb-release", "rU")
107 for line in etclsbrel:
108 m = _distributor_id_file_re.search(line)
110 _distname = m.group(1).strip()
111 if _distname and _version:
112 return (_distname, _version)
113 m = _release_file_re.search(line)
115 _version = m.group(1).strip()
116 if _distname and _version:
117 return (_distname, _version)
118 except EnvironmentError:
121 (_distname, _version) = platform.dist()[:2]
122 if _distname and _version:
123 return (_distname, _version)
126 p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
129 for line in p.stdout.readlines():
130 m = _distributor_id_cmdline_re.search(line)
132 _distname = m.group(1).strip()
133 if _distname and _version:
134 return (_distname, _version)
136 m = _release_cmdline_re.search(p.stdout.read())
138 _version = m.group(1).strip()
139 if _distname and _version:
140 return (_distname, _version)
141 except EnvironmentError:
144 if os.path.exists("/etc/arch-release"):
145 return ("Arch_Linux", "")
147 return (_distname,_version)
150 # Our version of platform.platform(), telling us both less and more than the
151 # Python Standard Library's version does.
152 # We omit details such as the Linux kernel version number, but we add a
153 # more detailed and correct rendition of the Linux distribution and
154 # distribution-version.
155 if "linux" in platform.system().lower():
156 return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
158 return platform.platform()
160 def get_package_versions_and_locations():
161 # because there are a few dependencies that are outside setuptools's ken
162 # (Python and platform, and sqlite3 if you are on Python >= 2.5), and
163 # because setuptools might fail to find something even though import
165 import OpenSSL, allmydata, foolscap.api, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec, zope.interface
173 from pysqlite2 import dbapi2
177 pysqlitever = dbapi2.version
178 pysqlitefile = os.path.dirname(dbapi2.__file__)
179 sqlitever = dbapi2.sqlite_version
181 pysqlitever = sqlite3.version
182 pysqlitefile = os.path.dirname(sqlite3.__file__)
183 sqlitever = sqlite3.sqlite_version
186 'pyOpenSSL': (OpenSSL.__version__, os.path.dirname(OpenSSL.__file__)),
187 'allmydata-tahoe': (allmydata.__version__, os.path.dirname(allmydata.__file__)),
188 'foolscap': (foolscap.api.__version__, os.path.dirname(foolscap.__file__)),
189 'Nevow': (nevow.__version__, os.path.dirname(nevow.__file__)),
190 'pycryptopp': (pycryptopp.__version__, os.path.dirname(pycryptopp.__file__)),
191 'setuptools': (setuptools.__version__, os.path.dirname(setuptools.__file__)),
192 'simplejson': (simplejson.__version__, os.path.dirname(simplejson.__file__)),
193 'pysqlite': (pysqlitever, pysqlitefile),
194 'sqlite': (sqlitever, 'unknown'),
195 'zope.interface': ('unknown', os.path.dirname(zope.interface.__file__)),
196 'Twisted': (twisted.__version__, os.path.dirname(twisted.__file__)),
197 'zfec': (zfec.__version__, os.path.dirname(zfec.__file__)),
198 'python': (platform.python_version(), sys.executable),
199 'platform': (get_platform(), None),
202 # But we prefer to get all the dependencies as known by setuptools:
205 d2 = _auto_deps.get_package_versions_from_setuptools()
206 except pkg_resources.DistributionNotFound:
207 # See docstring in _auto_deps.require_auto_deps() to explain why it makes sense to ignore this exception.
214 def get_package_versions():
215 return dict([(k, v) for k, (v, l) in get_package_versions_and_locations().iteritems()])
217 def get_package_locations():
218 return dict([(k, l) for k, (v, l) in get_package_versions_and_locations().iteritems()])
220 def get_package_versions_string(show_paths=False):
221 vers_and_locs = get_package_versions_and_locations()
223 for p in ["allmydata-tahoe", "foolscap", "pycryptopp", "zfec", "Twisted", "Nevow", "zope.interface", "python", "platform"]:
224 (ver, loc) = vers_and_locs.get(p, ('UNKNOWN', 'UNKNOWN'))
225 info = str(p) + ": " + str(ver)
227 info = info + " (%s)" % str(loc)
229 if vers_and_locs.has_key(p):
232 for p, (v, loc) in vers_and_locs.iteritems():
233 info = str(p) + ": " + str(v)
235 info = info + " (%s)" % str(loc)
237 return ', '.join(res)