PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

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

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