1 # -*- coding: iso-8859-1 -*-
5 @copyright: 2008 Johannes Berg
6 @license: GNU GPL, see COPYING for details.
10 from dbparse import DBParser, band_flags
12 Dependencies = ["time"]
14 def _country(macro, bpc, code):
15 band, power, country = bpc
22 f.text('Regulatory definition for %s' % _get_iso_code(code)),
26 result.append(f.table(1))
29 f.table_cell(1), f.strong(1),
31 f.strong(0), f.table_cell(0),
32 f.table_cell(1), f.strong(1),
33 f.text('Max BW (MHz)'),
34 f.strong(0), f.table_cell(0),
35 f.table_cell(1), f.strong(1),
37 f.strong(0), f.table_cell(0),
38 f.table_cell(1), f.strong(1),
39 f.text('Environment'),
40 f.strong(0), f.table_cell(0),
41 f.table_cell(1), f.strong(1),
42 f.text('Max antenna gain (dBi)'),
43 f.strong(0), f.table_cell(0),
44 f.table_cell(1), f.strong(1),
45 f.text('Max IR PTMP (dBm)'),
46 f.strong(0), f.table_cell(0),
47 f.table_cell(1), f.strong(1),
48 f.text('Max IR PTP (dBm)'),
49 f.strong(0), f.table_cell(0),
50 f.table_cell(1), f.strong(1),
51 f.text('Max EIRP PTMP (dBm)'),
52 f.strong(0), f.table_cell(0),
53 f.table_cell(1), f.strong(1),
54 f.text('Max EIRP PTP (dBm)'),
55 f.strong(0), f.table_cell(0),
59 l = list(country[code])
60 l.sort(cmp=lambda x,y: cmp(band[x[0]], band[y[0]]))
65 for flag, val in band_flags.iteritems():
76 f.text('%.3f - %.3f' % (b[0], b[1])),
79 f.text('%.3f' % (b[2],)),
82 f.text(', '.join(flags)),
88 f.text('%.3f' % p[1]),
91 f.text('%.3f' % p[2]),
94 f.text('%.3f' % p[3]),
97 f.text('%.3f' % p[4]),
100 f.text('%.3f' % p[5]),
105 result.append(f.table(0))
107 result.append(f.linebreak(0))
108 result.append(f.linebreak(0))
109 result.append(macro.request.page.link_to(macro.request, 'return to country list'))
110 return ''.join(result)
114 def _get_iso_code(code):
116 for line in codecs.open('/usr/share/iso-codes/iso_3166.tab', encoding='utf-8'):
118 code, name = line.split('\t')
119 _iso_list[code] = name
120 _iso_list['00'] = 'Debug 1'
121 _iso_list['01'] = 'Debug 2'
122 _iso_list['02'] = 'Debug 3'
123 _iso_list['03'] = 'Debug 4'
124 return _iso_list.get(code, 'Unknown (%s)' % code)
126 def macro_Regulatory(macro):
127 _ = macro.request.getText
128 request = macro.request
131 country = request.form.get('alpha2', [None])[0]
133 dbpath = '/tmp/db.txt'
134 if hasattr(request.cfg, 'regdb_path'):
135 dbpath = request.cfg.regdb_path
136 bpc = DBParser().parse(open(dbpath))
139 return _country(macro, bpc, country)
141 band, power, country = bpc
142 countries = country.keys()
143 countries = [(_get_iso_code(code), code) for code in countries]
154 result.append(f.bullet_list(1))
155 for name, code in countries:
158 request.page.link_to(request, name, querystr={'alpha2': code}),
161 result.append(f.bullet_list(0))
163 return ''.join(result)