Skip to content
Snippets Groups Projects
Commit bb11795e authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

removed ref to threadnames.py and added missing ui files

parent f060416c
No related branches found
No related tags found
No related merge requests found
...@@ -13,12 +13,10 @@ from _collections import deque ...@@ -13,12 +13,10 @@ from _collections import deque
import time import time
import traceback import traceback
import zipfile import zipfile
from wetb.utils.timing import print_time
import glob import glob
import getpass
from sshtunnel import SSHTunnelForwarder, SSH_CONFIG_FILE from sshtunnel import SSHTunnelForwarder, SSH_CONFIG_FILE
from wetb.utils.ui import UI from wetb.utils.ui import UI
from wetb.utils import threadnames
...@@ -138,9 +136,6 @@ class SSHClient(object): ...@@ -138,9 +136,6 @@ class SSHClient(object):
return self.client return self.client
def connect(self): def connect(self):
print ("connect", self.host, threadnames.name())
#print (traceback.print_stack())
if self.gateway: if self.gateway:
if self.gateway.interactive_auth_handler: if self.gateway.interactive_auth_handler:
self.tunnel = SSHInteractiveAuthTunnelForwarder(self.gateway.interactive_auth_handler, self.tunnel = SSHInteractiveAuthTunnelForwarder(self.gateway.interactive_auth_handler,
...@@ -215,9 +210,7 @@ class SSHClient(object): ...@@ -215,9 +210,7 @@ class SSHClient(object):
print ("Retry download %s, #%d"%(remotefilepath, i)) print ("Retry download %s, #%d"%(remotefilepath, i))
try: try:
#print ("start download enter", threadnames.name())
SSHClient.__enter__(self) SSHClient.__enter__(self)
#print ("start download", threadnames.name())
if isinstance(localfile, (str, bytes, int)): if isinstance(localfile, (str, bytes, int)):
ret = self.sftp.get(remotefilepath, localfile, callback=callback) ret = self.sftp.get(remotefilepath, localfile, callback=callback)
elif hasattr(localfile, 'write'): elif hasattr(localfile, 'write'):
...@@ -226,10 +219,8 @@ class SSHClient(object): ...@@ -226,10 +219,8 @@ class SSHClient(object):
except: except:
pass pass
finally: finally:
#print ("End download", threadnames.name())
SSHClient.__exit__(self) SSHClient.__exit__(self)
#print ("End download exit", threadnames.name())
print ("Download %s failed from %s"%(remotefilepath, self.host)) print ("Download %s failed from %s"%(remotefilepath, self.host))
if verbose: if verbose:
print (ret) print (ret)
...@@ -248,9 +239,7 @@ class SSHClient(object): ...@@ -248,9 +239,7 @@ class SSHClient(object):
localfile.seek(0) localfile.seek(0)
ret = self.sftp.putfo(localfile, filepath, file_size=size, callback=callback) ret = self.sftp.putfo(localfile, filepath, file_size=size, callback=callback)
finally: finally:
#print ("End upload", threadnames.name())
SSHClient.__exit__(self) SSHClient.__exit__(self)
#print ("End upload exit", threadnames.name())
if verbose: if verbose:
print (ret) print (ret)
...@@ -414,9 +403,7 @@ class SharedSSHClient(SSHClient): ...@@ -414,9 +403,7 @@ class SharedSSHClient(SSHClient):
self.shared_ssh_queue.append(threading.get_ident()) self.shared_ssh_queue.append(threading.get_ident())
while self.shared_ssh_queue[0] != threading.get_ident(): while self.shared_ssh_queue[0] != threading.get_ident():
#print ("Waiting for ssh", threadnames.name(), [threadnames.name(id) for id in self.shared_ssh_queue])
time.sleep(2) time.sleep(2)
#print ("Got SSH", threadnames.name())
return self.client return self.client
......
import sys
import time
from wetb.utils.ui import OutputUI, InputUI, StatusUI
class TextOutputUI(OutputUI):
last_text = ""
def __init__(self, parent=None):
OutputUI.__init__(self, parent=parent)
self.errors = sys.stdout.errors
self.encoding = sys.stdout.encoding
sys.stdout = self
sys.stderr = self
def show_message(self, msg, title="Information"):
#self.last_text = msg
if title != "":
print ("\n\n%s\n%s\n%s\n" % (title, "-"*len(title), msg))
else:
print (msg)
def show_warning(self, msg, title="Warning"):
#self.last_text = msg
print ("%s\n%s\n%s" % (title, "-"*len(title), msg))
def show_text(self, text, end="\n", flush=False):
#self.last_text = text
#print (text, end=end)
self.write(text+end)
if flush:
sys.stdout.flush()
def flush(self):
sys.__stdout__.flush()
def write(self, txt):
if txt.strip()!="":
self.last_text = txt
sys.__stdout__.write(txt)
class TextInputUI(InputUI):
def get_confirmation(self, title, msg):
raise NotImplementedError
def get_string(self, title, msg):
raise NotImplementedError
def get_open_filename(self, title="Open", filetype_filter="*.*", file_dir=None, selected_filter=None):
raise NotImplementedError
def get_save_filename(self, title, filetype_filter, file_dir=None, selected_filter=None):
raise NotImplementedError
def get_open_filenames(self, title, filetype_filter, file_dir=None):
raise NotImplementedError
def get_foldername(self, title='Select directory', file_dir=None):
raise NotImplementedError
class TextStatusUI(StatusUI, TextOutputUI):
def progress_iterator(self, sequence, text="Working... Please wait", allow_cancel=True, always_refresh=False):
global pct
it = iter(list(sequence))
if it.__length_hint__() > 0:
def init():
global pct
self.show_text("\n\n|0" + " " * 46 + "50%" + " " * 46 + "100%|")
pct = 0
self.show_text("|", end="")
self.show_text(text, flush=True)
#sys.__stdout__.flush()
N = it.__length_hint__()
init()
for n, v in enumerate(it):
#if n % 100 == 99:
# self.show_text("")
if (self.last_text != "." and n > 0) or (always_refresh and ((n + 1) / N * 100 > pct)):
init()
while ((n + 1) / N * 100 > pct):
self.show_text(".", end="", flush=True)
pct += 1
yield(v)
self.show_text("|")
def exec_long_task(self, text, allow_cancel, task, *args, **kwargs):
print (text)
return task(*args, **kwargs)
def start_wait(self):
#print ("Working please wait")
pass
def end_wait(self):
#print ("finish")
pass
def progress_callback(self, text="Working... Please wait", always_refresh=False):
class ProgressCallBack():
def __init__(self, ui, text, always_refresh=False):
self.ui = ui
self.text = text
self.always_refresh = always_refresh
self.pct = None
def init(self):
self.ui.show_text("\n\n" + self.text, flush=True)
self.ui.show_text("|0" + " " * 46 + "50%" + " " * 46 + "100%|")
self.pct = 0
self.ui.show_text("|", end="")
def __call__(self, n, N):
if (self.pct is None) or (self.ui.last_text != "." and self.pct > 0) or (self.always_refresh and ((n + 1) / N * 100 > self.pct)):
self.init()
while ((n + 1) / N * 100 > (self.pct+1)):
self.ui.show_text(".", end="", flush=True)
self.pct += 1
if self.pct==100:
self.ui.show_text("|")
return ProgressCallBack(self, text, always_refresh)
class TextUI(TextInputUI, TextStatusUI):
pass
if __name__ == "__main__":
def task(callback):
for i in range(100):
callback(i,100)
time.sleep(0.05)
task (TextStatusUI().progress_callback())
\ No newline at end of file
class OutputUI(object):
def __init__(self, parent=None):
self.parent = parent
def run(self, f, *args, **kwargs):
try:
return f(*args, **kwargs)
except Warning as e:
self.show_warning(e)
except Exception as e:
self.show_error(e)
raise
def show_error(self, msg, title="Error"):
pass
def show_message(self, msg, title="Information"):
pass
def show_warning(self, msg, title="Warning"):
pass
def show_text(self, text, end="\n", flush=False):
pass
class InputUI(object):
def get_confirmation(self, title, msg):
raise NotImplementedError
def get_string(self, title, msg):
raise NotImplementedError
def get_open_filename(self, title="Open", filetype_filter="*.*", file_dir=None, selected_filter=None):
raise NotImplementedError
def get_save_filename(self, title, filetype_filter, file_dir=None, selected_filter=None):
raise NotImplementedError
def get_open_filenames(self, title, filetype_filter, file_dir=None):
raise NotImplementedError
def get_foldername(self, title='Select directory', file_dir=None):
raise NotImplementedError
class StatusUI(object):
is_waiting = False
def progress_iterator(self, sequence, text="Working... Please wait", allow_cancel=True):
return sequence
def exec_long_task(self, text, allow_cancel, task, *args, **kwargs):
return task(*args, **kwargs)
def progress_callback(self):
def callback(n,N):
pass
return callback
def start_wait(self):
self.is_waiting = True
def end_wait(self):
self.is_waiting = False
class UI(InputUI, OutputUI, StatusUI):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment