/indra/lib/python/indra/util/llversion.py

https://bitbucket.org/lindenlab/viewer-beta/ · Python · 107 lines · 76 code · 13 blank · 18 comment · 4 complexity · 7e21e56cc4092a92c456c7167ea74be4 MD5 · raw file

  1. #!/usr/bin/env python
  2. """\
  3. @file llversion.py
  4. @brief Parses llcommon/llversionserver.h and llcommon/llversionviewer.h
  5. for the version string and channel string.
  6. Parses hg info for branch and revision.
  7. $LicenseInfo:firstyear=2006&license=mit$
  8. Copyright (c) 2006-2009, Linden Research, Inc.
  9. Permission is hereby granted, free of charge, to any person obtaining a copy
  10. of this software and associated documentation files (the "Software"), to deal
  11. in the Software without restriction, including without limitation the rights
  12. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. copies of the Software, and to permit persons to whom the Software is
  14. furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in
  16. all copies or substantial portions of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. THE SOFTWARE.
  24. $/LicenseInfo$
  25. """
  26. import re, sys, os, subprocess
  27. # Methods for gathering version information from
  28. # llversionviewer.h and llversionserver.h
  29. def get_src_root():
  30. indra_lib_python_indra_path = os.path.dirname(__file__)
  31. return os.path.abspath(os.path.realpath(indra_lib_python_indra_path + "/../../../../../"))
  32. def get_version_file_contents(version_type):
  33. filepath = get_src_root() + '/indra/llcommon/llversion%s.h' % version_type
  34. file = open(filepath,"r")
  35. file_str = file.read()
  36. file.close()
  37. return file_str
  38. def get_version(version_type):
  39. file_str = get_version_file_contents(version_type)
  40. m = re.search('const S32 LL_VERSION_MAJOR = (\d+);', file_str)
  41. VER_MAJOR = m.group(1)
  42. m = re.search('const S32 LL_VERSION_MINOR = (\d+);', file_str)
  43. VER_MINOR = m.group(1)
  44. m = re.search('const S32 LL_VERSION_PATCH = (\d+);', file_str)
  45. VER_PATCH = m.group(1)
  46. m = re.search('const S32 LL_VERSION_BUILD = (\d+);', file_str)
  47. VER_BUILD = m.group(1)
  48. version = "%(VER_MAJOR)s.%(VER_MINOR)s.%(VER_PATCH)s.%(VER_BUILD)s" % locals()
  49. return version
  50. def get_channel(version_type):
  51. file_str = get_version_file_contents(version_type)
  52. m = re.search('const char \* const LL_CHANNEL = "(.+)";', file_str)
  53. return m.group(1)
  54. def get_viewer_version():
  55. return get_version('viewer')
  56. def get_server_version():
  57. return get_version('server')
  58. def get_viewer_channel():
  59. return get_channel('viewer')
  60. def get_server_channel():
  61. return get_channel('server')
  62. # Methods for gathering hg information
  63. def get_hg_repo():
  64. child = subprocess.Popen(["hg","showconfig","paths.default"], stdout=subprocess.PIPE)
  65. output, error = child.communicate()
  66. status = child.returncode
  67. if status:
  68. print >> sys.stderr, error
  69. sys.exit(1)
  70. if not output:
  71. print >> sys.stderr, 'ERROR: cannot find repo we cloned from'
  72. sys.exit(1)
  73. return output
  74. def get_hg_changeset():
  75. # The right thing to do would be to use the *global* revision id:
  76. # "hg id -i"
  77. # For the moment though, we use the parent revision:
  78. child = subprocess.Popen(["hg","parents","--template","{rev}"], stdout=subprocess.PIPE)
  79. output, error = child.communicate()
  80. status = child.returncode
  81. if status:
  82. print >> sys.stderr, error
  83. sys.exit(1)
  84. lines = output.splitlines()
  85. if len(lines) > 1:
  86. print >> sys.stderr, 'ERROR: working directory has %d parents' % len(lines)
  87. return lines[0]
  88. def using_hg():
  89. return os.path.isdir(os.path.join(get_src_root(), '.hg'))