From 6fb61e1e3f183c723d53b3ae38c4afccb4621643 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Thu, 12 Nov 2020 15:45:58 +0000 Subject: [PATCH] Reverted logging style --- .pylintrc | 6 +-- openflexure_microscope/api/app.py | 2 +- .../api/default_extensions/__init__.py | 2 +- .../api/default_extensions/autofocus.py | 10 ++--- .../api/default_extensions/autostorage.py | 6 +-- .../recalibrate_utils.py | 10 ++--- .../api/default_extensions/scan.py | 16 ++++---- .../api/default_extensions/zip_builder.py | 2 +- .../api/dev_extensions/tools.py | 2 +- .../api/utilities/__init__.py | 4 +- openflexure_microscope/api/utilities/gui.py | 2 +- .../api/v2/views/actions/stage.py | 4 +- openflexure_microscope/camera/base.py | 4 +- openflexure_microscope/camera/pi.py | 40 +++++++++---------- .../camera/set_picamera_gain.py | 4 +- openflexure_microscope/captures/capture.py | 32 +++++++-------- .../captures/capture_manager.py | 10 ++--- openflexure_microscope/config.py | 12 +++--- openflexure_microscope/microscope.py | 18 ++++----- .../rescue/check_capture_reload.py | 2 +- .../rescue/monitor_timeout.py | 2 +- openflexure_microscope/stage/mock.py | 4 +- openflexure_microscope/stage/sanga.py | 10 ++--- openflexure_microscope/utilities.py | 2 +- 24 files changed, 100 insertions(+), 106 deletions(-) diff --git a/.pylintrc b/.pylintrc index 7dc2c3fe..9aa90314 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,8 +1,4 @@ [MESSAGES CONTROL] disable=fixme,C,R -max-line-length = 88 - -[LOGGING] - -logging-format-style=new \ No newline at end of file +max-line-length = 88 \ No newline at end of file diff --git a/openflexure_microscope/api/app.py b/openflexure_microscope/api/app.py index 998be592..ebb77d19 100644 --- a/openflexure_microscope/api/app.py +++ b/openflexure_microscope/api/app.py @@ -72,7 +72,7 @@ root_log.addHandler(fh) access_log.addHandler(afh) # Log server paths being used -logging.info("Running with data path {}", OPENFLEXURE_VAR_PATH) +logging.info("Running with data path %s", OPENFLEXURE_VAR_PATH) logging.info("Creating app") # Create flask app diff --git a/openflexure_microscope/api/default_extensions/__init__.py b/openflexure_microscope/api/default_extensions/__init__.py index e76733f9..561239af 100644 --- a/openflexure_microscope/api/default_extensions/__init__.py +++ b/openflexure_microscope/api/default_extensions/__init__.py @@ -10,7 +10,7 @@ def handle_extension_error(extension_name): yield except Exception: # pylint: disable=W0703 logging.error( - "Exception loading builtin extension {}: \n{}", + "Exception loading builtin extension %s: \n%s", extension_name, traceback.format_exc(), ) diff --git a/openflexure_microscope/api/default_extensions/autofocus.py b/openflexure_microscope/api/default_extensions/autofocus.py index cc30a908..a9e3f0e4 100644 --- a/openflexure_microscope/api/default_extensions/autofocus.py +++ b/openflexure_microscope/api/default_extensions/autofocus.py @@ -83,7 +83,7 @@ class JPEGSharpnessMonitor: raise e if stop < 1: stop = len(jpeg_times) - logging.debug("changing stop to {}", (stop)) + logging.debug("changing stop to %s", (stop)) jpeg_times = jpeg_times[start:stop] jpeg_zs = np.interp(jpeg_times, stage_times, stage_zs) return jpeg_times, jpeg_zs, jpeg_sizes[start:stop] @@ -258,13 +258,12 @@ def fast_up_down_up_autofocus( # Ensure the MJPEG stream has started microscope.camera.start_stream_recording() - df = dz # TODO: refactor so I actually use dz in the code below! logging.debug("Initial move") if initial_move_up: - m.focus_rel(df / 2) + m.focus_rel(dz / 2) # move down logging.debug("Move down") - i, z = m.focus_rel(-df) + i, z = m.focus_rel(-dz) # now inspect where the sharpest point is, and estimate the sharpness # (JPEG size) that we should find at the start of the Z stack _, jz, js = m.move_data(i) @@ -285,14 +284,13 @@ def fast_up_down_up_autofocus( inow = np.argmax( js < current_js ) # use the curve we recorded to estimate our position - # TODO: fancy interpolation stuff # So, the Z position corresponding to our current sharpness value is zs[inow] # That means we should move forwards, by best_z - zs[inow] logging.debug("Correction move") correction_move = best_z + target_z - jz[inow] logging.debug( - "Fast autofocus scan: correcting backlash by moving {} steps", + "Fast autofocus scan: correcting backlash by moving %s steps", (correction_move), ) m.focus_rel(correction_move) diff --git a/openflexure_microscope/api/default_extensions/autostorage.py b/openflexure_microscope/api/default_extensions/autostorage.py index 8a7c4abe..e54f3aea 100644 --- a/openflexure_microscope/api/default_extensions/autostorage.py +++ b/openflexure_microscope/api/default_extensions/autostorage.py @@ -95,10 +95,10 @@ class AutostorageExtension(BaseExtension): def on_microscope(self, microscope_obj): """Function to automatically call when the parent LabThing has a microscope attached.""" - logging.debug("Autostorage extension found microscope {}", microscope_obj) + logging.debug("Autostorage extension found microscope %s", microscope_obj) if hasattr(microscope_obj, "captures"): logging.debug( - "Autostorage extension bound to CaptureManager {}", self.capture_manager + "Autostorage extension bound to CaptureManager %s", self.capture_manager ) # Store a reference to the CaptureManager @@ -117,7 +117,7 @@ class AutostorageExtension(BaseExtension): # If preferred path does not exist, or cannot be written to if not (os.path.isdir(location) and check_rw(location)): logging.error( - "Preferred capture path {} is missing or cannot be written to. Restoring defaults.", + "Preferred capture path %s is missing or cannot be written to. Restoring defaults.", location, ) # Reset the storage location to default diff --git a/openflexure_microscope/api/default_extensions/picamera_autocalibrate/recalibrate_utils.py b/openflexure_microscope/api/default_extensions/picamera_autocalibrate/recalibrate_utils.py index 6aa70937..fd18cf46 100644 --- a/openflexure_microscope/api/default_extensions/picamera_autocalibrate/recalibrate_utils.py +++ b/openflexure_microscope/api/default_extensions/picamera_autocalibrate/recalibrate_utils.py @@ -63,15 +63,15 @@ def auto_expose_and_freeze_settings(camera): logging.info("Freezing the camera settings...") camera.shutter_speed = camera.exposure_speed - logging.info("Shutter speed = {}", (camera.shutter_speed)) + logging.info("Shutter speed = %s", (camera.shutter_speed)) camera.exposure_mode = "off" logging.info("Auto exposure disabled") g = camera.awb_gains camera.awb_mode = "off" camera.awb_gains = g - logging.info("Auto white balance disabled, gains are {}", (g)) + logging.info("Auto white balance disabled, gains are %s", (g)) logging.info( - "Analogue gain: {}, Digital gain: {}", camera.analog_gain, camera.digital_gain + "Analogue gain: %s, Digital gain: %s", camera.analog_gain, camera.digital_gain ) adjust_exposure_to_setpoint(camera, 215) @@ -98,7 +98,7 @@ def lst_from_channels(channels): # lst_resolution = list(np.ceil(full_resolution / 64.0).astype(int)) lst_resolution = [(r // 64) + 1 for r in full_resolution] # NB the size of the LST is 1/64th of the image, but rounded UP. - logging.info("Generating a lens shading table at {}x{}", *lst_resolution) + logging.info("Generating a lens shading table at %sx%s", *lst_resolution) lens_shading = np.zeros([channels.shape[0]] + lst_resolution, dtype=np.float) for i in range(lens_shading.shape[0]): image_channel = channels[i, :, :] @@ -116,7 +116,7 @@ def lst_from_channels(channels): image_channel, [(0, lw * 32 - iw), (0, lh * 32 - ih)], mode="edge" ) # Pad image to the right and bottom logging.info( - "Channel shape: {}x{}, shading table shape: {}x{}, after padding {}", + "Channel shape: %sx%s, shading table shape: %sx%s, after padding %s", iw, ih, lw * 32, diff --git a/openflexure_microscope/api/default_extensions/scan.py b/openflexure_microscope/api/default_extensions/scan.py index 52b9e0ec..8eeb78bc 100644 --- a/openflexure_microscope/api/default_extensions/scan.py +++ b/openflexure_microscope/api/default_extensions/scan.py @@ -216,7 +216,7 @@ class ScanExtension(BaseExtension): for x_y in line: # Move to new grid position without changing z - logging.debug("Moving to step {}", ([x_y[0], x_y[1], next_z])) + logging.debug("Moving to step %s", ([x_y[0], x_y[1], next_z])) microscope.stage.move_abs([x_y[0], x_y[1], next_z]) # Refocus if autofocus_enabled: @@ -270,11 +270,11 @@ class ScanExtension(BaseExtension): # Make sure we use our current best estimate of focus (i.e. the current position) next point next_z = microscope.stage.position[2] - logging.debug("Returning to {}", (initial_position)) + logging.debug("Returning to %s", (initial_position)) microscope.stage.move_abs(initial_position) end = time.time() - logging.info("Scan took {} seconds", end - start) + logging.info("Scan took %s seconds", end - start) def stack( self, @@ -298,17 +298,17 @@ class ScanExtension(BaseExtension): # Store initial position initial_position = microscope.stage.position - logging.debug("Starting z-stack from position {}", microscope.stage.position) + logging.debug("Starting z-stack from position %s", microscope.stage.position) with microscope.lock: # Move to center scan logging.debug("Moving to z-stack starting position") microscope.stage.move_rel([0, 0, int((-step_size * steps) / 2)]) - logging.debug("Starting scan from position {}", microscope.stage.position) + logging.debug("Starting scan from position %s", microscope.stage.position) for i in range(steps): time.sleep(0.1) - logging.debug("Capturing from position {}", microscope.stage.position) + logging.debug("Capturing from position %s", microscope.stage.position) self.capture( microscope, basename, @@ -328,10 +328,10 @@ class ScanExtension(BaseExtension): return if i != steps - 1: - logging.debug("Moving z by {}", (step_size)) + logging.debug("Moving z by %s", (step_size)) microscope.stage.move_rel([0, 0, step_size]) if return_to_start: - logging.debug("Returning to {}", (initial_position)) + logging.debug("Returning to %s", (initial_position)) microscope.stage.move_abs(initial_position) diff --git a/openflexure_microscope/api/default_extensions/zip_builder.py b/openflexure_microscope/api/default_extensions/zip_builder.py index 9ce774da..5db25a70 100644 --- a/openflexure_microscope/api/default_extensions/zip_builder.py +++ b/openflexure_microscope/api/default_extensions/zip_builder.py @@ -156,7 +156,7 @@ class ZipGetterAPIView(View): if not session_id in default_zip_manager.session_zips: return abort(404) # 404 Not Found - logging.info("Session ID: {}", session_id) + logging.info("Session ID: %s", session_id) return send_file( default_zip_manager.zip_fp_from_id(session_id).name, diff --git a/openflexure_microscope/api/dev_extensions/tools.py b/openflexure_microscope/api/dev_extensions/tools.py index 1f6d12cf..ddbadfef 100644 --- a/openflexure_microscope/api/dev_extensions/tools.py +++ b/openflexure_microscope/api/dev_extensions/tools.py @@ -17,7 +17,7 @@ class SleepFor(ActionView): def post(self, args): sleep_time = args.get("time") - logging.info("Going to sleep for {}...", sleep_time) + logging.info("Going to sleep for %s...", sleep_time) start = time.time() time.sleep(sleep_time) end = time.time() diff --git a/openflexure_microscope/api/utilities/__init__.py b/openflexure_microscope/api/utilities/__init__.py index 333fa767..7c12b2a9 100644 --- a/openflexure_microscope/api/utilities/__init__.py +++ b/openflexure_microscope/api/utilities/__init__.py @@ -73,10 +73,10 @@ def init_default_extensions(extension_dir): default_ext_path = os.path.join(extension_dir, "defaults.py") if not os.path.isfile(default_ext_path): # If user extensions file doesn't exist - logging.warning("No extension file found at {}. Creating...", (extension_dir)) + logging.warning("No extension file found at %s. Creating...", (extension_dir)) create_file(default_ext_path) - logging.info("Populating {}...", (default_ext_path)) + logging.info("Populating %s...", (default_ext_path)) with open(default_ext_path, "w") as outfile: outfile.write(_DEFAULT_EXTENSION_INIT) diff --git a/openflexure_microscope/api/utilities/gui.py b/openflexure_microscope/api/utilities/gui.py index 5613ae69..1fc03c1f 100644 --- a/openflexure_microscope/api/utilities/gui.py +++ b/openflexure_microscope/api/utilities/gui.py @@ -27,7 +27,7 @@ def build_gui_from_dict(gui_description, extension_object): if "route" in form and form["route"] in ext_rules.keys(): form["route"] = ext_rules[form["route"]]["urls"][0] else: - logging.warning("No valid expandable route found for {}", form["route"]) + logging.warning("No valid expandable route found for %s", form["route"]) # Inject extension information api_gui["id"] = extension_object.name diff --git a/openflexure_microscope/api/v2/views/actions/stage.py b/openflexure_microscope/api/v2/views/actions/stage.py index 5c7cc416..80e2a037 100644 --- a/openflexure_microscope/api/v2/views/actions/stage.py +++ b/openflexure_microscope/api/v2/views/actions/stage.py @@ -25,11 +25,11 @@ class MoveStageAPI(ActionView): # Handle absolute positioning (calculate a relative move from current position and target) if (args.get("absolute")) and (microscope.stage): # Only if stage exists target_position = axes_to_array(args, ["x", "y", "z"]) - logging.debug("TARGET: {}", (target_position)) + logging.debug("TARGET: %s", (target_position)) position = [ target_position[i] - microscope.stage.position[i] for i in range(3) ] - logging.debug("DELTA: {}", (position)) + logging.debug("DELTA: %s", (position)) else: # Get coordinates from payload diff --git a/openflexure_microscope/camera/base.py b/openflexure_microscope/camera/base.py index d3bdbefa..dab2b06a 100644 --- a/openflexure_microscope/camera/base.py +++ b/openflexure_microscope/camera/base.py @@ -113,10 +113,10 @@ class BaseCamera(metaclass=ABCMeta): def close(self): """Close the BaseCamera and all attached StreamObjects.""" - logging.info("Closing {}", (self)) + logging.info("Closing %s", (self)) # Stop worker thread self.stop_worker() - logging.info("Closed {}", (self)) + logging.info("Closed %s", (self)) # START AND STOP WORKER THREAD diff --git a/openflexure_microscope/camera/pi.py b/openflexure_microscope/camera/pi.py index d86957d4..4d47e2de 100644 --- a/openflexure_microscope/camera/pi.py +++ b/openflexure_microscope/camera/pi.py @@ -156,10 +156,10 @@ class PiCameraStreamer(BaseCamera): for key in PiCameraStreamer.picamera_settings_keys: try: value = getattr(self.camera, key) - logging.debug("Reading PiCamera().{}: {}", key, value) + logging.debug("Reading PiCamera().%s: %s", key, value) conf_dict["picamera"][key] = value except AttributeError: - logging.debug("Unable to read PiCamera attribute {}", (key)) + logging.debug("Unable to read PiCamera attribute %s", (key)) # Include a serialised lens shading table if ( @@ -243,22 +243,22 @@ class PiCameraStreamer(BaseCamera): # Set exposure mode if "exposure_mode" in settings_dict: logging.debug( - "Applying exposure_mode: {}", (settings_dict["exposure_mode"]) + "Applying exposure_mode: %s", (settings_dict["exposure_mode"]) ) self.camera.exposure_mode = settings_dict["exposure_mode"] # Apply gains and let them settle if "analog_gain" in settings_dict: - logging.debug("Applying analog_gain: {}", (settings_dict["analog_gain"])) + logging.debug("Applying analog_gain: %s", (settings_dict["analog_gain"])) set_analog_gain(self.camera, float(settings_dict["analog_gain"])) if "digital_gain" in settings_dict: - logging.debug("Applying digital_gain: {}", (settings_dict["digital_gain"])) + logging.debug("Applying digital_gain: %s", (settings_dict["digital_gain"])) set_digital_gain(self.camera, float(settings_dict["digital_gain"])) # Apply shutter speed if "shutter_speed" in settings_dict: logging.debug( - "Applying shutter_speed: {}", (settings_dict["shutter_speed"]) + "Applying shutter_speed: %s", (settings_dict["shutter_speed"]) ) self.camera.shutter_speed = int(settings_dict["shutter_speed"]) @@ -268,17 +268,17 @@ class PiCameraStreamer(BaseCamera): if "awb_gains" in settings_dict: logging.debug("Applying awb_mode: off") self.camera.awb_mode = "off" - logging.debug("Applying awb_gains: {}", (settings_dict["awb_gains"])) + logging.debug("Applying awb_gains: %s", (settings_dict["awb_gains"])) self.camera.awb_gains = settings_dict["awb_gains"] elif "awb_mode" in settings_dict: - logging.debug("Applying awb_mode: {}", (settings_dict["awb_mode"])) + logging.debug("Applying awb_mode: %s", (settings_dict["awb_mode"])) self.camera.awb_mode = settings_dict["awb_mode"] # Handle some properties that can be quickly applied batched_keys = ["framerate", "saturation"] for key in batched_keys: if (key in settings_dict) and hasattr(self.camera, key): - logging.debug("Applying {}: {}", key, settings_dict[key]) + logging.debug("Applying %s: %s", key, settings_dict[key]) setattr(self.camera, key, settings_dict[key]) # Final optional pause to settle @@ -303,7 +303,7 @@ class PiCameraStreamer(BaseCamera): for i in range(2): if np.abs(centre[i] - 0.5) + size / 2 > 0.5: centre[i] = 0.5 + (1.0 - size) / 2 * np.sign(centre[i] - 0.5) - logging.info("setting zoom, centre {}, size {}", centre, size) + logging.info("setting zoom, centre %s, size %s", centre, size) new_fov = (centre[0] - size / 2, centre[1] - size / 2, size, size) self.camera.zoom = new_fov @@ -325,11 +325,11 @@ class PiCameraStreamer(BaseCamera): self.preview_active = True except picamerax.exc.PiCameraMMALError as e: logging.error( - "Suppressed a MMALError in start_preview. Exception: {}", (e) + "Suppressed a MMALError in start_preview. Exception: %s", (e) ) except picamerax.exc.PiCameraValueError as e: logging.error( - "Suppressed a ValueError exception in start_preview. Exception: {}", + "Suppressed a ValueError exception in start_preview. Exception: %s", (e), ) @@ -359,7 +359,7 @@ class PiCameraStreamer(BaseCamera): if not self.record_active: # Start the camera video recording on port 2 - logging.info("Recording to {}", (output)) + logging.info("Recording to %s", (output)) self.camera.start_recording( output, @@ -401,17 +401,17 @@ class PiCameraStreamer(BaseCamera): """ for k in kwargs.keys(): logging.warning( - "Warning, kwarg {} is invalid for stop_stream_recording.", k + "Warning, kwarg %s is invalid for stop_stream_recording.", k ) with self.lock: # Stop the camera video recording on port 1 try: self.camera.stop_recording(splitter_port=splitter_port) except picamerax.exc.PiCameraNotRecording: - logging.info("Not recording on splitter_port {}", (splitter_port)) + logging.info("Not recording on splitter_port %s", (splitter_port)) else: logging.info( - "Stopped MJPEG stream on port {}. Switching to {}.", + "Stopped MJPEG stream on port %s. Switching to %s.", splitter_port, self.image_resolution, ) @@ -431,7 +431,7 @@ class PiCameraStreamer(BaseCamera): """ for k in kwargs.keys(): logging.warning( - "Warning, kwarg {} is invalid for stop_stream_recording.", k + "Warning, kwarg %s is invalid for stop_stream_recording.", k ) with self.lock(timeout=None): # Reduce the resolution for video streaming @@ -465,7 +465,7 @@ class PiCameraStreamer(BaseCamera): ) else: logging.debug( - "Started MJPEG stream at {} on port {}", + "Started MJPEG stream at %s on port %s", self.stream_resolution, splitter_port, ) @@ -496,7 +496,7 @@ class PiCameraStreamer(BaseCamera): output_object (str/BytesIO): Target object. """ with self.lock: - logging.info("Capturing to {}", (output)) + logging.info("Capturing to %s", (output)) # Set resolution and stop stream recording if necessary if not use_video_port: @@ -532,7 +532,7 @@ class PiCameraStreamer(BaseCamera): logging.debug("Creating PiRGBArray") with picamerax.array.PiRGBArray(self.camera) as output: - logging.info("Capturing to {}", (output)) + logging.info("Capturing to %s", (output)) self.camera.capture(output, format="rgb", use_video_port=True) diff --git a/openflexure_microscope/camera/set_picamera_gain.py b/openflexure_microscope/camera/set_picamera_gain.py index 3e92b4b9..fc04f851 100644 --- a/openflexure_microscope/camera/set_picamera_gain.py +++ b/openflexure_microscope/camera/set_picamera_gain.py @@ -55,7 +55,7 @@ if __name__ == "__main__": # fix the shutter speed cam.shutter_speed = cam.exposure_speed - logging.info("Current a/d gains: {}, {}", cam.analog_gain, cam.digital_gain) + logging.info("Current a/d gains: %s, %s", cam.analog_gain, cam.digital_gain) logging.info("Attempting to set analogue gain to 1") set_analog_gain(cam, 1) @@ -65,7 +65,7 @@ if __name__ == "__main__": try: while True: logging.info( - "Current a/d gains: {}, {}", cam.analog_gain, cam.digital_gain + "Current a/d gains: %s, %s", cam.analog_gain, cam.digital_gain ) time.sleep(1) except KeyboardInterrupt: diff --git a/openflexure_microscope/captures/capture.py b/openflexure_microscope/captures/capture.py index 131f84ef..36d252b4 100644 --- a/openflexure_microscope/captures/capture.py +++ b/openflexure_microscope/captures/capture.py @@ -25,23 +25,23 @@ def make_file_list(directory, formats): glob.glob("{}/**/*.{}".format(directory, fmt.lower()), recursive=True) ) - logging.info("{} capture files found on disk", (len(files))) + logging.info("%s capture files found on disk", (len(files))) return files def build_captures_from_exif(capture_path): - logging.debug("Reloading captures from {}...", (capture_path)) + logging.debug("Reloading captures from %s...", (capture_path)) files = make_file_list(capture_path, EXIF_FORMATS) captures = OrderedDict() for f in files: - logging.debug("Reloading capture {}...", (f)) + logging.debug("Reloading capture %s...", (f)) capture = capture_from_path(f) if capture: captures[capture.id] = capture - logging.info("{} capture files successfully reloaded", (len(captures))) + logging.info("%s capture files successfully reloaded", (len(captures))) return captures @@ -58,7 +58,7 @@ def capture_from_path(path): capture.sync_basic_metadata() return capture except (InvalidImageDataError, json.decoder.JSONDecodeError): - logging.error("Invalid metadata at {}.", (path)) + logging.error("Invalid metadata at %s.", (path)) return None @@ -75,7 +75,7 @@ class CaptureObject(object): # Store a nice ID self.id = uuid.uuid4() #: str: Unique capture ID - logging.debug("Created CaptureObject {}", (self.id)) + logging.debug("Created CaptureObject %s", (self.id)) self.time = datetime.datetime.now() @@ -97,17 +97,17 @@ class CaptureObject(object): self.tags = [] def write(self, s): - logging.debug("Writing to {}", self) + logging.debug("Writing to %s", self) self.stream.write(s) def flush(self): - logging.info("Writing image data to disk {}", self.file) + logging.info("Writing image data to disk %s", self.file) with open(self.file, "wb") as outfile: outfile.write(self.stream.getbuffer()) self.stream.close() - logging.info("Writing metadata to disk {}", self.file) + logging.info("Writing metadata to disk %s", self.file) self._init_metadata() - logging.info("Finished writing to disk {}", self.file) + logging.info("Finished writing to disk %s", self.file) def open(self, mode): return open(self.file, mode) @@ -175,7 +175,7 @@ class CaptureObject(object): } def read_full_metadata(self): - logging.info("Reading full capture metadata from {}...", self.file) + logging.info("Reading full capture metadata from %s...", self.file) exif_dict = self._read_exif() return self._decode_usercomment(exif_dict) @@ -271,7 +271,7 @@ class CaptureObject(object): # Write new data to file EXIF, if supported if self.format.upper() in EXIF_FORMATS and self.exists: - logging.info("Writing Exif data to {}", self.file) + logging.info("Writing Exif data to %s", self.file) # Extract current Exif data exif_dict = self._read_exif() @@ -286,7 +286,7 @@ class CaptureObject(object): # Serialize metadata metadata_string = json.dumps(metadata_dict, cls=JSONEncoder) - logging.debug("Saving metadata string to file: {}", metadata_string) + logging.debug("Saving metadata string to file: %s", metadata_string) # Insert metadata into exif_dict exif_dict["Exif"][piexif.ExifIFD.UserComment] = metadata_string.encode() @@ -296,7 +296,7 @@ class CaptureObject(object): # Insert exif into file piexif.insert(exif_bytes, self.file) - logging.info("Finished writing Exif data to {}", self.file) + logging.info("Finished writing Exif data to %s", self.file) # PROPERTIES @@ -316,7 +316,7 @@ class CaptureObject(object): """ if self.exists: # If data file exists - logging.info("Opening from file {}", (self.file)) + logging.info("Opening from file %s", (self.file)) with open(self.file, "rb") as f: d = io.BytesIO(f.read()) # Load bytes from file d.seek(0) # Rewind loaded bytestream @@ -364,7 +364,7 @@ class CaptureObject(object): """If the StreamObject has been saved, delete the file.""" if os.path.isfile(self.file): - logging.info("Deleting file {}", (self.file)) + logging.info("Deleting file %s", (self.file)) os.remove(self.file) return True diff --git a/openflexure_microscope/captures/capture_manager.py b/openflexure_microscope/captures/capture_manager.py index 4b435016..98cc1dde 100644 --- a/openflexure_microscope/captures/capture_manager.py +++ b/openflexure_microscope/captures/capture_manager.py @@ -61,7 +61,7 @@ class CaptureManager: self.close() def close(self): - logging.info("Closing {}", (self)) + logging.info("Closing %s", (self)) # Close all StreamObjects for capture_list in [self.images.values(), self.videos.values()]: for stream_object in capture_list: @@ -75,9 +75,9 @@ class CaptureManager: """ if os.path.isdir(self.paths["temp"]): - logging.info("Clearing {}...", (self.paths["temp"])) + logging.info("Clearing %s...", (self.paths["temp"])) shutil.rmtree(self.paths["temp"]) - logging.debug("Cleared {}.", (self.paths["temp"])) + logging.debug("Cleared %s.", (self.paths["temp"])) def rebuild_captures(self): self.images = build_captures_from_exif(self.paths["default"]) @@ -158,7 +158,7 @@ class CaptureManager: # Update capture list capture_key = str(output.id) - logging.debug("Adding image {} with key {}", output, capture_key) + logging.debug("Adding image %s with key %s", output, capture_key) self.images[capture_key] = output @@ -205,7 +205,7 @@ class CaptureManager: # Update capture list capture_key = str(output.id) - logging.debug("Adding video {} with key {}", output, capture_key) + logging.debug("Adding video %s with key %s", output, capture_key) self.videos[capture_key] = output return output diff --git a/openflexure_microscope/config.py b/openflexure_microscope/config.py index f13cab2c..5788a385 100644 --- a/openflexure_microscope/config.py +++ b/openflexure_microscope/config.py @@ -86,7 +86,7 @@ def load_json_file(config_path) -> dict: """ config_path = os.path.expanduser(config_path) - logging.info("Loading {}...", config_path) + logging.info("Loading %s...", config_path) with open(config_path) as config_file: try: @@ -109,7 +109,7 @@ def save_json_file(config_path: str, config_dict: dict): """ config_path = os.path.expanduser(config_path) - logging.info("Saving {}...", config_path) + logging.info("Saving %s...", config_path) logging.debug(config_dict) with open(config_path, "w") as outfile: @@ -142,14 +142,14 @@ def initialise_file(config_path, populate: str = "{}\n"): """ config_path = os.path.expanduser(config_path) - logging.debug("Initialising {}", (config_path)) - logging.debug("Exists: {}", (os.path.exists(config_path))) + logging.debug("Initialising %s", (config_path)) + logging.debug("Exists: %s", (os.path.exists(config_path))) if not os.path.exists(config_path): # If user config file doesn't exist - logging.warning("No config file found at {}. Creating...", (config_path)) + logging.warning("No config file found at %s. Creating...", (config_path)) create_file(config_path) - logging.info("Populating {}...", (config_path)) + logging.info("Populating %s...", (config_path)) with open(config_path, "w") as outfile: outfile.write(populate) diff --git a/openflexure_microscope/microscope.py b/openflexure_microscope/microscope.py index bfb22ae1..46e63e28 100644 --- a/openflexure_microscope/microscope.py +++ b/openflexure_microscope/microscope.py @@ -71,7 +71,7 @@ class Microscope: def close(self): """Shut down the microscope hardware.""" - logging.info("Closing {}", (self)) + logging.info("Closing %s", (self)) if self.camera: try: self.camera.close() @@ -83,7 +83,7 @@ class Microscope: except TimeoutError as e: logging.error(e) self.captures.close() - logging.info("Closed {}", (self)) + logging.info("Closed %s", (self)) def setup(self, configuration): """ @@ -196,7 +196,7 @@ class Microscope: Applies a settings dictionary to the microscope. Missing parameters will be left untouched. """ with self.lock: - logging.debug("Microscope: Applying settings: {}", (settings)) + logging.debug("Microscope: Applying settings: %s", (settings)) # If attached to a camera if ("camera" in settings) and self.camera: @@ -329,14 +329,14 @@ class Microscope: # Load cached bits of metadata if cache_key: - logging.debug("Reading cached microscope metadata: {}", cache_key) + logging.debug("Reading cached microscope metadata: %s", cache_key) metadata = self.metadata_cache.get(cache_key, None) if not metadata: - logging.debug("Building and caching microscope metadata: {}", cache_key) + logging.debug("Building and caching microscope metadata: %s", cache_key) metadata = self.force_get_metadata() self.metadata_cache[cache_key] = metadata else: - logging.debug("Building microscope metadata: {}", cache_key) + logging.debug("Building microscope metadata: %s", cache_key) metadata = self.force_get_metadata() # Keys that should never be cached @@ -362,7 +362,7 @@ class Microscope: metadata: dict = None, cache_key: str = None, ): - logging.debug("Microscope capturing to {}", filename) + logging.debug("Microscope capturing to %s", filename) if not annotations: annotations = {} if not metadata: @@ -384,7 +384,7 @@ class Microscope: extras = {} if fmt == "jpeg": extras["thumbnail"] = (*THUMBNAIL_SIZE, 85) - logging.info("Starting microscope capture {}", output.file) + logging.info("Starting microscope capture %s", output.file) self.camera.capture( output, use_video_port=use_video_port, @@ -395,6 +395,6 @@ class Microscope: ) output.put_and_save(tags, annotations, full_metadata) - logging.debug("Finished capture to {}", output.file) + logging.debug("Finished capture to %s", output.file) return output diff --git a/openflexure_microscope/rescue/check_capture_reload.py b/openflexure_microscope/rescue/check_capture_reload.py index 843bc3c2..e50ae05b 100644 --- a/openflexure_microscope/rescue/check_capture_reload.py +++ b/openflexure_microscope/rescue/check_capture_reload.py @@ -27,7 +27,7 @@ def main(): logging.info("Loading user settings...") settings = user_settings.load() cap_path = str(settings.get("captures", {}).get("paths", {}).get("default")) - logging.info("Capture path found: {}", cap_path) + logging.info("Capture path found: %s", cap_path) if not cap_path: logging.error( diff --git a/openflexure_microscope/rescue/monitor_timeout.py b/openflexure_microscope/rescue/monitor_timeout.py index 879f6063..49af1169 100644 --- a/openflexure_microscope/rescue/monitor_timeout.py +++ b/openflexure_microscope/rescue/monitor_timeout.py @@ -24,7 +24,7 @@ def launch_timeout_test_process(target, args=(), kwargs=None, timeout=10): # If thread is still active if p.is_alive(): logging.error( - "Function {} reached timeout after {} seconds. Terminating.", + "Function %s reached timeout after %s seconds. Terminating.", target, timeout, ) diff --git a/openflexure_microscope/stage/mock.py b/openflexure_microscope/stage/mock.py index 6d6dd856..9e9eb20f 100644 --- a/openflexure_microscope/stage/mock.py +++ b/openflexure_microscope/stage/mock.py @@ -80,13 +80,13 @@ class MissingStage(BaseStage): self._position = list(np.array(self._position) + np.array(initial_move)) logging.debug(np.array(self._position) + np.array(initial_move)) - logging.debug("New position: {}", self._position) + logging.debug("New position: %s", self._position) def move_abs(self, final, **kwargs): time.sleep(0.5) self._position = list(final) - logging.debug("New position: {}", self._position) + logging.debug("New position: %s", self._position) def zero_position(self): """Set the current position to zero""" diff --git a/openflexure_microscope/stage/sanga.py b/openflexure_microscope/stage/sanga.py index 3389d83d..c3a6c939 100644 --- a/openflexure_microscope/stage/sanga.py +++ b/openflexure_microscope/stage/sanga.py @@ -81,7 +81,7 @@ class SangaStage(BaseStage): @backlash.setter def backlash(self, blsh): - logging.debug("Setting backlash to {}", (blsh)) + logging.debug("Setting backlash to %s", (blsh)) if blsh is None: self._backlash = None elif isinstance(blsh, Iterable): @@ -118,7 +118,7 @@ class SangaStage(BaseStage): backlash: (default: True) whether to correct for backlash. """ with self.lock: - logging.debug("Moving sangaboard by {}", displacement) + logging.debug("Moving sangaboard by %s", displacement) if not backlash or self.backlash is None: return self.board.move_rel(displacement, axis=axis) if axis is not None: @@ -158,7 +158,7 @@ class SangaStage(BaseStage): """Make an absolute move to a position """ with self.lock: - logging.debug("Moving sangaboard to {}", final) + logging.debug("Moving sangaboard to %s", final) self.board.move_abs(final, **kwargs) # Settle outside of the stage lock so that another move request # can just take over before settling @@ -262,7 +262,7 @@ class SangaDeltaStage(SangaStage): # Transform into delta coordinates displacement = np.dot(self.Tdv, displacement) - logging.debug("Delta displacement: {}", (displacement)) + logging.debug("Delta displacement: %s", (displacement)) # Do the move SangaStage.move_rel(self, displacement, axis=None, backlash=backlash) @@ -274,7 +274,7 @@ class SangaDeltaStage(SangaStage): # Transform into delta coordinates final = np.dot(self.Tdv, final) - logging.debug("Delta final: {}", (final)) + logging.debug("Delta final: %s", (final)) # Do the move SangaStage.move_abs(self, final, **kwargs) diff --git a/openflexure_microscope/utilities.py b/openflexure_microscope/utilities.py index 4ded53c7..e0756303 100644 --- a/openflexure_microscope/utilities.py +++ b/openflexure_microscope/utilities.py @@ -22,7 +22,7 @@ class Timer(object): def __exit__(self, type_, value, traceback): self.end = time.time() - logging.debug("{} time: {}", self.name, self.end - self.start) + logging.debug("%s time: %s", self.name, self.end - self.start) def deserialise_array_b64(b64_string, dtype, shape):