-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
sort_smartcard_list.py
executable file
·82 lines (62 loc) · 1.87 KB
/
sort_smartcard_list.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
78
79
80
81
82
#! /usr/bin/env python3
import difflib
import pprint
import sys
pp = pprint.PrettyPrinter(indent=4)
def check_format():
ret_value = False
ATRs = list()
with open("smartcard_list.txt", "r") as f:
for line in f.readlines():
if line.endswith(" \n") or line.endswith("\t\n"):
print("Trailing space in:", line)
ret_value = True
if line == "\n":
continue
if line.startswith("#") or line.startswith("\t"):
continue
# check the ATR is all upper case
if line.upper() != line:
print("error:", line)
ret_value = True
ATRs.append(line.strip())
# if line.startswith("\t"):
# ATRs.append([atr, line.strip()])
# else:
# atr = line.strip()
# pp.pprint(ATRs)
sorted_ATRs = list(ATRs)
sorted_ATRs.sort()
uniq_ATRs = sorted(set(sorted_ATRs))
# pp.pprint(sorted_ATRs)
# pp.pprint(uniq_ATRs)
# sorted
for line in difflib.context_diff(ATRs, sorted_ATRs):
print(line)
ret_value = True
# uniq
for line in difflib.context_diff(sorted_ATRs, uniq_ATRs):
print(line)
ret_value = True
return ret_value
def count_cards():
# compte le nombre de nouveau ATR
from subprocess import Popen, PIPE
p1 = Popen(["git", "diff"], stdout=PIPE)
p2 = Popen(["grep", "+3[B,F]"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()
output = p2.communicate()[0]
output = output.decode("utf-8")
size = len(output.split("\n")) - 1
if size >= 10:
print()
print("********************")
print(" %d new ATRs" % size)
print("********************")
print()
else:
print("only", size, "ATR")
if __name__ == "__main__":
if check_format():
sys.exit(1)
count_cards()