Skip to content

Commit

Permalink
python-bareos: adapt version numbers to PEP 440
Browse files Browse the repository at this point in the history
Bareos version numbers don't comply to PEP 440
and needs to be translated.
Version translation has been adapted to the
more strict requirements of the
Python packaging modul >=23.
  • Loading branch information
joergsteffens committed Sep 28, 2023
1 parent 50997a7 commit b376f3d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 18 deletions.
5 changes: 3 additions & 2 deletions python-bareos/bareos/util/__init__.py
@@ -1,6 +1,6 @@
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2015-2021 Bareos GmbH & Co. KG
# Copyright (C) 2015-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand All @@ -24,5 +24,6 @@
from bareos.util.bareosbase64 import BareosBase64
from bareos.util.password import Password
from bareos.util.path import Path
from bareos.util.version import Version

__all__ = ["BareosBase64", "Password", "Path"]
__all__ = ["BareosBase64", "Password", "Path", "Version"]
35 changes: 35 additions & 0 deletions python-bareos/bareos/util/version.py
@@ -0,0 +1,35 @@
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2023-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
# License as published by the Free Software Foundation and included
# in the file LICENSE.
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

import re


class Version(object):
def __init__(self, version):
self.version = version

def __str__(self):
return self.version

def as_python_version(self):
"""
Translate a Bareos version number
into a version compatible with PEP 440.
"""
return re.sub(r"~pre([0-9]+\.)", r".dev+\1", self.version)
4 changes: 2 additions & 2 deletions python-bareos/setup.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2020 Bareos GmbH & Co. KG
# Copyright (C) 2019-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -33,7 +33,7 @@ def get_version():
# and adapt it according to
# https://www.python.org/dev/peps/pep-0440/.
fullversion = version_file.read().strip()
__version__ = re.compile(r"~pre([0-9]+).*").sub(r".dev\1", fullversion)
__version__ = re.sub(r"~pre([0-9]+\.)", r".dev+\1", fullversion)
except IOError:
# Fallback version.
# First protocol implemented
Expand Down
27 changes: 15 additions & 12 deletions restapi/bareos_restapi/__init__.py
Expand Up @@ -4,7 +4,7 @@
#
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2020-2021 Bareos GmbH & Co. KG
# Copyright (C) 2020-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -37,6 +37,7 @@
import yaml

import bareos.bsock
import bareos.util
from bareos_restapi.models import *

# Read config from api.ini
Expand Down Expand Up @@ -199,23 +200,25 @@ def versionCheck(
else:
result = read_director_version(response=response, current_user=current_user)
if "version" in result:
myVersion = result["version"]
myVersion = bareos.util.Version(result["version"]).as_python_version()
current_user.directorVersion = myVersion
else:
raise HTTPException(
status_code=500,
detail="Could not read version from director. Need at least version %s"
% (minVersion),
)
# print (myVersion)
if not (version.parse(myVersion) >= version.parse(minVersion)):
raise HTTPException(
status_code=501,
detail="Not implemented in Bareos %s. Need at least version %s"
% (myVersion, minVersion),
)
else:
return True
try:
if not (version.parse(myVersion) >= version.parse(minVersion)):
raise HTTPException(
status_code=501,
detail="Not implemented in Bareos %s. Need at least version %s"
% (myVersion, minVersion),
)
else:
return True
except version.InvalidVersion as exception:
raise HTTPException(status_code=500, detail=str(exception))


def configure_add_standard_component(
Expand Down Expand Up @@ -321,7 +324,7 @@ def show_configuration_items(
versionCheck(
response=response,
current_user=current_user,
minVersion="20.0.0~pre996.de46d0b15",
minVersion="20.0.1",
)
# Sometimes config type identificator differs from key returned by director, we need to map
itemKey = itemType
Expand Down
4 changes: 2 additions & 2 deletions restapi/setup.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2020-2021 Bareos GmbH & Co. KG
# Copyright (C) 2020-2023 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -36,7 +36,7 @@ def get_version():
# and adapt it according to
# https://www.python.org/dev/peps/pep-0440/.
fullversion = version_file.read().strip()
__version__ = re.compile(r"~pre([0-9]+).*").sub(r".dev\1", fullversion)
__version__ = re.sub(r"~pre([0-9]+\.)", r".dev+\1", fullversion)
except IOError:
# Fallback version.
# First protocol implemented
Expand Down

0 comments on commit b376f3d

Please sign in to comment.