mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-29 10:17:27 +02:00
[core] Correctly parse status in version names when it exists
Version objects were meant to be used only with numerical characters, separated by periods. Now that the version of Meshroom can also contain its status ("develop" when it is in develop mode), the Version class needs to be able to parse the status string as well as the version components when it exists. The status is handled as a separate string, which is returned in addition to the tuple of integers when the whole version string is parsed in the first place. This prevents issues when opening files that have been saved with a version like "x.x.x-develop".
This commit is contained in:
parent
13135a4db3
commit
0b4e38fe9d
1 changed files with 15 additions and 5 deletions
|
@ -147,16 +147,19 @@ class Version(object):
|
|||
"""
|
||||
if len(args) == 0:
|
||||
self.components = tuple()
|
||||
self.status = str()
|
||||
elif len(args) == 1:
|
||||
versionName = args[0]
|
||||
if isinstance(versionName, str):
|
||||
self.components = Version.toComponents(versionName)
|
||||
self.components, self.status = Version.toComponents(versionName)
|
||||
elif isinstance(versionName, (list, tuple)):
|
||||
self.components = tuple([int(v) for v in versionName])
|
||||
self.status = str()
|
||||
else:
|
||||
raise RuntimeError("Version: Unsupported input type.")
|
||||
else:
|
||||
self.components = tuple([int(v) for v in args])
|
||||
self.status = str()
|
||||
|
||||
def __repr__(self):
|
||||
return self.name
|
||||
|
@ -206,17 +209,24 @@ class Version(object):
|
|||
@staticmethod
|
||||
def toComponents(versionName):
|
||||
"""
|
||||
Split 'versionName' as a tuple of individual components.
|
||||
Split 'versionName' as a tuple of individual components, including its status if
|
||||
there is any.
|
||||
|
||||
Args:
|
||||
versionName (str): version name
|
||||
|
||||
Returns:
|
||||
tuple of str: split version numbers
|
||||
tuple of int, string: split version numbers, status if any (or empty string)
|
||||
"""
|
||||
if not versionName:
|
||||
return ()
|
||||
return tuple([int(v) for v in versionName.split(".")])
|
||||
return (), str()
|
||||
|
||||
status = str()
|
||||
# If there is a status, it is placed after a "-"
|
||||
splitComponents = versionName.split("-", maxsplit=1)
|
||||
if (len(splitComponents) > 1): # If there is no status, splitComponents is equal to [versionName]
|
||||
status = splitComponents[-1]
|
||||
return tuple([int(v) for v in splitComponents[0].split(".")]), status
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue