#!/usr/bin/env python # matrix.py generate a matrix of all readers characteristics # Copyright (C) 2009 Ludovic Rousseau # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import glob import os import ConfigParser import pprint import templayer import time pp = pprint.PrettyPrinter(indent=4) def merge(*input): """ merge all the lists passed as argument """ return reduce(list.__add__, input, list()) def parse_reader(path, reader): """ parse a reader CCID descriptor and return a dictionnary """ reader_dict = {} reader_file = open(path+reader) for line in reader_file.readlines(): line = line[0:-1] l = line.strip(" ").split(':') if (len(l) > 1): reader_dict[l[0]] = l[1].strip(" ") reader_file.close() return reader_dict def parse_all(path, reader_list): """ parse each reader from list return a dictionnary """ readers = {} for reader in reader_list: p = parse_reader(path, reader) readers[reader] = p return readers def parse_ini(path, inifile): """ parse a foobas.ini file to extract all informations """ config = ConfigParser.ConfigParser() # do not use the default case insensitive transform for key value config.optionxform = str config.read(inifile) reader_list = config.sections() readers = parse_all(path, reader_list) for r in readers.keys(): for o in config.options(r): readers[r][o] = config.get(r, o) return readers def check_list(path, reader_list): cwd = os.getcwd() os.chdir(path) real_list = glob.glob("*.txt") os.chdir(cwd) # check that each reader file is listed #print real_list for r in reader_list: #print "remove ", r try: real_list.remove(r) except: print "reader %s not yet listed" % r # also remove the non-reader supported_readers.txt file real_list.remove("supported_readers.txt") # some USB descriptor are not listed in readers.txt? if len(real_list) > 0: raise Exception("readers %s are not listed" % real_list) def get_by_manufacturer(readers): d = {} for r in readers.keys(): d.setdefault(readers[r]['iManufacturer'], []).append(r) return d if __name__ == "__main__": path = "../trunk/Drivers/ccid/readers/" supported_readers = parse_ini(path, "supported.ini") shouldwork_readers = parse_ini(path, "shouldwork.ini") unsupported_readers = parse_ini(path, "unsupported.ini") reader_list = merge(supported_readers.keys(), shouldwork_readers.keys(), unsupported_readers.keys()) #pp.pprint(reader_list) check_list(path, reader_list) # sort the readers by manufacturers manufacturer_readers = get_by_manufacturer(supported_readers) manufacturers = list(manufacturer_readers) manufacturers.sort(key=str.lower) r = "Gemalto_PDT.txt" #pp.pprint(supported_readers[r]) for k in supported_readers[r].keys(): #print k, ":", supported_readers[r][k] pass template = templayer.HTMLTemplate("supported.template") file_writer = template.start_file(file=file("supported.html", "w")) main_layer = file_writer.open(date=time.asctime()) # for each manufacturer for m in manufacturers: main_layer.write_layer('manufacturer', manufacturer=m) # for each reader for r in sorted(manufacturer_readers[m]): url=supported_readers[r].get('url', "") note = supported_readers[r].get('note', "").split('\n') note_layer = main_layer.open_layer('reader', manufacturer=m, product=supported_readers[r]['iProduct'], image="img/" + supported_readers[r].get('image', "no_image.png")) if (url): note_layer.write_layer('url', url = url, manufacturer=m, product=supported_readers[r]['iProduct']) features = supported_readers[r].get('features', "") if features: note_layer.write_layer('features', features = features) for n in note: note_layer.write_layer('note', contents = n) file_writer.close()