From: Frank Brehm Date: Thu, 25 Jul 2024 15:46:41 +0000 (+0200) Subject: Integrating spinners X-Git-Tag: 1.11.0^2~3 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=a5dfafa7e6b253ce42fd1c67a4a7fb56d2ef8a6c;p=pixelpark%2Fcreate-terraform.git Integrating spinners --- diff --git a/lib/create_terraform/handler/__init__.py b/lib/create_terraform/handler/__init__.py index dff853a..74c3501 100644 --- a/lib/create_terraform/handler/__init__.py +++ b/lib/create_terraform/handler/__init__.py @@ -12,6 +12,7 @@ from __future__ import absolute_import, print_function import copy import os import logging +import random import re import stat import sys @@ -30,6 +31,7 @@ from fb_tools.common import pp, to_bool, to_str from fb_tools.errors import HandlerError, ExpectedHandlerError from fb_tools.handling_obj import HandlingObject, CalledProcessError from fb_tools.handler import BaseHandler +from fb_tools.spinner import CycleList # Own modules from ..errors import ConsulApiNotFoundError @@ -50,7 +52,7 @@ from ..errors import AbortExecution from ..xlate import XLATOR -__version__ = '4.3.2' +__version__ = '4.4.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -606,6 +608,20 @@ class CreateTerraformHandler( print(_("and enter: {}").format(self.colored('terraform apply', 'GREEN'))) print() + # ------------------------------------------------------------------------- + def get_spinner_name(self): + """ + Return the name of a valid spinner. + + If the configured spinner is 'random', then a random name from the list + of all available spinners will be returned. + """ + if self.config and self.config.spinner != 'random': + return self.config.spinner + + randomizer = random.SystemRandom() + return randomizer.choice(list(CycleList.keys())) + # ------------------------------------------------------------------------- def exit(self, retval=-1, msg=None): """Exit the current application.""" diff --git a/lib/create_terraform/handler/vmware.py b/lib/create_terraform/handler/vmware.py index ed8fa7c..d2fe83d 100644 --- a/lib/create_terraform/handler/vmware.py +++ b/lib/create_terraform/handler/vmware.py @@ -19,10 +19,13 @@ from operator import attrgetter # Third party modules from fb_tools.common import pp -from fb_tools.errors import HandlerError, ExpectedHandlerError -from fb_vmware.errors import VSphereExpectedError +from fb_tools.errors import ExpectedHandlerError +from fb_tools.errors import HandlerError +from fb_tools.spinner import Spinner + from fb_vmware.config import VSPhereConfigInfo from fb_vmware.connect import VsphereConnection +from fb_vmware.errors import VSphereExpectedError # Own modules from ..errors import AbortExecution @@ -31,7 +34,7 @@ from ..slim_vm import SlimVm from ..xlate import XLATOR -__version__ = '1.1.0' +__version__ = '1.2.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -252,10 +255,17 @@ class CrTfHandlerVmwMixin(): self.incr_verbosity() nr_total = 0 + spinner_name = self.get_spinner_name() for vsphere_name in self.vsphere: - LOG.debug(_("Searching for datastores in VSPhere {!r} ...").format(vsphere_name)) - self.vsphere[vsphere_name].get_datastores() + msg = _('Searching for datastores in VSPhere {!r} ...').format(vsphere_name) + if self.verbose: + LOG.debug(msg) + self.vsphere[vsphere_name].get_datastores() + else: + with Spinner(msg + ' ', spinner_name): + self.vsphere[vsphere_name].get_datastores() + nr_total += len(self.vsphere[vsphere_name].datastores.keys()) if nr_total: @@ -272,14 +282,19 @@ class CrTfHandlerVmwMixin(): def exec_vmw_ds_clusters(self): nr_total = 0 + spinner_name = self.get_spinner_name() if self.stop_at_step == 'vmw-ds-clusters': self.incr_verbosity() for vsphere_name in self.vsphere: - LOG.debug(_("Searching for datastore clusters in VSPhere {!r} ...").format( - vsphere_name)) - self.vsphere[vsphere_name].get_ds_clusters() + msg = _("Searching for datastore clusters in VSPhere {!r} ...").format(vsphere_name) + if self.verbose: + LOG.debug(msg) + self.vsphere[vsphere_name].get_ds_clusters() + else: + with Spinner(msg + ' ', spinner_name): + self.vsphere[vsphere_name].get_ds_clusters() nr_total += len(self.vsphere[vsphere_name].ds_clusters.keys()) if nr_total: @@ -301,9 +316,17 @@ class CrTfHandlerVmwMixin(): if self.stop_at_step == 'vmw-networks': self.incr_verbosity() + spinner_name = self.get_spinner_name() + for vsphere_name in self.vsphere: - LOG.debug(_("Searching for networks in VSPhere {!r} ...").format(vsphere_name)) - self.vsphere[vsphere_name].get_networks() + msg = _("Searching for networks in VSPhere {!r} ...").format(vsphere_name) + if self.verbose: + LOG.debug(msg) + self.vsphere[vsphere_name].get_networks() + else: + with Spinner(msg + ' ', spinner_name): + self.vsphere[vsphere_name].get_networks() + if self.eval_errors: msg = ngettext( "Found one error in exploring vSphere {v!r} resources.", @@ -438,14 +461,26 @@ class CrTfHandlerVmwMixin(): total_vms = 0 slim_vms = [] slim_verbose = 3 + re_vm = re.compile(r'.*') + + spinner_name = self.get_spinner_name() + + def _do_get_vms(vsphere_name): + return self.vsphere[vsphere_name].get_vms(re_vm, as_obj=True, stop_at_found=False) for vsphere_name in self.vsphere: if vsphere_name not in self.vsphere_vm_cache: self.vsphere_vm_cache[vsphere_name] = [] - re_vm = re.compile(r'.*') - vm_list = self.vsphere[vsphere_name].get_vms(re_vm, as_obj=True, stop_at_found=False) + msg = _('Getting all VSPhere VMs and templates from {!r} ...').format(vsphere_name) + + if self.verbose: + LOG.debug(msg) + vm_list = _do_get_vms(vsphere_name) + else: + with Spinner(msg + ' ', spinner_name): + vm_list = _do_get_vms(vsphere_name) for vm in vm_list: self.vsphere_vm_cache[vsphere_name].append(vm) diff --git a/locale/de_DE/LC_MESSAGES/create_terraform.po b/locale/de_DE/LC_MESSAGES/create_terraform.po index d70cf31..1c8367c 100644 --- a/locale/de_DE/LC_MESSAGES/create_terraform.po +++ b/locale/de_DE/LC_MESSAGES/create_terraform.po @@ -1331,7 +1331,7 @@ msgstr[1] "Insgesamt {n} Fehler bei der Validierung der VM-Netzwerkschnittstelle #: lib/create_terraform/handler/vmware.py:443 msgid "Exploring and caching all vSphere VMs and templates ..." -msgstr "Ermittle und cache alle vSpheres VMs und -Vorlagen …" +msgstr "Ermittle und cache alle vSphere VMs und -Vorlagen …" #: lib/create_terraform/handler/vmware.py:464 msgid "Found one VM or template in vSphere."