1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 """
21 Dive computer related Kenozooid command line commands.
22 """
23
24 import logging
25
26 from kenozooid.component import inject
27 from kenozooid.cli import CLICommand, ArgumentError, add_master_command, \
28 add_uddf_input
29 from kenozooid.component import query, params
30 from kenozooid.driver import DeviceDriver, Simulator, DataParser
31
32 log = logging.getLogger('kenozooid.cli.dc')
33
34
35 add_master_command('sim',
36 'Kenozooid dive simulation commands',
37 'simulate dives with a dive computer')
41 """
42 Command to list dive computers drivers.
43 """
44 description = 'list available dive computer drivers and their capabilities'
45
46 @classmethod
48 """
49 No arguments for drivers listing.
50 """
51
52
54 """
55 Execute drivers listing command.
56 """
57 drivers = query(DeviceDriver)
58 print('Available drivers:\n')
59 for cls in drivers:
60 p = params(cls)
61 id = p['id']
62 name = p['name']
63 drivers = query(id=id)
64
65
66 caps = []
67 if len(tuple(query(Simulator, id=id))) > 0:
68 caps.append('simulation')
69 if len(tuple(query(DataParser, id=id))) > 0:
70 caps.append('backup')
71
72
73
74
75 print('%s (%s): %s' % (id, name, ', '.join(caps)))
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 @inject(CLICommand, name='sim plan')
95 -class Simulate(object):
96 """
97 Simulate dive on a dive computer.
98 """
99 description = 'simulate dive with a dive computer'
100
101 @classmethod
103 """
104 Add dive computer dive simulation arguments.
105 """
106 parser.add_argument('--no-start',
107 action='store_false',
108 dest='sim_start',
109 default=True,
110 help='assume simulation is started, don\'t start simulation')
111 parser.add_argument('--no-stop',
112 action='store_false',
113 dest='sim_stop',
114 default=True,
115 help='don\'t stop simulation, leave dive computer in simulation mode')
116 parser.add_argument('driver',
117 nargs=1,
118 help='device driver id')
119 parser.add_argument('port',
120 nargs=1,
121 help='device port, i.e. /dev/ttyUSB0, COM1')
122 parser.add_argument('plan',
123 nargs=1,
124 help='dive plan')
125
126
146
151 """
152 Replay dive profile on a dive computer.
153 """
154 description = 'replay dive on a dive computer'
155
156 @classmethod
158 """
159 Add dive computer dive replay arguments.
160 """
161 parser.add_argument('driver',
162 help='device driver id')
163 parser.add_argument('port',
164 help='device port, i.e. /dev/ttyUSB0, COM1')
165 add_uddf_input(parser)
166
167
190
195 """
196 Dive computer data backup Kenozooid command.
197 """
198 description = 'backup dive computer data (logbook, settings, etc.)'
199
200 @classmethod
202 """
203 Add arguments for dive computer data backup command.
204 """
205 parser.add_argument('driver',
206 help='device driver id')
207 parser.add_argument('port',
208 help='device port, i.e. /dev/ttyUSB0, COM1')
209 parser.add_argument('output',
210 help='UDDF file to contain dive computer backup')
211
212
214 """
215 Execute dive computer data backup command.
216 """
217 import kenozooid.dc as kd
218
219 drv_name = args.driver
220 port = args.port
221 fout = args.output
222
223 kd.backup(drv_name, port, fout)
224
229 """
230 Extract dive profiles from dive computer dump (binary) data.
231 """
232 description = 'extract dives from dive computer backup'
233
234 @classmethod
236 """
237 Add options for dive extract command.
238 """
239 parser.add_argument('input',
240 help='UDDF file with dive computer dump data')
241 parser.add_argument('output',
242 help='output UDDF file')
243
244
246 """
247 Execute dive extract command.
248 """
249 import kenozooid.dc as kd
250
251 fin = args.input
252 fout = args.output
253 log.debug('extracting dive profiles from {} (saving to {})' \
254 .format(fin, fout))
255 kd.extract_dives(fin, fout)
256
261 """
262 Command to store binary dive computer data in UDDF file.
263 """
264 description = 'store binary dive computer data in UDDF file'
265
266 @classmethod
268 """
269 Add arguments for dive computer data conversion command.
270 """
271 parser.add_argument('driver',
272 help='device driver id')
273 parser.add_argument('input',
274 help='dive computer binary data')
275 parser.add_argument('output',
276 help='UDDF file to contain dive computer backup')
277
278
280 """
281 Execute dive computer data conversion command.
282 """
283 import kenozooid.dc as kd
284
285 drv_name = args.driver
286 fin = args.input
287 fout = args.output
288
289 kd.convert(drv_name, fin, fout)
290
291
292
293