source: rtems-source-builder/source-builder/sb/version.py @ 29f23e0

4.104.95
Last change on this file since 29f23e0 was 29f23e0, checked in by Chris Johns <chrisj@…>, on 03/10/16 at 03:52:25

sb: Fix configparser import on Python2 in version.py.

Updates #2619.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1#
2# RTEMS Tools Project (http://www.rtems.org/)
3# Copyright 2010-2016 Chris Johns (chrisj@rtems.org)
4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
8# Permission to use, copy, modify, and/or distribute this software for any
9# purpose with or without fee is hereby granted, provided that the above
10# copyright notice and this permission notice appear in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#
21# To release the RSB create a git archive and then add a suitable VERSION file
22# to the top directory.
23#
24
25from __future__ import print_function
26
27import sys
28
29import error
30import git
31import path
32import sources
33
34#
35# Default to an internal string.
36#
37_version = '4.12'
38_revision = 'not_released'
39_version_str = '%s.%s' % (_version, _revision)
40_released = False
41_git = False
42
43def _top():
44    top = path.dirname(sys.argv[0])
45    if len(top) == 0:
46        top = '.'
47    return top
48
49def _load_released_version_config():
50    top = _top()
51    for ver in [top, '..']:
52        if path.exists(path.join(ver, 'VERSION')):
53            try:
54                import configparser
55            except ImportError:
56                import ConfigParser as configparser
57            v = configparser.SafeConfigParser()
58            v.read(path.join(ver, 'VERSION'))
59            return v
60    return None
61
62def _load_released_version():
63    global _released
64    global _version_str
65    v = _load_released_version_config()
66    if v is not None:
67        _version_str = v.get('version', 'release')
68        _released = True
69    return _released
70
71def _load_git_version():
72    global _git
73    global _version_str
74    repo = git.repo(_top())
75    if repo.valid():
76        head = repo.head()
77        if repo.dirty():
78            modified = ' modified'
79        else:
80            modified = ''
81        _version_str = '%s (%s%s)' % (_version, head[0:12], modified)
82        _git = True
83    return _git
84
85def released():
86    return _load_released_version()
87
88def version_control():
89    return _load_git_version()
90
91def str():
92    if not _released and not _git:
93        if not _load_released_version():
94            _load_git_version()
95    return _version_str
96
97def load_release_hashes(macros):
98    def hash_error(msg):
99        raise error.general(msg)
100
101    if released():
102        v = _load_released_version_config()
103        if v is not None:
104            try:
105                hashes = v.items('hashes')
106            except:
107                hashes = []
108            for hash in hashes:
109                hs = hash[1].split()
110                if len(hs) != 2:
111                    raise error.general('invalid release hash in VERSION')
112                sources.hash((hs[0], hash[0], hs[1]), macros, hash_error)
113
114if __name__ == '__main__':
115    print('Version: %s' % (str()))
Note: See TracBrowser for help on using the repository browser.