''' Created on Feb 18, 2021 @author: vnc-console ''' import os import traceback import operator import sys import platform import subprocess as sp from time import sleep def filter_files(code, _ext='.xml', path=None): '''lists all pdf's in current directory''' if path: my_files = filter(lambda file: file.endswith(_ext) and code in file or file.endswith(_ext.upper()) and code in file, os.listdir(path)) else: my_files = filter(lambda file: file.endswith(_ext) and code in file or file.endswith(_ext.upper()) and code in file, os.listdir()) return my_files def count_down(t, d_type, up_down, max_count=None): if up_down == 'down': one_ = -1 OPERAND_ = operator.ge max_count = 0 finish = 'count%s finished' % up_down elif up_down == 'up': one_ = 1 OPERAND_ = operator.le finish = 'count%s finished' % up_down max_count = max_count while OPERAND_(t, max_count): if d_type == 'm': mins, secs = divmod(t, 60) tf = '{0:2d}:{1:2d}'.format(mins, secs) print(tf, end='\r') sleep(1) t += one_ elif d_type == 'h': hour, rem = divmod(t, 60) _, secs = divmod(rem, 60) hours, mins = divmod(hour, 60) tf = '{0:02d}:{1:02d}:{2:02d}'.format(hours, mins, secs) print(tf, end='\r') sleep(1) t += one_ else: print(finish) def pretty_exc(exc): exc_type, _exc_obj, exc_tb = sys.exc_info() # fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] for tb in list(traceback.format_exception(exc_type, _exc_obj, exc_tb)): print(tb) # print(exc_type, fname, 'ln', exc_tb.tb_lineno, '-' + str(exc)) def file_open(file_name): abs_path = os.path.abspath(file_name) if platform.system() == 'Windows': sp.run(f'start {abs_path}', shell=True) elif platform.system() == 'Linux': sp.run(['xdg-open', f'{abs_path}']) else: raise NotImplementedError