-
Notifications
You must be signed in to change notification settings - Fork 2
/
log_manager.py
executable file
·37 lines (29 loc) · 1.13 KB
/
log_manager.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
import os
import logger
log = logger.get()
class LogManager(object):
def __init__(self, folder):
self.folder = folder
if not os.path.exists(self.folder):
os.makedirs(self.folder)
self.catalog = os.path.join(folder, 'catalog')
self.filelist = []
if not os.path.exists(self.catalog):
with open(self.catalog, 'w') as f:
f.write('filename,type,name\n')
else:
with open(self.catalog, 'r') as f:
lines = f.readlines()
lines = lines[1:]
for line in lines:
parts = line.strip('\n').split(',')
self.filelist.append((parts[0], parts[1], parts[2]))
def register(self, filename, typ, name):
basename = os.path.basename(filename)
for pair in self.filelist:
if pair[0] == basename:
log.info('File {} is already registered.'.format(basename))
return
with open(self.catalog, 'a') as f:
f.write('{},{},{}\n'.format(basename, typ, name))
self.filelist.append((basename, typ, name))