/[pcsclite]/website/matrix.py
ViewVC logotype

Contents of /website/matrix.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3345 - (show annotations) (download) (as text)
Fri Mar 13 15:57:32 2009 UTC (4 years, 2 months ago) by rousseau
File MIME type: text/x-python
File size: 4513 byte(s)
generate web pages
1 #!/usr/bin/env python
2
3 # matrix.py generate a matrix of all readers characteristics
4 # Copyright (C) 2009 Ludovic Rousseau
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 import glob
21 import os
22 import ConfigParser
23 import pprint
24 import templayer
25 import time
26
27 pp = pprint.PrettyPrinter(indent=4)
28
29 def merge(*input):
30 """
31 merge all the lists passed as argument
32 """
33 return reduce(list.__add__, input, list())
34
35 def parse_reader(path, reader):
36 """
37 parse a reader CCID descriptor and return a dictionnary
38 """
39 reader_dict = {}
40 reader_file = open(path+reader)
41 for line in reader_file.readlines():
42 line = line[0:-1]
43 l = line.strip(" ").split(':')
44 if (len(l) > 1):
45 reader_dict[l[0]] = l[1].strip(" ")
46 reader_file.close()
47 return reader_dict
48
49 def parse_all(path, reader_list):
50 """
51 parse each reader from list
52 return a dictionnary
53 """
54 readers = {}
55 for reader in reader_list:
56 p = parse_reader(path, reader)
57 readers[reader] = p
58
59 return readers
60
61 def parse_ini(path, inifile):
62 """
63 parse a foobas.ini file to extract all informations
64 """
65 config = ConfigParser.ConfigParser()
66 # do not use the default case insensitive transform for key value
67 config.optionxform = str
68 config.read(inifile)
69 reader_list = config.sections()
70
71 readers = parse_all(path, reader_list)
72 for r in readers.keys():
73 for o in config.options(r):
74 readers[r][o] = config.get(r, o)
75
76 return readers
77
78 def check_list(path, reader_list):
79 cwd = os.getcwd()
80 os.chdir(path)
81 real_list = glob.glob("*.txt")
82 os.chdir(cwd)
83
84 # check that each reader file is listed
85 #print real_list
86 for r in reader_list:
87 #print "remove ", r
88 try:
89 real_list.remove(r)
90 except:
91 print "reader %s not yet listed" % r
92
93 # also remove the non-reader supported_readers.txt file
94 real_list.remove("supported_readers.txt")
95
96 # some USB descriptor are not listed in readers.txt?
97 if len(real_list) > 0:
98 raise Exception("readers %s are not listed" % real_list)
99
100 def get_by_manufacturer(readers):
101 d = {}
102 for r in readers.keys():
103 d.setdefault(readers[r]['iManufacturer'], []).append(r)
104 return d
105
106 if __name__ == "__main__":
107 path = "../trunk/Drivers/ccid/readers/"
108
109 supported_readers = parse_ini(path, "supported.ini")
110 shouldwork_readers = parse_ini(path, "shouldwork.ini")
111 unsupported_readers = parse_ini(path, "unsupported.ini")
112 reader_list = merge(supported_readers.keys(),
113 shouldwork_readers.keys(), unsupported_readers.keys())
114 #pp.pprint(reader_list)
115 check_list(path, reader_list)
116
117 # sort the readers by manufacturers
118 manufacturer_readers = get_by_manufacturer(supported_readers)
119 manufacturers = list(manufacturer_readers)
120 manufacturers.sort(key=str.lower)
121
122 r = "Gemalto_PDT.txt"
123 #pp.pprint(supported_readers[r])
124 for k in supported_readers[r].keys():
125 #print k, ":", supported_readers[r][k]
126 pass
127
128 template = templayer.HTMLTemplate("supported.template")
129 file_writer = template.start_file(file=file("supported.html", "w"))
130 main_layer = file_writer.open(date=time.asctime())
131
132 # for each manufacturer
133 for m in manufacturers:
134 main_layer.write_layer('manufacturer', manufacturer=m)
135
136 # for each reader
137 for r in sorted(manufacturer_readers[m]):
138 main_layer.write_layer('reader',
139 manufacturer=m,
140 product=supported_readers[r]['iProduct'],
141 url=supported_readers[r].get('url', ""),
142 image="img/" + supported_readers[r].get('image',
143 "no_image.png"))
144 file_writer.close()

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5