From 4f8d73db1d416b9d431a8d9b610bcead5de9bb81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B8=D1=80=D0=B5=D1=86=D0=BA=D0=B8=D0=B9=20=D0=9C?= =?UTF-8?q?=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= Date: Tue, 31 Jul 2012 16:32:02 +0400 Subject: [PATCH] Improve spinner by method pause/resume. Add -P param from get password without interactive. --- console/application/cl_client.py | 18 ++++++++++++++++++ console/application/methods_func.py | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/console/application/cl_client.py b/console/application/cl_client.py index 8ab66a5..1ec21e2 100644 --- a/console/application/cl_client.py +++ b/console/application/cl_client.py @@ -65,6 +65,8 @@ class StoppableThread(threading.Thread): def __init__(self): super(StoppableThread, self).__init__() self._stop = threading.Event() + self._pause = threading.Event() + self._paused = threading.Event() def run(self): l = ['|','/','-','\\','|','/','-','\\'] @@ -74,10 +76,23 @@ class StoppableThread(threading.Thread): sys.stdout.write("\r\r" + i) sys.stdout.flush() time.sleep(.1) + while self.paused() and not self.stopped(): + self._paused.set() if self.stopped(): sys.stdout.write("\b") sys.stdout.flush() return 0 + + + def pause(self): + self._pause.set() + while not self._paused.is_set(): + self._paused.clear() + sys.stdout.write("\r") + sys.stdout.flush() + + def resume(self): + self._pause.clear() def stop(self): self._stop.set() @@ -85,6 +100,9 @@ class StoppableThread(threading.Thread): def stopped(self): return self._stop.isSet() + def paused(self): + return self._pause.isSet() + def connect_with_cert(cert, path_to_cert, url, args, wait_thread, clVarsCore, crypto_Error, Connect_Error): flag_thread_start = False diff --git a/console/application/methods_func.py b/console/application/methods_func.py index 7afde09..2087b4a 100644 --- a/console/application/methods_func.py +++ b/console/application/methods_func.py @@ -90,6 +90,10 @@ def parse(): parser.add_argument( '-f', '--force', action='store_true', default=False, dest = 'no_questions', help=_('silent during the process')) + parser.add_argument( + '-P', action='store_true', default=False, + dest = 'stdin_passwd', + help=_('use passwords for the users accounts from standard input')) return parser def get_view(client, method, sid, view_params): @@ -103,6 +107,7 @@ def get_view(client, method, sid, view_params): def call_method(client, args, wait_thread): method = args.method no_questions = args.no_questions + stdin_passwd = args.stdin_passwd view_params = get_view_params(client, method + '_view', step = None, \ expert = True) @@ -122,7 +127,7 @@ def call_method(client, args, wait_thread): _print (_('Unknown parameter'), i) raise Exception(1) param_object, steps = collect_object(client, param_object, view, args, - wait_thread) + wait_thread,stdin_passwd=stdin_passwd) if steps.label and hasattr (param_object, 'CheckOnly'): param_object['CheckOnly'] = True check_res = {}