sort_smartcard_list.py 1.17 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 7 8 9
import difflib
import pprint
pp = pprint.PrettyPrinter(indent=4)

ATRs = list()
10 11 12 13
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)
14

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

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

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

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

#pp.pprint(ATRs)
sorted_ATRs = list(ATRs)
sorted_ATRs.sort()

#pp.pprint(sorted_ATRs)

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

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

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