-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
66 lines (51 loc) · 1.72 KB
/
cli.py
File metadata and controls
66 lines (51 loc) · 1.72 KB
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
import argparse, json, os, time
from polyvinyl import lin, SEEK_END
from polyvinyl.utils import identifier, config, colors, token as token_d
def ParseCli():
parser = argparse.ArgumentParser(
prog="PolyVinylCli",
description="PolyVinyl Command Line Tool")
parser.add_argument("--in")
parser.add_argument("--out")
parser.add_argument("--log-color", action="store_true")
return parser.parse_args()
def parse_arg(ar):
try:
ar.index("=")
ident = identifier.Ident(ar)
s = ident.name
except ValueError:
ident = None
s = ar
file_name, base, ext = config.get_name_ext(s)
return (ident, file_name, base, ext)
def show(args, records):
if args.log_color:
print("\x1b[{}m{} records\x1b[0m".format(colors.CYAN, len(records)))
else:
print("{} records".format(len(records)))
for rec in records:
for k,v in rec.items():
if k.find("date") != -1:
v = token_d.time_from_bytes(v)
if args.log_color:
print("\x1b[{};{}m{}\x1b[0m: {}".format(colors.BOLD, colors.YELLOW,k,v))
else:
print("{}: {}".format(k,v))
print("")
if __name__ == "__main__":
args = ParseCli()
in_ident, in_file, _, in_ext = parse_arg(getattr(args, "in"))
if in_ident:
print("Handle Ident")
else:
if in_ext == "linr":
records = []
with open(in_file, "rb") as f:
f.seek(0, SEEK_END)
while True:
rec = lin.map_r(f, None)
if not rec:
break
records.append(rec)
show(args, records)