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)),
28 result.append(f.table(1))
31 f.table_cell(1), f.strong(1),
33 f.strong(0), f.table_cell(0),
34 f.table_cell(1), f.strong(1),
35 f.text('Max BW (MHz)'),
36 f.strong(0), f.table_cell(0),
37 f.table_cell(1), f.strong(1),
39 f.strong(0), f.table_cell(0),
40 f.table_cell(1), f.strong(1),
41 f.text('Environment'),
42 f.strong(0), f.table_cell(0),
43 f.table_cell(1), f.strong(1),
44 f.text('Max antenna gain (dBi)'),
45 f.strong(0), f.table_cell(0),
46 f.table_cell(1), f.strong(1),
47 f.text('Max IR PTMP (dBm)'),
48 f.strong(0), f.table_cell(0),
49 f.table_cell(1), f.strong(1),
50 f.text('Max IR PTP (dBm)'),
51 f.strong(0), f.table_cell(0),
52 f.table_cell(1), f.strong(1),
53 f.text('Max EIRP PTMP (dBm)'),
54 f.strong(0), f.table_cell(0),
55 f.table_cell(1), f.strong(1),
56 f.text('Max EIRP PTP (dBm)'),
57 f.strong(0), f.table_cell(0),
61 for b, p in country[code]:
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
130 country = request.form.get('alpha2', [None])[0]
132 dbpath = '/tmp/db.txt'
133 if hasattr(request.cfg, 'regdb_path'):
134 dbpath = request.cfg.regdb_path
135 bpc = DBParser().parse(open(dbpath))
138 return _country(macro, bpc, country)
140 band, power, country = bpc
141 countries = country.keys()
142 countries = [(_get_iso_code(code), code) for code in countries]
146 result.append(macro.formatter.bullet_list(1))
147 for name, code in countries:
149 macro.formatter.listitem(1),
150 request.page.link_to(request, name, querystr={'alpha2': code}),
151 macro.formatter.listitem(0),
153 result.append(macro.formatter.bullet_list(0))
155 return ''.join(result)