aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/scripts
diff options
context:
space:
mode:
authorJacek Antonelli2011-05-19 00:40:19 -0500
committerJacek Antonelli2011-05-19 00:40:19 -0500
commit7a5a907f4918b20cf77d2a3ed33ef5e6d8c3844a (patch)
tree84dfe9623a32a7c434536b3ca8a7f018f01ec5ee /linden/scripts
parentPorted viewerinfo.cpp from Kokua. (diff)
downloadmeta-impy-7a5a907f4918b20cf77d2a3ed33ef5e6d8c3844a.zip
meta-impy-7a5a907f4918b20cf77d2a3ed33ef5e6d8c3844a.tar.gz
meta-impy-7a5a907f4918b20cf77d2a3ed33ef5e6d8c3844a.tar.bz2
meta-impy-7a5a907f4918b20cf77d2a3ed33ef5e6d8c3844a.tar.xz
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.
Diffstat (limited to 'linden/scripts')
-rwxr-xr-xlinden/scripts/build_version.py62
-rwxr-xr-xlinden/scripts/viewer_info.py101
2 files changed, 101 insertions, 62 deletions
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 @@
1#!/usr/bin/env python
2#
3# Print the build information embedded in a header file.
4#
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#
9# llversionserver.h
10# llversionviewer.h
11#
12# The directory list that follows will include indra/llcommon, where
13# these files live.
14
15import errno, os, re
16
17def get_version(filename):
18 fp = open(filename)
19 data = fp.read()
20 fp.close()
21
22 vals = {}
23 m = re.search('<viewer version_major="(\d+)" />', data)
24 vals['major'] = m.group(1)
25 m = re.search('<viewer version_minor="(\d+)" />', data)
26 vals['minor'] = m.group(1)
27 m = re.search('<viewer version_patch="(\d+)" />', data)
28 vals['patch'] = m.group(1)
29 m = re.search('<viewer version_test="(.*)" />', data)
30 vals['test'] = m.group(1)
31
32 version = "%(major)s.%(minor)s.%(patch)s" % vals
33
34 if len(vals['test']) > 0:
35 # Replace some puncuation and spaces with '-' in the test version
36 vals['test'] = re.sub('[ \t:;,+/\\"\'`]+', '-', vals['test'])
37 version += "-%(test)s" % vals
38
39 return version
40
41
42if __name__ == '__main__':
43 import sys
44
45 try:
46 for path in sys.argv[2:]:
47 name = os.path.join(path, sys.argv[1])
48 try:
49 print get_version(name)
50 break
51 except OSError, err:
52 if err.errno != errno.ENOENT:
53 raise
54 else:
55 print >> sys.stderr, 'File not found:', sys.argv[1]
56 sys.exit(1)
57 except AttributeError:
58 print >> sys.stderr, 'Error: malformatted file: ', name
59 sys.exit(1)
60 except IndexError:
61 print >> sys.stderr, ('Usage: %s llversion[...].h [directories]' %
62 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 @@
1#!/usr/bin/env python
2#
3# @file viewer_info.py
4# @author Jacek Antonelli
5# @brief Scans and prints the viewer name and/or version.
6#
7# Copyright (c) 2010, Jacek Antonelli
8#
9# Permission is hereby granted, free of charge, to any person
10# obtaining a copy of this software and associated documentation files
11# (the "Software"), to deal in the Software without restriction,
12# including without limitation the rights to use, copy, modify, merge,
13# publish, distribute, sublicense, and/or sell copies of the Software,
14# and to permit persons to whom the Software is furnished to do so,
15# subject to the following conditions:
16#
17# The above copyright notice and this permission notice shall be
18# included in all copies or substantial portions of the Software.
19#
20# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27# SOFTWARE.
28#
29#
30# Usage:
31#
32# viewer_info.py --name # viewer name (e.g. "Kokua")
33# viewer_info.py --version # viewer version (e.g. "1.0.0-RC1"
34# viewer_info.py --combined # name + version (e.g. "Kokua-1.0.0-RC1")
35#
36# You can pass multiple flags to print each thing on a separate line.
37# E.g. `viewer_info.py --name --version' will print 2 lines, e.g.:
38#
39# Kokua
40# 1.0.0-RC1
41#
42
43import errno, os, re, string, sys
44
45
46class ViewerInfo:
47
48 def __init__(self, filepath=None):
49 f = open(filepath or self.default_file())
50 data = f.read()
51 f.close()
52
53 self.name = re.search('NAME\s*=\s*"([^"]*)"', data).group(1)
54 self.major = re.search('MAJOR\s*=\s*(\d+)', data).group(1)
55 self.minor = re.search('MINOR\s*=\s*(\d+)', data).group(1)
56 self.patch = re.search('PATCH\s*=\s*(\d+)', data).group(1)
57 self.extra = re.search('EXTRA\s*=\s*"([^"]*)"', data).group(1)
58 self.bundle_id = re.search('BUNDLE_ID\s*=\s*"([^"]*)"', data).group(1)
59
60 self.version = "%s.%s.%s"%(self.major, self.minor, self.patch)
61 if len(self.extra) > 0:
62 # Replace spaces and some puncuation with '-' in extra
63 extra = re.sub('[- \t:;,!+/\\"\'`]+', '-', self.extra)
64 # Strip any leading or trailing "-"s
65 extra = string.strip(extra, '-')
66 self.version += "-" + extra
67
68 self.combined = self.name + "-" + self.version
69
70 @classmethod
71 def default_file(klass):
72 scripts_dir = sys.path[0] # directory containing this script
73 viewerinfo = os.path.join('indra', 'newview', 'viewerinfo.cpp')
74 filepath = os.path.join(scripts_dir, '..', viewerinfo)
75 return os.path.abspath(filepath)
76
77
78if __name__ == '__main__':
79
80 try:
81 info = ViewerInfo()
82 except IOError, err:
83 if err.errno == errno.ENOENT:
84 print >> sys.stderr, 'File not found:', ViewerInfo.default_file()
85 sys.exit(1)
86 else:
87 raise
88
89 args = sys.argv[1:]
90
91 if not args:
92 print "Usage: %s [--name] [--version] [--combined]"%(sys.argv[0])
93 for arg in args:
94 if '--name' == arg:
95 print info.name
96 elif '--version' == arg:
97 print info.version
98 elif '--combined' == arg:
99 print info.combined
100 elif '--bundle-id' == arg:
101 print info.bundle_id