Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python-bareos: integrate usage of config files #1678

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Disable automated package-tests for SLES 12 [PR #1671]
- Make BareosDirPluginPrometheusExporter.py work with python3 [PR #1647]
- Improve FreeBSD dependencies [PR #1670]
- python-bareos: integrate usage of config files [PR #1678]

### Removed
- plugins: remove old deprecated postgres plugin [PR #1606]
Expand Down Expand Up @@ -72,5 +73,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[PR #1670]: https://github.com/bareos/bareos/pull/1670
[PR #1671]: https://github.com/bareos/bareos/pull/1671
[PR #1672]: https://github.com/bareos/bareos/pull/1672
[PR #1678]: https://github.com/bareos/bareos/pull/1678
[PR #1684]: https://github.com/bareos/bareos/pull/1684
[unreleased]: https://github.com/bareos/bareos/tree/master
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
Requires Bareos >= 19.2.4.
"""

from __future__ import print_function
import argparse
from bareos.util import argparse
import bareos.bsock
import bareos.exceptions
import logging
Expand Down
3 changes: 1 addition & 2 deletions contrib/misc/triggerjob/bareos-triggerjob.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function
import argparse
from bareos.util import argparse
import bareos.bsock
import logging
import sys
Expand Down
1 change: 0 additions & 1 deletion docs/pkglists/Debian_11.x86_64
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
all/bareos-webui
all/python-bareos
all/python3-bareos
amd64/bareos
amd64/bareos-bconsole
Expand Down
1 change: 0 additions & 1 deletion docs/pkglists/Debian_12.x86_64
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
all/bareos-webui
all/python-bareos
all/python3-bareos
amd64/bareos
amd64/bareos-bconsole
Expand Down
1 change: 0 additions & 1 deletion docs/pkglists/xUbuntu_20.04.x86_64
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
all/bareos-webui
all/python-bareos
all/python3-bareos
amd64/bareos
amd64/bareos-bconsole
Expand Down
1 change: 0 additions & 1 deletion docs/pkglists/xUbuntu_22.04.x86_64
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
all/bareos-webui
all/python-bareos
all/python3-bareos
amd64/bareos
amd64/bareos-bconsole
Expand Down
5 changes: 3 additions & 2 deletions python-bareos/bareos/bsock/directorconsole.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2016-2023 Bareos GmbH & Co. KG
# Copyright (C) 2016-2024 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 @@ -61,8 +61,9 @@ def argparser_add_default_command_line_arguments(argparser):
>>> director = DirectorConsole(**bareos_args)

Args:
argparser (ArgParser): ArgParser instance.
argparser (ArgParser or ConfigArgParser): (Config)ArgParser instance.
"""

argparser.add_argument(
"--name",
default="*UserAgent*",
Expand Down
4 changes: 2 additions & 2 deletions python-bareos/bareos/bsock/lowlevel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2015-2023 Bareos GmbH & Co. KG
# Copyright (C) 2015-2024 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 @@ -71,7 +71,7 @@ class LowLevel(object):
def argparser_get_bareos_parameter(args):
"""Extract arguments.

This method is usally used together with the method :py:func:`argparser_add_default_command_line_arguments`.
This method is usually used together with the method :py:func:`argparser_add_default_command_line_arguments`.

Args:
args (ArgParser.Namespace): Arguments retrieved by :py:func:`ArgumentParser.parse_args`.
Expand Down
5 changes: 3 additions & 2 deletions python-bareos/bareos/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2015-2023 Bareos GmbH & Co. KG
# Copyright (C) 2015-2024 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 @@ -21,9 +21,10 @@
Bareos utility classes.
"""

from bareos.util.argparse import ArgumentParser
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", "Version"]
__all__ = ["ArgumentParser", "BareosBase64", "Password", "Path", "Version"]
44 changes: 44 additions & 0 deletions python-bareos/bareos/util/argparse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2024-2024 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.

"""
ArgumentParser wrapper.

Uses configargparse, if available,
otherwise, falls back to argparse.
"""

HAVE_CONFIG_ARG_PARSE_MODULE = False
try:
import configargparse as argparse

HAVE_CONFIG_ARG_PARSE_MODULE = True
except ImportError:
import argparse


class ArgumentParser(argparse.ArgumentParser):
"""ArgumentParser wrapper"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if HAVE_CONFIG_ARG_PARSE_MODULE:
self.add_argument(
"-c", "--config", is_config_file=True, help="Config file path."
)
11 changes: 4 additions & 7 deletions python-bareos/bareos/util/path.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2015-2021 Bareos GmbH & Co. KG
# Copyright (C) 2015-2024 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 @@ -21,8 +21,6 @@
Handle file paths.
"""

from copy import copy


class Path(object):
"""
Expand Down Expand Up @@ -55,7 +53,7 @@ def __set_defaults(self):
self.path = None

def set_path(self, path):
if path == None:
if path is None:
self.__set_defaults()
elif isinstance(path, str):
self.path_orig = path
Expand All @@ -76,10 +74,9 @@ def set_path(self, path):
pass

def get(self, index=None):
if index == None:
if index is None:
return self.path
else:
return self.path[index]
return self.path[index]

def shift(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions python-bareos/bin/bareos-fd-connect.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python
#
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2020 Bareos GmbH & Co. KG
# Copyright (C) 2019-2024 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 @@ -18,8 +19,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


import argparse
from bareos.util import argparse
import bareos.bsock
from bareos.bsock.filedaemon import FileDaemon
import logging
Expand Down Expand Up @@ -53,7 +53,7 @@ def getArguments():
logger.debug("options: %s" % (bareos_args))
try:
bsock = FileDaemon(**bareos_args)
except (bareos.exceptions.Error) as e:
except bareos.exceptions.Error as e:
print(str(e))
sys.exit(1)
logger.debug("authentication successful")
Expand Down
8 changes: 4 additions & 4 deletions python-bareos/bin/bareos-jsonrpc-server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python
#
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2020 Bareos GmbH & Co. KG
# Copyright (C) 2019-2024 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 @@ -19,8 +20,7 @@
# 02110-1301, USA.


from __future__ import print_function
import argparse
from bareos.util import argparse
import bareos.bsock
import bareos.exceptions
import inspect
Expand Down Expand Up @@ -116,7 +116,7 @@ def getArguments():
logger.debug("options: %s" % (bareos_args))
try:
director = bareos.bsock.DirectorConsoleJson(**bareos_args)
except (bareos.exceptions.ConnectionError) as e:
except bareos.exceptions.ConnectionError as e:
print(str(e))
sys.exit(1)
logger.debug("authentication successful")
Expand Down
8 changes: 4 additions & 4 deletions python-bareos/bin/bconsole-json.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python
#
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2020 Bareos GmbH & Co. KG
# Copyright (C) 2019-2024 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 @@ -19,8 +20,7 @@
# 02110-1301, USA.


from __future__ import print_function
import argparse
from bareos.util import argparse
import bareos.bsock
import bareos.exceptions
import logging
Expand Down Expand Up @@ -53,7 +53,7 @@ def getArguments():
logger.debug("options: %s" % (bareos_args))
try:
director = bareos.bsock.DirectorConsoleJson(**bareos_args)
except (bareos.exceptions.Error) as e:
except bareos.exceptions.Error as e:
print(str(e))
sys.exit(1)

Expand Down
11 changes: 6 additions & 5 deletions python-bareos/bin/bconsole.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python
#
# BAREOS - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2020 Bareos GmbH & Co. KG
# Copyright (C) 2019-2024 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 @@ -18,9 +19,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


from __future__ import print_function
import argparse
from bareos.util import argparse
import bareos.bsock
import bareos.exceptions
import logging
Expand All @@ -34,6 +33,8 @@ def getArguments():
)
bareos.bsock.DirectorConsole.argparser_add_default_command_line_arguments(argparser)
args = argparser.parse_args()
if args.debug:
print(argparser.format_values())
return args


Expand All @@ -51,7 +52,7 @@ def getArguments():
logger.debug("options: %s" % (bareos_args))
try:
director = bareos.bsock.DirectorConsole(**bareos_args)
except (bareos.exceptions.Error) as e:
except bareos.exceptions.Error as e:
print(str(e))
sys.exit(1)

Expand Down
14 changes: 2 additions & 12 deletions python-bareos/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@ Source: python-bareos
Maintainer: Bareos Team <packager@bareos.com>
Section: python
Priority: optional
Build-Depends: debhelper (>= 7.4.3),
python-all (>= 2.6.6-3) <bullseye> <buster> <stretch> <xenial> <bionic>,
python-setuptools (>= 0.6b3) <bullseye> <buster> <stretch> <xenial> <bionic>,
python3-all, python3-setuptools
Build-Depends: debhelper (>= 7.4.3), python3-all, python3-setuptools
Standards-Version: 3.9.1

Package: python-bareos
Architecture: all
Depends: ${misc:Depends}, ${python:Depends}
Description: Backup Archiving REcovery Open Sourced - python module (Python 2)
This packages contains a python module to interact with a Bareos backup system.
It also includes some tools based on this module.

Package: python3-bareos
Architecture: all
Depends: ${misc:Depends}, ${python3:Depends}
Depends: ${misc:Depends}, ${python3:Depends}, python3-configargparse
Description: Backup Archiving REcovery Open Sourced - python module (Python 3)
This packages contains a python module to interact with a Bareos backup system.
It also includes some tools based on this module.
2 changes: 1 addition & 1 deletion python-bareos/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
export PYBUILD_NAME = bareos

%:
dh $@ --with python2,python3 --buildsystem=pybuild
dh $@ --with python3 --buildsystem=pybuild
16 changes: 4 additions & 12 deletions python-bareos/packaging/python-bareos.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@

# based on
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Python_Appendix/
# specifically on
# https://pagure.io/packaging-committee/blob/ae14fdb50cc6665a94bc32f7d984906ce1eece45/f/guidelines/modules/ROOT/pages/Python_Appendix.adoc
#

#
# For current distribution, create
# python2-bareos and python3-bareos packages.
#
# CentOS 6 supports only Python2.
#
# CentOS <= 7 and SLES <= 12,
# the Python2 package is namend python-bareos (instead of python2-bareos).
#

%global srcname bareos
Expand Down Expand Up @@ -48,6 +36,10 @@ It also includes some tools based on this module.}
Summary: %{summary}
BuildRequires: %{python3_build_requires}
%{?python_provide:%python_provide python3-%{srcname}}
%if 0%{?fedora} || 0%{?rhel} >= 8 || 0%{?suse_version} || 0%{?sle_version}
# Recommends is not supported on RHEL <= 7.
Recommends: python3-configargparse
%endif

%description -n python3-%{srcname} %_description

Expand Down