-
Notifications
You must be signed in to change notification settings - Fork 1
/
basics.py
executable file
·41 lines (30 loc) · 969 Bytes
/
basics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import shutil
import traceback
def create_folder_structure(filename):
d = os.path.dirname(filename)
if not os.path.exists(d):
os.makedirs(d)
def delete_folder(filename, force=True):
d = os.path.dirname(filename)
if os.path.exists(d):
shutil.rmtree(d)
def delete_file(filename):
if os.path.isfile(filename):
os.remove(filename)
def find_files(base_dir, file_ending):
res = list()
for root, dirs, files in os.walk(base_dir):
if not root.endswith('/'):
root += '/'
res.extend([root + i for i in filter(lambda x: x.endswith(file_ending), files)])
return sorted(res)
def try_catch_traceback_wrapper(func):
def inner(*args, **kwargs):
try:
ret_val = func(*args, **kwargs)
except Exception as e:
print(traceback.format_exc())
raise e
return ret_val
return inner