sort_smartcard_list.py 1.21 KB
Newer Older
Ludovic Rousseau's avatar
Ludovic Rousseau committed
1 2
#! /usr/bin/env python

3 4
from __future__ import print_function

Ludovic Rousseau's avatar
Ludovic Rousseau committed
5 6
import difflib
import pprint
7

Ludovic Rousseau's avatar
Ludovic Rousseau committed
8 9 10
pp = pprint.PrettyPrinter(indent=4)

ATRs = list()
11 12 13 14
with open("smartcard_list.txt", "r") as f:
    for l in f.readlines():
        if l.endswith(" \n") or l.endswith("\t\n"):
            print("Trailing space in:", l)
15

16 17
        if l == "\n":
            continue
18

19 20
        if l.startswith("#") or l.startswith("\t"):
            continue
21

22 23 24
        # check the ATR is all upper case
        if l.upper() != l:
            print("error:", l)
25

26
        ATRs.append(l.strip())
27 28 29 30
# 	if l.startswith("\t"):
# 		ATRs.append([atr, l.strip()])
# 	else:
# 		atr = l.strip()
Ludovic Rousseau's avatar
Ludovic Rousseau committed
31

32
# pp.pprint(ATRs)
Ludovic Rousseau's avatar
Ludovic Rousseau committed
33 34 35
sorted_ATRs = list(ATRs)
sorted_ATRs.sort()

36
# pp.pprint(sorted_ATRs)
Ludovic Rousseau's avatar
Ludovic Rousseau committed
37 38

for l in difflib.context_diff(ATRs, sorted_ATRs):
39
    print(l)
40 41 42 43 44 45 46 47 48

# 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]

49
output = output.decode("utf-8")
50

51
size = len(output.split("\n")) - 1
52
if size >= 10:
53 54 55 56 57
    print()
    print("********************")
    print("    %d new ATRs" % size)
    print("********************")
    print()