]> Frank Brehm's Git Trees - pixelpark/puppet-tools.git/commitdiff
Unifying output
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 14 Feb 2023 14:27:35 +0000 (15:27 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 14 Feb 2023 14:27:35 +0000 (15:27 +0100)
lib/dpx_puppettools/__init__.py
lib/dpx_puppettools/app/__init__.py
lib/dpx_puppettools/app/get_forge_module.py
lib/dpx_puppettools/forge/__init__.py
lib/dpx_puppettools/forge/base_module_info.py
lib/dpx_puppettools/forge/cur_mod_release_info.py
lib/dpx_puppettools/forge/mod_info.py
lib/dpx_puppettools/forge/mod_release_info.py
lib/dpx_puppettools/forge/owner_info.py

index 0df5255f65e1bc5aac22260e5634e51bca102c6d..d0a1815f551b33fcd6e7905ff64bc92ac17e47fa 100644 (file)
@@ -10,7 +10,7 @@ from pathlib import Path
 # Own modules
 import fb_tools.common
 
-__version__ = '0.2.1'
+__version__ = '0.2.2'
 
 MAX_PORT_NUMBER = (2 ** 16) - 1
 DEFAULT_CONFIG_DIR = 'pixelpark'
@@ -46,6 +46,28 @@ def pp(value, indent=4, width=None, depth=None):
     return fb_tools.common.pp(value, indent=indent, width=width, depth=depth)
 
 
+# =============================================================================
+def print_out(msg, end='\n', file=None, flush=False):
+
+    print(msg, end=end, file=file, flush=flush)
+
+
+# =============================================================================
+def line(width=None, linechar='-', end='\n', file=None, flush=False):
+
+    lchar = str(linechar).strip()
+    if not lchar:
+        lchar = '-'
+
+    if not width:
+        term_size = shutil.get_terminal_size(
+            (DEFAULT_TERMINAL_WIDTH, DEFAULT_TERMINAL_HEIGHT))
+        width = term_size.columns
+
+    lin = (lchar * width)[0:width]
+    print(lin, end=end, file=file, flush=flush)
+
+
 # =============================================================================
 
 # vim: ts=4 et list
index 188c649d31d790e110209a0bba383bbffdf8b3dc..75c743d6c6c8ac80b7dc1a08031a3380f422a1ce 100644 (file)
@@ -9,7 +9,6 @@ from __future__ import absolute_import
 
 # Standard modules
 import logging
-import shutil
 import copy
 import pipes
 import os
@@ -45,7 +44,7 @@ LOG = logging.getLogger(__name__)
 _ = XLATOR.gettext
 ngettext = XLATOR.ngettext
 
-__version__ = '0.3.1'
+__version__ = '0.3.2'
 
 
 # =============================================================================
@@ -90,31 +89,6 @@ class BaseDPXPuppetApplication(FbConfigApplication):
             env_prefix=env_prefix, config_dir=config_dir
         )
 
