From: Frank Brehm Date: Fri, 22 Jan 2021 13:52:14 +0000 (+0100) Subject: Transforming bin/format-du to the new schema X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=ce83d3ed2bee97e78804bb6b5e7baacae905944a;p=pixelpark%2Fadmin-tools.git Transforming bin/format-du to the new schema --- diff --git a/bin/format-du b/bin/format-du index 9c25f9f..206ff31 100755 --- a/bin/format-du +++ b/bin/format-du @@ -1,30 +1,58 @@ #!/usr/bin/env python3 +from __future__ import print_function + # Standard modules import sys + +__exp_py_version_major__ = 3 +__min_py_version_minor__ = 4 + +if sys.version_info[0] != __exp_py_version_major__: + print("This script is intended to use with Python {}.".format( + __exp_py_version_major__), file=sys.stderr) + print("You are using Python: {0}.{1}.{2}-{3}-{4}.".format( + *sys.version_info) + "\n", file=sys.stderr) + sys.exit(1) + +if sys.version_info[1] < __min_py_version_minor__: + print("A minimal Python version of {maj}.{min} is necessary to execute this script.".format( + maj=__exp_py_version_major__, min=__min_py_version_minor__), file=sys.stderr) + print("You are using Python: {0}.{1}.{2}-{3}-{4}.".format( + *sys.version_info) + "\n", file=sys.stderr) + sys.exit(1) + +# Standard modules import os -import logging import locale # own modules: cur_dir = os.getcwd() base_dir = cur_dir -if sys.argv[0] != '' and sys.argv[0] != '-c': - bin_dir = os.path.dirname(os.path.realpath(sys.argv[0])) -else: - bin_dir = os.path.dirname(os.path.realpath(__file__)) -base_dir = os.path.abspath(os.path.join(bin_dir, '..')) -module_dir = os.path.join(base_dir, 'pp_lib') -if os.path.exists(module_dir): - sys.path.insert(0, base_dir) +try: + import pathlib + from pathlib import Path +except ImportError: + from pathlib2 import Path + import pathlib2 as pathlib -from pp_lib.format_du import FormatDuApp +# own modules: + +my_path = Path(__file__) +my_real_path = my_path.resolve() +bin_path = my_real_path.parent +base_dir = bin_path.parent +lib_dir = base_dir.joinpath('lib') +module_dir = lib_dir.joinpath('pp_lib') -log = logging.getLogger(__name__) +if module_dir.exists(): + sys.path.insert(0, str(lib_dir)) + +from pp_lib.format_du import FormatDuApp __author__ = 'Frank Brehm ' -__copyright__ = '(C) 2018 by Frank Brehm, Pixelpark GmbH, Berlin' +__copyright__ = '(C) 2021 by Frank Brehm, Pixelpark GmbH, Berlin' appname = os.path.basename(sys.argv[0]) diff --git a/lib/pp_lib/du.py b/lib/pp_lib/du.py index 8f731b1..e9026c0 100644 --- a/lib/pp_lib/du.py +++ b/lib/pp_lib/du.py @@ -3,7 +3,7 @@ """ @author: Frank Brehm @contact: frank.brehm@pixelpark.com -@copyright: © 2018 by Frank Brehm, Publicies Pixelpark GmbH, Berlin +@copyright: © 2021 by Frank Brehm, Publicies Pixelpark GmbH, Berlin """ from __future__ import absolute_import @@ -16,12 +16,10 @@ import re import six # Own modules -from .common import pp, to_str +from fb_tools.common import pp, to_str +from fb_tools.obj import FbBaseObjectError, FbBaseObject -from .obj import PpBaseObjectError, PpBaseObject - - -__version__ = '0.4.2' +__version__ = '0.4.3' LOG = logging.getLogger(__name__) @@ -35,7 +33,7 @@ DU_UNIT_EXP = { # ============================================================================= -class DuError(PpBaseObjectError): +class DuError(FbBaseObjectError): pass @@ -59,7 +57,7 @@ class DuListError(DuError): # ============================================================================= -class DuEntry(PpBaseObject): +class DuEntry(FbBaseObject): """ Class encapsulating one DU entry. """ diff --git a/lib/pp_lib/format_du.py b/lib/pp_lib/format_du.py index 596f400..bcb1083 100644 --- a/lib/pp_lib/format_du.py +++ b/lib/pp_lib/format_du.py @@ -3,7 +3,7 @@ """ @author: Frank Brehm @contact: frank.brehm@pixelpark.com -@copyright: © 2018 by Frank Brehm, Berlin +@copyright: © 2021 by Frank Brehm, Berlin @summary: The module for the application object. """ from __future__ import absolute_import @@ -18,9 +18,8 @@ import copy import six # Own modules -from .common import pp - -from .app import PpApplication +from fb_tools.common import pp +from fb_tools.app import BaseApplication from .du import DuParseError, DuEntry from .du import DU_UNITS, DU_UNIT_EXP @@ -30,12 +29,12 @@ try: except ImportError: from .global_version import __version__ as my_version -__version__ = '0.4.4' +__version__ = '0.4.5' LOG = logging.getLogger(__name__) # ============================================================================= -class FormatDuApp(PpApplication): +class FormatDuApp(BaseApplication): """ Application class for the format-du command """