From 7a5a907f4918b20cf77d2a3ed33ef5e6d8c3844a Mon Sep 17 00:00:00 2001
From: Jacek Antonelli
Date: Thu, 19 May 2011 00:40:19 -0500
Subject: Ported viewer_info.py and BuildVersion.cmake from Kokua.
viewer_info.py provides a way to easily query the viewer name and
version (from viewerinfo.cpp). It replaces build_version.py, which has
been removed. BuildVersion.cmake has been updated to use
viewer_info.py instead of build_version.py.
---
linden/scripts/build_version.py | 62 ------------------------
linden/scripts/viewer_info.py | 101 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+), 62 deletions(-)
delete mode 100755 linden/scripts/build_version.py
create mode 100755 linden/scripts/viewer_info.py
(limited to 'linden/scripts')
diff --git a/linden/scripts/build_version.py b/linden/scripts/build_version.py
deleted file mode 100755
index f6b88a9..0000000
--- a/linden/scripts/build_version.py
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python
-#
-# Print the build information embedded in a header file.
-#
-# Expects to be invoked from the command line with a file name and a
-# list of directories to search. The file name will be one of the
-# following:
-#
-# llversionserver.h
-# llversionviewer.h
-#
-# The directory list that follows will include indra/llcommon, where
-# these files live.
-
-import errno, os, re
-
-def get_version(filename):
- fp = open(filename)
- data = fp.read()
- fp.close()
-
- vals = {}
- m = re.search('', data)
- vals['major'] = m.group(1)
- m = re.search('', data)
- vals['minor'] = m.group(1)
- m = re.search('', data)
- vals['patch'] = m.group(1)
- m = re.search('', data)
- vals['test'] = m.group(1)
-
- version = "%(major)s.%(minor)s.%(patch)s" % vals
-
- if len(vals['test']) > 0:
- # Replace some puncuation and spaces with '-' in the test version
- vals['test'] = re.sub('[ \t:;,+/\\"\'`]+', '-', vals['test'])
- version += "-%(test)s" % vals
-
- return version
-
-
-if __name__ == '__main__':
- import sys
-
- try:
- for path in sys.argv[2:]:
- name = os.path.join(path, sys.argv[1])
- try:
- print get_version(name)
- break
- except OSError, err:
- if err.errno != errno.ENOENT:
- raise
- else:
- print >> sys.stderr, 'File not found:', sys.argv[1]
- sys.exit(1)
- except AttributeError:
- print >> sys.stderr, 'Error: malformatted file: ', name
- sys.exit(1)
- except IndexError:
- print >> sys.stderr, ('Usage: %s llversion[...].h [directories]' %
- sys.argv[0])
diff --git a/linden/scripts/viewer_info.py b/linden/scripts/viewer_info.py
new file mode 100755
index 0000000..53ea432
--- /dev/null
+++ b/linden/scripts/viewer_info.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+#
+# @file viewer_info.py
+# @author Jacek Antonelli
+# @brief Scans and prints the viewer name and/or version.
+#
+# Copyright (c) 2010, Jacek Antonelli
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+#
+# Usage:
+#
+# viewer_info.py --name # viewer name (e.g. "Kokua")
+# viewer_info.py --version # viewer version (e.g. "1.0.0-RC1"
+# viewer_info.py --combined # name + version (e.g. "Kokua-1.0.0-RC1")
+#
+# You can pass multiple flags to print each thing on a separate line.
+# E.g. `viewer_info.py --name --version' will print 2 lines, e.g.:
+#
+# Kokua
+# 1.0.0-RC1
+#
+
+import errno, os, re, string, sys
+
+
+class ViewerInfo:
+
+ def __init__(self, filepath=None):
+ f = open(filepath or self.default_file())
+ data = f.read()
+ f.close()
+
+ self.name = re.search('NAME\s*=\s*"([^"]*)"', data).group(1)
+ self.major = re.search('MAJOR\s*=\s*(\d+)', data).group(1)
+ self.minor = re.search('MINOR\s*=\s*(\d+)', data).group(1)
+ self.patch = re.search('PATCH\s*=\s*(\d+)', data).group(1)
+ self.extra = re.search('EXTRA\s*=\s*"([^"]*)"', data).group(1)
+ self.bundle_id = re.search('BUNDLE_ID\s*=\s*"([^"]*)"', data).group(1)
+
+ self.version = "%s.%s.%s"%(self.major, self.minor, self.patch)
+ if len(self.extra) > 0:
+ # Replace spaces and some puncuation with '-' in extra
+ extra = re.sub('[- \t:;,!+/\\"\'`]+', '-', self.extra)
+ # Strip any leading or trailing "-"s
+ extra = string.strip(extra, '-')
+ self.version += "-" + extra
+
+ self.combined = self.name + "-" + self.version
+
+ @classmethod
+ def default_file(klass):
+ scripts_dir = sys.path[0] # directory containing this script
+ viewerinfo = os.path.join('indra', 'newview', 'viewerinfo.cpp')
+ filepath = os.path.join(scripts_dir, '..', viewerinfo)
+ return os.path.abspath(filepath)
+
+
+if __name__ == '__main__':
+
+ try:
+ info = ViewerInfo()
+ except IOError, err:
+ if err.errno == errno.ENOENT:
+ print >> sys.stderr, 'File not found:', ViewerInfo.default_file()
+ sys.exit(1)
+ else:
+ raise
+
+ args = sys.argv[1:]
+
+ if not args:
+ print "Usage: %s [--name] [--version] [--combined]"%(sys.argv[0])
+ for arg in args:
+ if '--name' == arg:
+ print info.name
+ elif '--version' == arg:
+ print info.version
+ elif '--combined' == arg:
+ print info.combined
+ elif '--bundle-id' == arg:
+ print info.bundle_id
--
cgit v1.1