PageRenderTime 29ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/build_version.py

https://bitbucket.org/lindenlab/viewer-beta/
Python | 77 lines | 35 code | 6 blank | 36 comment | 9 complexity | aad118dfc3f991eb8ce5c1888e8b59b6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. #!/usr/bin/env python
  2. """\
  3. @file build_version.py
  4. @brief Print the build information embedded in a header file.
  5. Expects to be invoked from the command line with a file name and a
  6. list of directories to search. The file name will be one of the
  7. following:
  8. llversionserver.h
  9. llversionviewer.h
  10. The directory list that follows will include indra/llcommon, where
  11. these files live.
  12. $LicenseInfo:firstyear=2010&license=viewerlgpl$
  13. Second Life Viewer Source Code
  14. Copyright (C) 2010-2011, Linden Research, Inc.
  15. This library is free software; you can redistribute it and/or
  16. modify it under the terms of the GNU Lesser General Public
  17. License as published by the Free Software Foundation;
  18. version 2.1 of the License only.
  19. This library is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  22. Lesser General Public License for more details.
  23. You should have received a copy of the GNU Lesser General Public
  24. License along with this library; if not, write to the Free Software
  25. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  27. $/LicenseInfo$
  28. """
  29. import errno, os, re
  30. def get_version(filename):
  31. fp = open(filename)
  32. data = fp.read()
  33. fp.close()
  34. vals = {}
  35. m = re.search('const S32 LL_VERSION_MAJOR = (\d+);', data)
  36. vals['major'] = m.group(1)
  37. m = re.search('const S32 LL_VERSION_MINOR = (\d+);', data)
  38. vals['minor'] = m.group(1)
  39. m = re.search('const S32 LL_VERSION_PATCH = (\d+);', data)
  40. vals['patch'] = m.group(1)
  41. m = re.search('const S32 LL_VERSION_BUILD = (\d+);', data)
  42. vals['build'] = m.group(1)
  43. return "%(major)s.%(minor)s.%(patch)s.%(build)s" % vals
  44. if __name__ == '__main__':
  45. import sys
  46. try:
  47. for path in sys.argv[2:]:
  48. name = os.path.join(path, sys.argv[1])
  49. try:
  50. print get_version(name)
  51. break
  52. except OSError, err:
  53. if err.errno != errno.ENOENT:
  54. raise
  55. else:
  56. print >> sys.stderr, 'File not found:', sys.argv[1]
  57. sys.exit(1)
  58. except AttributeError:
  59. print >> sys.stderr, 'Error: malformatted file: ', name
  60. sys.exit(1)
  61. except IndexError:
  62. print >> sys.stderr, ('Usage: %s llversion[...].h [directories]' %
  63. sys.argv[0])