-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVersionInformation.py
130 lines (103 loc) · 3.79 KB
/
VersionInformation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""
UEBuild Tools - Version Information Updater for Unreal Engine
Copyright (C) 2024 IT-Hock
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from GitVersion import GitVersion
class VersionInformation(GitVersion):
"""
A class used to represent the version information of a project.
...
Attributes
----------
public_branches : list
a list of branch names that are considered public
Methods
-------
is_public():
Returns True if the current branch is public, False otherwise.
set_public_branches(branches):
Sets the list of public branches.
add_public_branch(branch):
Adds a new branch to the list of public branches.
get_version_short():
Returns a short version string in the format 'major.minor'.
get_visibility():
Returns 'PUBLIC' if the current branch is public, 'PRIVATE' otherwise.
get_version_string():
Returns a formatted version string with date, visibility, branch, version, and changelist information.
"""
public_branches = ["master", "main", "releases"]
def is_public(self):
"""
Returns True if the current branch is public, False otherwise.
Returns
-------
bool
True if the current branch is public, False otherwise.
"""
return self.branch.lower() in self.public_branches
def set_public_branches(self, branches):
"""
Sets the list of public branches.
Parameters
----------
branches : list
The new list of public branches.
"""
self.public_branches = branches
def add_public_branch(self, branch):
"""
Adds a new branch to the list of public branches.
Parameters
----------
branch : str
The name of the new public branch.
"""
self.public_branches.append(branch)
def get_version_short(self):
"""
Returns a short version string in the format 'major.minor'.
Returns
-------
str
The short version string.
"""
return f"{self.version[0]}.{self.version[1]}"
def get_version_long(self):
"""
Returns a version string in the format 'major.minor.patch-build'.
Returns
-------
str
The version string.
"""
return f"{self.version[0]}.{self.version[1]}.{self.version[2]}-{self.version[3]}"
def get_visibility(self):
"""
Returns 'PUBLIC' if the current branch is public, 'PRIVATE' otherwise.
Returns
-------
str
The visibility of the current branch.
"""
return "PUBLIC" if self.is_public() else "PRIVATE"
def get_version_string(self):
"""
Returns a formatted version string with date, visibility, branch, version, and changelist information.
Returns
-------
str
The formatted version string.
"""
return (f"({self.commit_date.strftime('%d %b %Y')}/{self.commit_date.strftime('%H:%M:%S')}) "
f"[{self.get_visibility()}] <{self.branch}/{self.get_version_short()}> ChangeList: {self.short_sha}")