Debian Codegraph @

gtk-priv/scripts/version.py

raw
1 '''
2 MIT License
3
4 Copyright 2020 Sophie Winter
5
6 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:
7
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
10 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.
11 '''
12
13 import logging
14 import functools
15 import re
16
17 from config import MIN_SUPPORTED_GTK, MAX_SUPPORTED_GTK
18
19 logger = logging.getLogger(__name__)
20
21 COMBO_FACTOR = 1000
22
23 @functools.total_ordering # implement all comparisons with just eq and lt
24 class Version:
25 def __init__(self, git_name, minor, micro, released):
26 self.git_name = git_name
27 self.minor = minor
28 self.micro = micro
29 self.released = released
30
31 def __eq__(self, other):
32 return self.minor == other.minor and self.micro == other.micro
33
34 def __lt__(self, other):
35 if self.minor == other.minor:
36 return self.micro < other.micro
37 else:
38 return self.minor < other.minor
39
40 def get_checkout_name(self):
41 return self.git_name
42
43 def is_supported(self):
44 '''Returns if the version is one we support'''
45 return (
46 self >= min_supported_version and
47 self <= max_supported_version and
48 self != bad_release_3_24_19)
49
50 def is_released(self):
51 return self.released
52
53 def get_combo(self):
54 return self.minor * 1000 + self.micro
55
56 def __str__(self):
57 result = 'v3.' + str(self.minor) + '.' + str(self.micro)
58 if not self.is_released():
59 result += ' (unreleased)'
60 return result
61
62 def c_id(self):
63 '''a string suitable for a C identifier'''
64 return 'v3_' + str(self.minor) + '_' + str(self.micro)
65
66 def parse_tag(tag):
67 match = re.search(r'^3\.(\d+)\.(\d+)$', tag)
68 if match:
69 minor = int(match.group(1))
70 micro = int(match.group(2))
71 return Version(tag, minor, micro, True)
72 else:
73 return None
74
75 def parse_branch(branch):
76 match = re.search(r'^gtk\-3\-(\d+)$', branch)
77 if match:
78 minor = int(match.group(1))
79 return minor
80 else:
81 return None
82
83 min_supported_version = parse_tag(MIN_SUPPORTED_GTK)
84 max_supported_version = parse_tag(MAX_SUPPORTED_GTK)
85 bad_release_3_24_19 = parse_tag('3.24.19') # this is not a good release
86
87 def parse_tags_and_branches(tags, branches):
88 result = []
89 for tag in tags:
90 version = parse_tag(tag)
91 if version and version.is_supported():
92 result.append(version)
93 highest_micro = {}
94 for v in result:
95 highest_micro[v.minor] = max(v.micro, highest_micro.get(v.minor, -1))
96 for branch in branches:
97 minor = parse_branch(branch)
98 if minor is not None:
99 micro = highest_micro.get(minor, -1) + 1
100 version = Version(branch, minor, micro, False)
101 if version.is_supported():
102 result.append(version)
103 result.sort()
104 logger.info('Found ' + str(len(result)) + ' supported versions')
105 return result