From: Frank Brehm Date: Fri, 13 Oct 2023 12:24:29 +0000 (+0200) Subject: put two functions into a separate module X-Git-Tag: 1.8.0^2~49 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=4a945bc965b00d0e1bcc703d25ffc51da2e79ff2;p=pixelpark%2Fcreate-terraform.git put two functions into a separate module --- diff --git a/lib/cr_tf/handler/__init__.py b/lib/cr_tf/handler/__init__.py index e19012e..af134c2 100644 --- a/lib/cr_tf/handler/__init__.py +++ b/lib/cr_tf/handler/__init__.py @@ -3,7 +3,7 @@ """ @author: Frank Brehm @contact: frank.brehm@pixelpark.com -@copyright: © 2021 by Frank Brehm, Berlin +@copyright: © 2023 by Frank Brehm, Berlin @summary: A handler module for underlaying actions """ from __future__ import absolute_import, print_function @@ -28,13 +28,6 @@ from distutils.version import LooseVersion from operator import attrgetter -HAS_GETCH = False -try: - import getch - HAS_GETCH = True -except ImportError: - pass - # Third party modules import pytz import yaml @@ -64,56 +57,17 @@ from ..terraform.vm import TerraformVm from ..terraform.disk import TerraformDisk +# from ..tools import password_input + from ..xlate import XLATOR -__version__ = '3.9.0' +__version__ = '3.9.1' LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -# ============================================================================= -def password_input_getch(prompt='', fill_char='*', max_len=64): - p_s = '' - proxy_string = ' ' * 64 - - # fch = ' ' - # if len(fill_char) >= 1: - # fch = fill_char[0] - - while True: - - print('\r' + proxy_string, end='', flush=True) - print('\r' + prompt, end='', flush=True) - - c = getch.getch() - if c == b'\r' or c == b'\n': - break - elif c == b'\x08': - if len(p_s): - p_s = p_s[:-1] - continue - - p_s += to_str(c) - if len(p_s) >= max_len: - break - - print('', flush=True) - return p_s - - -# ============================================================================= -def password_input(prompt='', fill_char='*', max_len=64): - - if HAS_GETCH: - return password_input_getch(prompt=prompt, fill_char=fill_char, max_len=max_len) - - import getpass - - return getpass.getpass(prompt=prompt) - - # ============================================================================= class CreateTerraformHandler(BaseHandler): """ diff --git a/lib/cr_tf/tools.py b/lib/cr_tf/tools.py new file mode 100644 index 0000000..846796b --- /dev/null +++ b/lib/cr_tf/tools.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +@author: Frank Brehm +@contact: frank.brehm@pixelpark.com +@copyright: © 2023 by Frank Brehm, Berlin +@summary: A handler module for underlaying actions +""" +from __future__ import absolute_import, print_function + +# Standard module +import logging + +HAS_GETCH = False +try: + import getch + HAS_GETCH = True +except ImportError: + pass + +# Third party modules +from fb_tools.common import to_str + +__version__ = '0.1.0' +LOG = logging.getLogger(__name__) + + +# ============================================================================= +def password_input_getch(prompt='', fill_char='*', max_len=64): + p_s = '' + proxy_string = ' ' * 64 + + while True: + + print('\r' + proxy_string, end='', flush=True) + print('\r' + prompt, end='', flush=True) + + c = getch.getch() + if c == b'\r' or c == b'\n': + break + elif c == b'\x08': + if len(p_s): + p_s = p_s[:-1] + continue + + p_s += to_str(c) + if len(p_s) >= max_len: + break + + print('', flush=True) + return p_s + + +# ============================================================================= +def password_input(prompt='', fill_char='*', max_len=64): + + if HAS_GETCH: + return password_input_getch(prompt=prompt, fill_char=fill_char, max_len=max_len) + + import getpass + + return getpass.getpass(prompt=prompt) + + +# ============================================================================= + +if __name__ == "__main__": + + pass + +# ============================================================================= + +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list