source file: /home/buildslave/tahoe/edgy/build/src/allmydata/__init__.py
file stats: 73 lines, 27 executed: 37.0% covered
   1. """
   2. Decentralized storage grid.
   3. 
   4. maintainer web site: U{http://allmydata.com/}
   5. 
   6. community web site: U{http://allmydata.org/}
   7. """
   8. 
   9. __version__ = "unknown"
  10. try:
  11.     from _version import __version__
  12. except ImportError:
  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.
  16.     pass
  17. 
  18. hush_pyflakes = __version__
  19. del hush_pyflakes
  20. 
  21. import _auto_deps
  22. _auto_deps.require_auto_deps()
  23. 
  24. import platform, re, subprocess
  25. _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
  26. _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
  27. 
  28. _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
  29. _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
  30. 
  31. global _distname,_version
  32. _distname = None
  33. _version = None
  34. 
  35. def get_linux_distro():
  36.     """ Tries to determine the name of the Linux OS distribution name.
  37. 
  38.     First, try to parse a file named "/etc/lsb-release".  If it exists, and
  39.     contains the "DISTRIB_ID=" line and the "DISTRIB_RELEASE=" line, then return
  40.     the strings parsed from that file.
  41. 
  42.     If that doesn't work, then invoke platform.dist().
  43. 
  44.     If that doesn't work, then try to execute "lsb_release", as standardized in
  45.     2001:
  46. 
  47.     http://refspecs.freestandards.org/LSB_1.0.0/gLSB/lsbrelease.html
  48. 
  49.     The current version of the standard is here:
  50. 
  51.     http://refspecs.freestandards.org/LSB_3.2.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html
  52. 
  53.     that lsb_release emitted, as strings.
  54. 
  55.     Returns a tuple (distname,version). Distname is what LSB calls a
  56.     "distributor id", e.g. "Ubuntu".  Version is what LSB calls a "release",
  57.     e.g. "8.04".
  58. 
  59.     A version of this has been submitted to python as a patch for the standard
  60.     library module "platform":
  61. 
  62.     http://bugs.python.org/issue3937
  63.     """
  64.     global _distname,_version
  65.     if _distname and _version:
  66.         return (_distname, _version)
  67. 
  68.     try:
  69.         etclsbrel = open("/etc/lsb-release", "rU")
  70.         for line in etclsbrel:
  71.             m = _distributor_id_file_re.search(line)
  72.             if m:
  73.                 _distname = m.group(1).strip()
  74.                 if _distname and _version:
  75.                     return (_distname, _version)
  76.             m = _release_file_re.search(line)
  77.             if m:
  78.                 _version = m.group(1).strip()
  79.                 if _distname and _version:
  80.                     return (_distname, _version)
  81.     except EnvironmentError:
  82.             pass
  83. 
  84.     (_distname, _version) = platform.dist()[:2]
  85.     if _distname and _version:
  86.         return (_distname, _version)
  87. 
  88.     try:
  89.         p = subprocess.Popen(["lsb_release", "--all"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  90.         rc = p.wait()
  91.         if rc == 0:
  92.             for line in p.stdout.readlines():
  93.                 m = _distributor_id_cmdline_re.search(line)
  94.                 if m:
  95.                     _distname = m.group(1).strip()
  96.                     if _distname and _version:
  97.                         return (_distname, _version)
  98. 
  99.                 m = _release_cmdline_re.search(p.stdout.read())
 100.                 if m:
 101.                     _version = m.group(1).strip()
 102.                     if _distname and _version:
 103.                         return (_distname, _version)
 104.     except EnvironmentError:
 105.         pass
 106. 
 107.     return (_distname,_version)
 108. 
 109. def get_platform():
 110.     # Our version of platform.platform(), telling us both less and more than the
 111.     # Python Standard Library's version does.
 112.     # We omit details such as the Linux kernel version number, but we add a
 113.     # more detailed and correct rendition of the Linux distribution and
 114.     # distribution-version.
 115.     if "linux" in platform.system().lower():
 116.         return platform.system()+"-"+"_".join(get_linux_distro())+"-"+platform.machine()+"-"+"_".join([x for x in platform.architecture() if x])
 117.     else:
 118.         return platform.platform()
 119. 
 120. def get_package_versions():
 121.     import OpenSSL, allmydata, foolscap, nevow, platform, pycryptopp, setuptools, simplejson, twisted, zfec
 122. 
 123.     return {
 124.         'pyopenssl': OpenSSL.__version__,
 125.         'allmydata': allmydata.__version__,
 126.         'foolscap': foolscap.__version__,
 127.         'nevow': nevow.__version__,
 128.         'pycryptopp': pycryptopp.__version__,
 129.         'setuptools': setuptools.__version__,
 130.         'simplejson': simplejson.__version__,
 131.         'twisted': twisted.__version__,
 132.         'zfec': zfec.__version__,
 133.         'python': platform.python_version(),
 134.         'platform': get_platform()
 135.         }
 136. 
 137. def get_package_versions_string():
 138.     versions = get_package_versions()
 139.     res = []
 140.     for p in ["allmydata", "foolscap", "pycryptopp", "zfec", "twisted", "nevow", "python", "platform"]:
 141.         if versions.has_key(p):
 142.             res.append(str(p) + ": " + str(versions[p]))
 143.             del versions[p]
 144.         else:
 145.             res.append(str(p) + ": UNKNOWN")
 146.     for p, v in versions.iteritems():
 147.         res.append(str(p) + ": " + str(v))
 148.     return ', '.join(res)