Skip to content

Commit ba0ce75

Browse files
committed
updated apps to pass logger to connection
1 parent 5c53925 commit ba0ce75

File tree

11 files changed

+29
-97
lines changed

11 files changed

+29
-97
lines changed

src/instrumentman/datatransfer/app.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ def main_download(
2020
) -> None:
2121
eof_bytes = eof.encode("ascii")
2222
logger = getLogger("iman.data.download")
23-
logger.info(f"Opening connection on {port}")
24-
logger.debug(f"Connection parameters: baud={baud:d}, timeout={timeout:d}")
2523
with open_serial(
2624
port,
2725
speed=baud,
28-
timeout=timeout
26+
timeout=timeout,
27+
logger=logger.getChild("com")
2928
) as com:
3029
eol_bytes = com.eombytes
3130
started = False
@@ -65,8 +64,6 @@ def main_download(
6564
logger.exception("Download interrupted by error")
6665
break
6766

68-
logger.info(f"Closed connection on {port}")
69-
7067

7168
def main_upload(
7269
port: str,
@@ -76,12 +73,11 @@ def main_upload(
7673
skip: int = 0
7774
) -> None:
7875
logger = getLogger("iman.data.upload")
79-
logger.info(f"Opening connection on {port}")
80-
logger.debug(f"Connection parameters: baud={baud:d}, timeout={timeout:d}")
8176
with open_serial(
8277
port,
8378
speed=baud,
84-
timeout=timeout
79+
timeout=timeout,
80+
logger=logger.getChild("com")
8581
) as com:
8682
try:
8783
logger.info("Starting data upload")
@@ -104,5 +100,4 @@ def main_upload(
104100
logger.exception("Upload interrupted by error")
105101
else:
106102
echo_green("Upload finished")
107-
108-
logger.info(f"Closed connection on {port}")
103+
logger.info("Upload finished")

src/instrumentman/filetransfer/app.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def run_listing_tree(
202202
filetype: str | None,
203203
depth: int = 1
204204
) -> None:
205+
filetype = filetype or "unknown"
205206
console = Console(width=120)
206207
logger.info(
207208
f"Starting content listing of '{directory}' from '{dev}' device"
@@ -310,17 +311,13 @@ def main_download(
310311
large: bool = False
311312
) -> None:
312313
logger = getLogger("iman.files.download")
313-
logger.info(f"Starting connection on {port}")
314-
logger.debug(
315-
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
316-
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
317-
)
318314
with open_serial(
319315
port=port,
320316
speed=baud,
321317
timeout=timeout,
322318
retry=retry,
323-
sync_after_timeout=sync_after_timeout
319+
sync_after_timeout=sync_after_timeout,
320+
logger=logger.getChild("com")
324321
) as com:
325322
tps = GeoCom(com, logger.getChild("instrument"))
326323
try:
@@ -337,8 +334,6 @@ def main_download(
337334
finally:
338335
tps.ftr.abort_download()
339336

340-
logger.info(f"Closed connection on {port}")
341-
342337

343338
def main_list(
344339
port: str,
@@ -352,17 +347,13 @@ def main_list(
352347
depth: int = 1
353348
) -> None:
354349
logger = getLogger("iman.files.list")
355-
logger.info(f"Opening connection on {port}")
356-
logger.debug(
357-
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
358-
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
359-
)
360350
with open_serial(
361351
port=port,
362352
speed=baud,
363353
timeout=timeout,
364354
retry=retry,
365-
sync_after_timeout=sync_after_timeout
355+
sync_after_timeout=sync_after_timeout,
356+
logger=logger.getChild("com")
366357
) as com:
367358
tps = GeoCom(com, logger.getChild("instrument"))
368359
try:
@@ -376,5 +367,3 @@ def main_list(
376367
)
377368
finally:
378369
tps.ftr.abort_listing()
379-
380-
logger.info(f"Closed connection on {port}")

src/instrumentman/inclination/app.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,13 @@ def main_measure(
114114
) -> None:
115115
logger = getLogger("iman.inclination.measure")
116116
logger.info(f"Opening connection on {port}")
117-
logger.debug(
118-
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
119-
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
120-
)
121117
with open_serial(
122118
port,
123119
retry=retry,
124120
sync_after_timeout=sync_after_timeout,
125121
speed=baud,
126-
timeout=timeout
122+
timeout=timeout,
123+
logger=logger.getChild("com")
127124
) as com:
128125
tps = GeoCom(com, logger.getChild("instrument"))
129126
run_measure(
@@ -135,8 +132,6 @@ def main_measure(
135132
cycles
136133
)
137134

138-
logger.info(f"Closed connection on {port}")
139-
140135

141136
def main_merge(
142137
inputs: list[TextIOWrapper],

src/instrumentman/jobs/app.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,16 @@ def main_list(
6666
sync_after_timeout: bool = False
6767
) -> None:
6868
logger = getLogger("iman.jobs.list")
69-
logger.info(f"Opening connection on {port}")
70-
logger.debug(
71-
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
72-
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
73-
)
7469
with open_serial(
7570
port=port,
7671
speed=baud,
7772
timeout=timeout,
7873
retry=retry,
79-
sync_after_timeout=sync_after_timeout
74+
sync_after_timeout=sync_after_timeout,
75+
logger=logger.getChild("com")
8076
) as com:
8177
tps = GeoCom(com, logger.getChild("instrument"))
8278
try:
8379
run_listing(tps, logger)
8480
finally:
8581
tps.csv.abort_listing()
86-
87-
logger.info(f"Closed connection on {port}")

src/instrumentman/morse/app.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,13 @@ def main(
146146
logger.critical("Message contains non-ASCII characters.")
147147
exit(1)
148148

149-
logger.info(f"Opening connection on {port}")
150-
logger.debug(
151-
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
152-
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
153-
)
154149
with open_serial(
155150
port,
156151
speed=baud,
157152
timeout=timeout,
158153
retry=retry,
159-
sync_after_timeout=sync_after_timeout
154+
sync_after_timeout=sync_after_timeout,
155+
logger=logger.getChild("com")
160156
) as com:
161157
tps = GeoCom(com, logger.getChild("instrument"))
162158
beepstart = tps.bmm.beep_start
@@ -176,5 +172,3 @@ def main(
176172
message,
177173
unittime * 1e-3
178174
)
179-
180-
logger.info(f"Closed connection on {port}")

src/instrumentman/protocoltest/app.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,14 @@ def main(
153153
sync_after_timeout: bool = False
154154
) -> None:
155155
logger = getLogger("iman.protocoltest")
156-
logger.info(f"Opening connection on {port}")
157-
logger.debug(
158-
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
159-
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
160-
)
161156
try:
162157
with open_serial(
163158
port,
164159
speed=baud,
165160
timeout=timeout,
166161
retry=retry,
167-
sync_after_timeout=sync_after_timeout
162+
sync_after_timeout=sync_after_timeout,
163+
logger=logger.getChild("com")
168164
) as com:
169165
try:
170166
if protocol == "geocom":
@@ -182,5 +178,3 @@ def main(
182178
except (SerialException, ConnectionError) as e:
183179
echo_red(f"Connection was not successful ({e})")
184180
logger.exception("Connection was not successful")
185-
186-
logger.info(f"Closed connection on {port}")

src/instrumentman/setmeasurement/measure.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ def measure_set(
168168

169169
logger.info("Finished set measurements")
170170
progress.stop()
171-
tps.aut.turn_to(0, Angle(180, 'deg'))
172171
logger.info("Returning to face-down position")
172+
tps.aut.turn_to(0, Angle(180, 'deg'))
173173

174174
return session
175175

@@ -189,17 +189,13 @@ def main(
189189
points: str = ""
190190
) -> None:
191191
logger = getLogger("iman.sets.measure")
192-
logger.info(f"Opening connection on {port}")
193-
logger.debug(
194-
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
195-
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
196-
)
197192
with open_serial(
198193
port,
199194
retry=retry,
200195
sync_after_timeout=sync_after_timeout,
201196
speed=baud,
202-
timeout=timeout
197+
timeout=timeout,
198+
logger=logger.getChild("com")
203199
) as com:
204200
tps = GeoCom(com, logger.getChild("instrument"))
205201
if sync_time:
@@ -215,8 +211,6 @@ def main(
215211
points
216212
)
217213

218-
logger.info(f"Closed connection on {port}")
219-
220214
timestamp = session.cycles[0].time.strftime("%Y%m%d_%H%M%S")
221215
filename = os.path.join(
222216
directory,

src/instrumentman/settings/load.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,13 @@ def main(
135135
logger.critical("Settings file does not follow schema")
136136
exit(1)
137137

138-
logger.info(f"Opening connection on {port}")
139-
logger.debug(
140-
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
141-
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
142-
)
143138
with open_serial(
144139
port,
145140
retry=retry,
146141
sync_after_timeout=sync_after_timeout,
147142
speed=baud,
148-
timeout=timeout
143+
timeout=timeout,
144+
logger=logger.getChild("com")
149145
) as com:
150146
match data["protocol"]:
151147
case "geocom":
@@ -156,4 +152,3 @@ def main(
156152
upload_settings_gsidna(dna, logger, data)
157153

158154
echo_green(f"Settings loaded from {settings}")
159-
logger.info(f"Closed connection on {port}")

src/instrumentman/settings/save.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,13 @@ def main(
270270
defaults: bool = False
271271
) -> None:
272272
logger = getLogger("iman.settings.save")
273-
logger.info(f"Opening connection on {port}")
274-
logger.debug(
275-
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
276-
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
277-
)
278273
with open_serial(
279274
port,
280275
retry=retry,
281276
sync_after_timeout=sync_after_timeout,
282277
speed=baud,
283-
timeout=timeout
278+
timeout=timeout,
279+
logger=logger.getChild("com")
284280
) as com:
285281
match protocol:
286282
case "geocom":
@@ -290,8 +286,6 @@ def main(
290286
dna = GsiOnlineDNA(com, logger.getChild("instrument"))
291287
data = download_settings_gsidna(dna, logger, defaults)
292288

293-
logger.info(f"Closed connection on {port}")
294-
295289
data = clean_settings(data)
296290
logger.info("Removed empty options")
297291

src/instrumentman/setup/app.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,13 @@ def main_measure(
166166
sync_after_timeout: bool = False
167167
) -> None:
168168
logger = getLogger("iman.targets.measure")
169-
logger.info(f"Opening connection on {port}")
170-
logger.debug(
171-
f"Connection parameters: baud={baud:d}, timeout={timeout:d}, "
172-
f"tries={retry:d}, sync-after-timeout={str(sync_after_timeout)}"
173-
)
174169
with open_serial(
175170
port,
176171
retry=retry,
177172
sync_after_timeout=sync_after_timeout,
178173
speed=baud,
179-
timeout=timeout
174+
timeout=timeout,
175+
logger=logger.getChild("com")
180176
) as com:
181177
tps = GeoCom(com, logger.getChild("instrument"))
182178
targets = measure_targets(tps, logger, output)
@@ -185,8 +181,6 @@ def main_measure(
185181
logger.info("Program was cancelled or no targets were recorded")
186182
exit(0)
187183

188-
logger.info(f"Closed connection on {port}")
189-
190184
if targets is not None:
191185
export_targets_to_json(output, targets)
192186
echo_green(f"Saved target results to '{output}'")

0 commit comments

Comments
 (0)