forked from shanto268/VeriCold_log_parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogConvert.py
53 lines (45 loc) · 1.45 KB
/
LogConvert.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
import pandas as pd
import sys, os
from log_parser import parse
class LogConvert:
def __init__(self, file_name):
self.file_path = file_name
self.name = self.get_formatted_name()
self.titles, self.data = self.get_data()
def get_formatted_name(self):
name = os.path.split(self.file_path)[1].replace("vcl","csv")
fpath = os.path.split(self.file_path)[0]
if sys.platform == "win32":
try:
save_path = fpath+r"\\data_csv\\"
try:
os.makedirs(save_path)
except:
pass
name = save_path + name
except:
raise SystemError()
else:
save_path = fpath+r"/data_csv/"
try:
os.makedirs(save_path)
except:
pass
name = save_path + name
return name
def get_data(self):
if not self.file_path:
raise ValueError()
try:
titles, data = parse(self.file_path)
except (IOError, RuntimeError) as ex:
print(' '.join(repr(a) for a in ex.args))
return titles, data
def get_df(self) -> bool:
df = pd.DataFrame(self.data.T)
df.columns = self.titles
return df
def to_csv(self) -> bool:
df = self.get_df()
df.to_csv(self.name, index=False)
print("{} has been generated!".format(self.name))