-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathioimage.py
77 lines (50 loc) · 1.95 KB
/
ioimage.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import yaml
# import wget
# from pyunpack import Archive
from time import strftime, localtime
# from termcolor import colored
class IO():
def __init__(self, log_dir=None):
self.log_dir = log_dir
def read_yaml_file(self, config_file):
pfile = open(config_file)
d = yaml.load(pfile)
pfile.close()
return d
# def download_data(self, filepath, outputdir):
#
# _, rar_file = os.path.split(filepath)
# rar_file = os.path.join(outputdir, rar_file)
#
# if not os.path.exists(rar_file):
# self.print_info('Downloading {} to {}'.format(filepath, rar_file))
# _ = wget.download(filepath, out=outputdir)
#
# self.print_info('Decompressing {} to {}'.format(rar_file, outputdir))
# Archive(rar_file).extractall(outputdir)
def print_info(self, info_string, quite=False):
info = '[{0}][INFO] {1}'.format(self.get_local_time(), info_string)
# print (colored(info, 'green'))
print (info)
def print_warning(self, warning_string):
warning = '[{0}][WARNING] {1}'.format(self.get_local_time(), warning_string)
# print (colored(warning, 'blue'))
print (warning)
def print_error(self, error_string):
error = '[{0}][ERROR] {1}'.format(self.get_local_time(), error_string)
# print (colored(error, 'red'))
print (error)
def get_local_time(self):
return strftime("%d %b %Y %A %H:%M:%S", localtime())
def read_file_list(self, filelist):
pfile = open(filelist)
filenames = pfile.readlines()
pfile.close()
filenames = [f.strip() for f in filenames]
return filenames
def split_pair_names(self, filenames, base_dir):
filenames = [c.split(' ') for c in filenames]
# print(filenames)
filenames = [(os.path.join(base_dir, c[0]), os.path.join(base_dir, c[1])) for c in filenames]
return filenames