You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Adapted by Nicolas Bessi. Copyright Camptocamp SA
  5. # Based on Florent Xicluna original code. Copyright Wingo SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. import locale
  22. import os
  23. import platform
  24. import subprocess
  25. from openerp import release
  26. from openerp.tools.config import config
  27. def _get_output(cmd):
  28. bindir = config['root_path']
  29. p = subprocess.Popen(cmd, shell=True, cwd=bindir, stdout=subprocess.PIPE,
  30. stderr=subprocess.STDOUT)
  31. return p.communicate()[0].rstrip()
  32. def get_server_environment():
  33. # inspired by server/bin/service/web_services.py
  34. try:
  35. rev_id = 'git:%s' % _get_output('git rev-parse HEAD')
  36. except Exception:
  37. try:
  38. rev_id = 'bzr: %s' % _get_output('bzr revision-info')
  39. except Exception:
  40. rev_id = 'Can not retrive revison from git or bzr'
  41. os_lang = '.'.join([x for x in locale.getdefaultlocale() if x])
  42. if not os_lang:
  43. os_lang = 'NOT SET'
  44. if os.name == 'posix' and platform.system() == 'Linux':
  45. lsbinfo = _get_output('lsb_release -a')
  46. else:
  47. lsbinfo = 'not lsb compliant'
  48. return (
  49. ('platform', platform.platform()),
  50. ('os.name', os.name),
  51. ('lsb_release', lsbinfo),
  52. ('release', platform.release()),
  53. ('version', platform.version()),
  54. ('architecture', platform.architecture()[0]),
  55. ('locale', os_lang),
  56. ('python', platform.python_version()),
  57. ('openerp', release.version),
  58. ('revision', rev_id),
  59. )