PageRenderTime 344ms CodeModel.GetById 181ms app.highlight 6ms RepoModel.GetById 155ms app.codeStats 0ms

/scripts/build_version.py

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