2 Decentralized storage grid.
4 maintainer web site: U{http://allmydata.com/}
6 community web site: U{http://allmydata.org/}
9 __version__ = "unknown"
11 from _version import __version__
13 # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
14 # come with a _version.py, so we don't know what our version is. This should
15 # not happen very often.
18 __appname__ = "unknown"
20 from _appname import __appname__
22 # We're running in a tree that hasn't run "./setup.py". This shouldn't happen.
25 # __full_version__ is the one that you ought to use when identifying yourself in the
26 # "application" part of the Tahoe versioning scheme:
27 # http://allmydata.org/trac/tahoe/wiki/Versioning
28 __full_version__ = __appname__ + '/' + str(__version__)
30 hush_pyflakes = __version__
34 _auto_deps.require_auto_deps()
36 import os, platform, re, subprocess, sys
37 _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
38 _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
40 _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
41 _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
43 global _distname,_version
47 def get_linux_distro():
48 """ Tries to determine the name of the Linux OS distribution name.
50 First, try to parse a file named "/etc/lsb-release". If it exists, and
51 contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
52 the strings parsed from that file.
54 If that doesn't work, then invoke platform.dist().
56 If that doesn't work, then try to execute "lsb_release", as standardized in
59 http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
61 The current version of the standard is here:
63 http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
65 that lsb_release emitted, as strings.
67 Returns a tuple (distname,version). Distname is what LSB calls a
68 "distributor id", e.g. "Ubuntu". Version is what LSB calls a "release",
71 A version of this has been submitted to python as a patch for the standard
72 library module "platform":
74 http://bugs.python.org/issue3937
76 global _distname,_version
77 if _distname and _version:
78 return (_distname, _version)
81 etclsbrel = open("/etc/lsb-release", "rU")
82 for line in etclsbrel:
83 m = _distributor_id_file_re.search(line)
85 _distname = m.group(1).strip()
86 if _distname and _version:
87 return (_distname, _version)
88 m = _release_file_re.search(line)
90 _version = m.group(1).strip()
91 if _distname and _version:
92 return (_distname, _version)
93 except EnvironmentError:
96 (_distname, _version) = platform.dist()[:2]
97 if _distname and _version:
98 return (_distname, _version)
101 p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
104 for line in p.stdout.readlines():
105 m = _distributor_id_cmdline_re.search(line)
107 _distname = m.group(1).strip()
108 if _distname and _version:
109 return (_distname, _version)
111 m = _release_cmdline_re.search(p.stdout.read())
113 _version = m.group(1).strip()
114 if _distname and _version:
115 return (_distname, _version)
116 except EnvironmentError:
119 if os.path.exists("/etc/arch-release"):
120 return ("Arch_Linux", "")
122 return (_distname,_version)
125 # Our version of platform.platform(), telling us both less and more than the
126 # Python Standard Library's version does.
127 # We omit details such as the Linux kernel version number, but we add a
128 # more detailed and correct rendition of the Linux distribution and
129 # distribution-version.
130 if "linux" in platform.system().lower():
131 return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
133 return platform.platform()
135 def get_package_versions_and_locations():
136 # because there are a few dependencies that are outside setuptools's ken (Python and
137 # platform), and because setuptools might fail to find something even though import finds
139 import OpenSSL, allmydata, foolscap.api, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec, zope.interface
142 'pyOpenSSL': (OpenSSL.__version__, os.path.dirname(OpenSSL.__file__)),
143 'allmydata-tahoe': (allmydata.__version__, os.path.dirname(allmydata.__file__)),
144 'foolscap': (foolscap.api.__version__, os.path.dirname(foolscap.__file__)),
145 'Nevow': (nevow.__version__, os.path.dirname(nevow.__file__)),
146 'pycryptopp': (pycryptopp.__version__, os.path.dirname(pycryptopp.__file__)),
147 'setuptools': (setuptools.__version__, os.path.dirname(setuptools.__file__)),
148 'simplejson': (simplejson.__version__, os.path.dirname(simplejson.__file__)),
149 'zope.interface': ('unknown', os.path.dirname(zope.interface.__file__)),
150 'Twisted': (twisted.__version__, os.path.dirname(twisted.__file__)),
151 'zfec': (zfec.__version__, os.path.dirname(zfec.__file__)),
152 'python': (platform.python_version(), sys.executable),
153 'platform': (get_platform(), None),
156 # But we prefer to get all the dependencies as known by setuptools:
159 d2 = _auto_deps.get_package_versions_from_setuptools()
160 except pkg_resources.DistributionNotFound:
161 # See docstring in _auto_deps.require_auto_deps() to explain why it makes sense to ignore this exception.
168 def get_package_versions():
169 return dict([(k, v) for k, (v, l) in get_package_versions_and_locations().iteritems()])
171 def get_package_locations():
172 return dict([(k, l) for k, (v, l) in get_package_versions_and_locations().iteritems()])
174 def get_package_versions_string(show_paths=False):
175 vers_and_locs = get_package_versions_and_locations()
177 for p in ["allmydata-tahoe", "foolscap", "pycryptopp", "zfec", "Twisted", "Nevow", "zope.interface", "python", "platform"]:
178 (ver, loc) = vers_and_locs.get(p, ('UNKNOWN', 'UNKNOWN'))
179 info = str(p) + ": " + str(ver)
181 info = info + " (%s)" % str(loc)
183 if vers_and_locs.has_key(p):
186 for p, (v, loc) in vers_and_locs.iteritems():
187 info = str(p) + ": " + str(v)
189 info = info + " (%s)" % str(loc)
191 return ', '.join(res)