-    # -------------------------------------------------------------------------
-    def line(self, width=None, linechar='-', color=None, end='\n', file=None, flush=False):
-        """Print out an line on stdout, if not in quiet mode."""
-        if self.quiet:
-            return
-
-        lchar = str(linechar).strip()
-        if not lchar:
-            lchar = '-'
-
-        if not width:
-            term_size = shutil.get_terminal_size((DEFAULT_TERMINAL_WIDTH, DEFAULT_TERMINAL_HEIGHT))
-            width = term_size.columns
-
-        lin = (lchar * width)[0:width]
-        if color:
-            lin = self.colored(lin, color)
-        print(lin, end=end, file=file, flush=flush)
-
-    # -------------------------------------------------------------------------
-    def empty_line(self, file=None, flush=False):
-        """Print out an empty line on stdout, if not in quiet mode."""
-        if not self.quiet:
-            print('', file=file, flush=flush)
-
     # -------------------------------------------------------------------------
     def post_init(self):
         """
@@ -378,6 +352,36 @@ class BaseDPXPuppetApplication(FbConfigApplication):
         p = Popen(cmd, stdin=PIPE, universal_newlines=True)
         p.communicate(mail.as_string())
 
+    # -------------------------------------------------------------------------
+    def print(self, msg, color=None, end='\n', file=None, flush=False):
+
+        if color:
+            msg = self.colored(msg, color)
+        print_out(msg, end=end, file=file, flush=flush)
+
+    # -------------------------------------------------------------------------
+    def empty_line(self, end='\n', file=None, flush=False):
+
+        print('', end=end, file=file, flush=flush)
+
+    # -------------------------------------------------------------------------
+    def line(self, width=None, linechar='-', color=None, end='\n', file=None, flush=False):
+
+        lchar = str(linechar).strip()
+        if not lchar:
+            lchar = '-'
+
+        if not width:
+            term_size = shutil.get_terminal_size(
+                (DEFAULT_TERMINAL_WIDTH, DEFAULT_TERMINAL_HEIGHT))
+            width = term_size.columns
+
+        lin = (lchar * width)[0:width]
+        if color:
+            lin = self.colored(lin, color)
+        print(lin, end=end, file=file, flush=flush)
+
+
 # =============================================================================
 
 if __name__ == "__main__":
index 5205b35a5093000fe97440da26b4708ccd70d75b..9d6eb0abc7d96dc7231655510d19bb2dcd4a0c79 100644 (file)
@@ -32,7 +32,7 @@ LOG = logging.getLogger(__name__)
 _ = XLATOR.gettext
 ngettext = XLATOR.ngettext
 
-__version__ = '0.6.1'
+__version__ = '0.6.2'
 
 
 # =============================================================================
@@ -160,10 +160,16 @@ class GetForgeModuleApplication(BaseDPXPuppetApplication):
 
         self.module_name = self.args.module_name[0]
 
+        LOG.debug(_("Creating a {} object ...").format('ForgeModuleInfo'))
+
         self.module_info = ForgeModuleInfo(
             appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
             full_name=self.module_name, var_dir=var_dir, initialized=True,)
 
+        LOG.debug(_("Finished creating a {} object.").format('ForgeModuleInfo'))
+
+        self.initialized = True
+
     # -------------------------------------------------------------------------
     def _run(self):
 
index 1ea1084b3fe6d9a4352ad48d9e8089c3464b0af5..0dc2b591f0e6b857a61becae28ff2468b8631c88 100644 (file)
@@ -23,7 +23,7 @@ from ..xlate import XLATOR
 
 from ..errors import BaseModuleInfoError
 
-__version__ = '0.3.0'
+__version__ = '0.4.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -180,7 +180,7 @@ class BaseForgeObject(FbBaseObject):
     @classmethod
     def from_data(cls, data, appname=None, verbose=0, base_dir=None):
 
-        if verbose > 3:
+        if verbose > 2:
             LOG.debug(_("Trying to get data for {} from:").format(
                 cls.__name__) + '\n' + pp(data))
 
@@ -198,6 +198,9 @@ class BaseForgeObject(FbBaseObject):
     # -------------------------------------------------------------------------
     def apply_data(self, data):
 
+        if self.verbose > 2:
+            LOG.debug(_("Applying data ..."))
+
         if 'slug' in data:
             self.slug = data['slug']
         if 'uri' in data:
index e12622a827d22135bc1efb60a815f6376ade9c28..15f19d7cf2d1a9755cda060d86b4103c9aa98028 100644 (file)
@@ -22,7 +22,7 @@ from . import BaseForgeObject
 
 from .owner_info import ForgeOwnerInfo
 
-__version__ = '0.2.0'
+__version__ = '0.2.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -158,6 +158,9 @@ class BaseForgeModuleInfo(BaseForgeObject):
     # -------------------------------------------------------------------------
     def apply_data(self, data):
 
+        if self.verbose > 2:
+            LOG.debug(_("Applying data ..."))
+
         super(BaseForgeModuleInfo, self).apply_data(data)
 
         if 'deprecated_at' in data:
index d24f757d27428883b018f1990f84d6be54f4ef9d..a05d7565b84c8964c1ba659bb6684deebfb75f4d 100644 (file)
@@ -12,12 +12,15 @@ from __future__ import absolute_import
 import logging
 import copy
 import datetime
+import textwrap
 
 # Thisrd party modules
 from fb_tools.common import to_bool
 
 # Own modules
 from .. import pp
+from .. import DEFAULT_TERMINAL_WIDTH, DEFAULT_TERMINAL_HEIGHT
+
 from ..xlate import XLATOR
 
 from . import parse_forge_date
@@ -28,7 +31,7 @@ from .mod_release_info import ModuleReleaseInfo
 
 from .base_module_info import BaseForgeModuleInfo
 
-__version__ = '0.2.0'
+__version__ = '0.2.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -388,6 +391,9 @@ class CurrentModuleReleaseInfo(ModuleReleaseInfo):
     # -------------------------------------------------------------------------
     def apply_data(self, data):
 
+        if self.verbose > 2:
+            LOG.debug(_("Applying data ..."))
+
         super(CurrentModuleReleaseInfo, self).apply_data(data)
 
         if 'changelog' in data and data['changelog']:
@@ -439,6 +445,8 @@ class CurrentModuleReleaseInfo(ModuleReleaseInfo):
             for task in data['tasks']:
                 self.tasks.append(copy.copy(task))
 
+    # -------------------------------------------------------------------------
+
 
 # =============================================================================
 if __name__ == "__main__":
index 14fc079885304e65b2a07e121c84185f773033ab..7cab1762f704a97822e8a70cd45fa3a076977789 100644 (file)
@@ -17,7 +17,7 @@ import datetime
 import collections
 import time
 import os
-import shutil
+import inspect
 
 from pathlib import Path
 
@@ -37,9 +37,9 @@ from requests.exceptions import ConnectionError, ReadTimeout, ConnectTimeout
 from fb_tools.common import to_bool
 
 # Own modules
-from .. import pp, DEFAULT_FORGE_API_URL, DEFAULT_HTTP_TIMEOUT, MAX_HTTP_TIMEOUT
+from .. import pp, print_out, line
+from .. import DEFAULT_FORGE_API_URL, DEFAULT_HTTP_TIMEOUT, MAX_HTTP_TIMEOUT
 from .. import DEFAULT_VAR_DIR
-from .. import DEFAULT_TERMINAL_WIDTH, DEFAULT_TERMINAL_HEIGHT
 
 from ..errors import BaseHookError, BaseModuleInfoError
 
@@ -47,15 +47,14 @@ from ..xlate import XLATOR
 
 from ..base_moduleinfo import BaseModuleInfo
 
-from . import parse_forge_date, ForgeModuleInfoError
+from . import parse_forge_date, ForgeModuleInfoError, BaseForgeObject
 
 from .mod_release_info import ModuleReleaseInfo
 from .mod_release_list import ModuleReleaseList
 from .cur_mod_release_info import CurrentModuleReleaseInfo
 from .owner_info import ForgeOwnerInfo
 
-
-__version__ = '0.6.0'
+__version__ = '0.6.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -668,6 +667,9 @@ class ForgeModuleInfo(BaseModuleInfo):
     # -------------------------------------------------------------------------
     def apply_data(self, data, from_cache=True):
 
+        if self.verbose > 2:
+            LOG.debug(_("Applying data ..."))
+
         fd = data
 
         if from_cache:
@@ -762,7 +764,7 @@ class ForgeModuleInfo(BaseModuleInfo):
     @classmethod
     def from_data(cls, data, appname=None, verbose=0, base_dir=None):
 
-        if verbose > 3:
+        if verbose > 2:
             LOG.debug(_(
                 "Trying to instantiate a {}-object from:").format(
                 cls.__name__) + '\n' + pp(data))
@@ -780,7 +782,7 @@ class ForgeModuleInfo(BaseModuleInfo):
             LOG.error(msg)
             return None
 
-        module_info = cls(appname=appname, verbose=verbose, base_dir=base_dir, full_name=full_name)
+        module_info = ForgeModuleInfo(appname=appname, verbose=verbose, base_dir=base_dir, full_name=full_name)
         module_info.apply_data(data)
 
         return module_info
@@ -868,7 +870,7 @@ class ForgeModuleInfo(BaseModuleInfo):
         cls, full_name, forge_uri=DEFAULT_FORGE_API_URL, http_timeout=DEFAULT_HTTP_TIMEOUT,
             appname=None, verbose=0, base_dir=None):
 
-        module_info = cls(
+        module_info = ForgeModuleInfo(
             appname=appname, verbose=verbose, base_dir=base_dir, full_name=full_name,
         )
 
@@ -878,33 +880,28 @@ class ForgeModuleInfo(BaseModuleInfo):
 
 
     # -------------------------------------------------------------------------
-    def show(self, file=None, flush=False):
-
-        def my_print(message):
-            print(message, file=file, flush=flush)
-
-        def my_line(width=None, linechar='-', end='\n'):
-            lchar = str(linechar).strip()
-            if not lchar:
-                lchar = '-'
-
-            if not width:
-                term_size = shutil.get_terminal_size(
-                    (DEFAULT_TERMINAL_WIDTH, DEFAULT_TERMINAL_HEIGHT))
-                width = term_size.columns
+    def show(self, detail=False, file=None, flush=False):
 
-            lin = (lchar * width)[0:width]
-            print(lin, end=end, file=file, flush=flush)
+        if self.verbose > 2:
+            msg = "Base classes of {}:".format(BaseForgeObject)
+            msg += '\n' + pp(inspect.getmro(BaseForgeObject))
+            LOG.debug(msg)
+            msg = "Base classes of {}:".format(BaseModuleInfo)
+            msg += '\n' + pp(inspect.getmro(BaseModuleInfo))
+            LOG.debug(msg)
+            msg = "Base classes of {}:".format(self.__class__.__name__)
+            msg += '\n' + pp(inspect.getmro(self.__class__))
+            LOG.debug(msg)
 
         if not self.exists_on_forge:
             msg = _("Module {!r} not found on Puppet forge.").format(self.full_name)
-            my_print(msg)
+            print_out(msg, file=file, flush=flush)
             return
 
         msg = _("Information about {!r} from Puppet forge:").format(self.full_name)
-        my_print(msg)
-        my_line(width=len(msg))
-        my_print('')
+        print_out(msg, file=file, flush=flush)
+        line(width=len(msg), file=file, flush=flush)
+        print_out('', file=file, flush=flush)
 
         labels = {}
         max_len_label = 1
@@ -935,8 +932,9 @@ class ForgeModuleInfo(BaseModuleInfo):
             if val is None:
                 val = '~'
             msg = "{lbl:<{max}} {val}".format(lbl=lbl, max=max_len_label, val=val)
-            my_print(msg)
-        my_print('')
+            print_out(msg, file=file, flush=flush)
+        print_out('', file=file, flush=flush)
+
 
 # =============================================================================
 if __name__ == "__main__":
index f05c980d2a950644114c0b06749c3cd969a635ef..64a3315d40d6d7bdda9bf97704e619bc57d1fdab 100644 (file)
@@ -21,7 +21,7 @@ from ..xlate import XLATOR
 from . import parse_forge_date
 from . import BaseForgeObject
 
-__version__ = '0.2.0'
+__version__ = '0.2.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -245,6 +245,9 @@ class ModuleReleaseInfo(BaseForgeObject):
     # -------------------------------------------------------------------------
     def apply_data(self, data):
 
+        if self.verbose > 2:
+            LOG.debug(_("Applying data ..."))
+
         super(ModuleReleaseInfo, self).apply_data(data)
 
         if 'created_at' in data and data['created_at']:
index ea13039885ff08e1f5d96bde209ddc67eb917b15..8398e2cf15936a1d0ba045a5f5f0da1c343e8f40 100644 (file)
@@ -17,7 +17,7 @@ from ..xlate import XLATOR
 
 from . import BaseForgeObject
 
-__version__ = '0.3.0'
+__version__ = '0.3.1'
 
 LOG = logging.getLogger(__name__)
 
@@ -141,6 +141,9 @@ class ForgeOwnerInfo(BaseForgeObject):
     # -------------------------------------------------------------------------
     def apply_data(self, data):
 
+        if self.verbose > 2:
+            LOG.debug(_("Applying data ..."))
+
         super(ForgeOwnerInfo, self).apply_data(data)
 
         if 'gravatar_id' in data: