File: make_supported.py

package info (click to toggle)
chirp 1%3A20200227%2Bpy3%2B20200213-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 10,568 kB
  • sloc: python: 95,766; ansic: 296; sh: 184; makefile: 40
file content (178 lines) | stat: -rwxr-xr-x 4,361 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python

import sys
import serial

sys.path.insert(0, ".")
sys.path.insert(0, "..")

tmp = sys.stdout
sys.stdout = sys.stderr
from chirp import *
from chirp.drivers import *
sys.stdout = tmp

RF = chirp_common.RadioFeatures()
KEYS = [x for x in sorted(RF.__dict__.keys())
        if "_" in x and not x.startswith("_")]

RADIO_TYPES = {
    'Clone': chirp_common.CloneModeRadio,
    'File':  chirp_common.FileBackedRadio,
    'Live':  chirp_common.LiveRadio,
}


counter = 0

def radio_type(radio):
    for k, v in RADIO_TYPES.items():
        if isinstance(radio, v):
            return k
    return ""


def supported_row(radio):
    global counter
    counter += 1
    odd = counter % 2

    row = '<tr class="%s" title="%s %s %s">' % (odd and "odd" or "even",
                                                radio.VENDOR,
                                                radio.MODEL,
                                                radio.VARIANT)
    row += "<td><a href=\"#%s\" name=\"%s\">%s %s %s</a></td>\n" % (
        'row%04i' % counter,
        'row%04i' % counter,
        radio.VENDOR, radio.MODEL, radio.VARIANT)
    rf = radio.get_features()
    for key in KEYS:
        value = rf.__dict__[key]
        if key == "valid_bands":
            value = ["%s-%s MHz" % (chirp_common.format_freq(x),
                                    chirp_common.format_freq(y))
                     for x, y in value]

        if key in ["valid_bands", "valid_modes", "valid_power_levels",
                   "valid_tuning_steps"]:
            try:
                value = ", ".join([str(x) for x in value
                                   if not str(x).startswith("?")])
            except Exception, e:
                raise

        if key == "memory_bounds":
            value = "%i-%i" % value

        if key == "requires_call_lists":
            if "DV" not in rf.valid_modes:
                value = None
            elif value:
                value = "Required"
            else:
                value = "Optional"

        if value is None:
            row += '<td class="%s"><span class="False">N/A</span></td>' % key
        elif isinstance(value, bool):
            row += '<td class="%s"><span class="%s">%s</span></td>' % \
                (key,
                 value,
                 value and "Yes" or "No")
        else:
            row += '<td class="%s">%s</td>' % (key, value)
    row += '<td class="radio_type">%s</td>' % radio_type(radio)
    row += "</tr>\n"
    return row


def header_row():
    row = "<thead><tr>"
    row += "<th>Radio</th>\n"
    for key in KEYS:
        Key = key.split("_", 1)[1].title().replace("_", " ")
        row += '<th title="%s">%s</th>' % (RF.get_doc(key), Key)
    row += '<th title="Radio programming type">Type</th>\n'
    row += "</tr></thead>\n"
    return row


dest = sys.stdout
if len(sys.argv) > 1:
    dest = open(sys.argv[1], 'w')


def output(string):
    dest.write(string + '\n')


output("""
<style>
td {
  white-space: nowrap;
  border-right: thin solid black;
  padding: 3px;
}
tr.odd {
  background: #E8E8E8;'
}
tr.odd:hover, tr.even:hover {
  background-color: #FFCCFF;
}
th {
  border-right: thin solid black;
}
table {
  border-collapse: collapse;
}
th {
  border-bottom: thick solid black;
}
span.false {
  color: grey;
}
a {
  text-decoration: none;
  color: inherit;
}
</style>
<table>
""")

models = {"Icom": [],
          "Kenwood": [],
          "Yaesu": [],
          "Alinco": [],
          "Baofeng": [],
          "z_Other": [],
          }

models = []

exclude = [directory.DRV_TO_RADIO["Icom_7200"]]

for radio in directory.DRV_TO_RADIO.values():
    if radio in exclude:
        continue

    models.append(radio)
    for alias in radio.ALIASES:
        class DynamicRadioAlias(radio):
            VENDOR = alias.VENDOR
            MODEL = alias.MODEL
            VARIANT = alias.VARIANT
        models.append(DynamicRadioAlias)


def get_key(rc):
    return '%s %s %s' % (rc.VENDOR, rc.MODEL, rc.VARIANT)

for radio in sorted(models, cmp=lambda a, b: get_key(a) < get_key(b) and -1 or 1):
    if counter % 10 == 0:
        output(header_row())
    _radio = radio(None)
    if _radio.get_features().has_sub_devices:
        for __radio in _radio.get_sub_devices():
            output(supported_row(__radio))
    else:
        output(supported_row(_radio))