Skip to content

Commit

Permalink
possible fix for filefinder ('find')
Browse files Browse the repository at this point in the history
  • Loading branch information
jepegit committed Dec 8, 2023
1 parent 0ec1f27 commit a05cca5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cellpy/readers/filefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import pathlib
import sys
import time
from typing import Optional, Union, List, Tuple
import warnings
Expand Down Expand Up @@ -91,18 +92,28 @@ def find_in_raw_file_directory(
glob_txt = f"{glob_txt}{extension}"
else:
glob_txt = f"{glob_txt}.{extension}"

platform = sys.platform
logging.info(f"Searching for files matching: {glob_txt}")
for d in raw_file_dir:
connect_kwargs, host = d.connection_info()
with fabric.Connection(host, connect_kwargs=connect_kwargs) as conn:
out = conn.run(f'find -L {d.raw_path} -name "{glob_txt}"', hide="both", warn=True)
if out.return_code != 0:
warnings.warn(f"Could not find any files in {d.raw_path} -> {out.stderr}")
warnings.warn(f"Most likely the OS does not have the 'find' command")
continue
_file_list = out.stdout.splitlines()
if not host and platform == "win32":
logging.info("Windows platform detected - assuming 'find' is not available")
_file_list = glob.glob(f"{d.raw_path}/**/{glob_txt}", recursive=True)
f = _file_list[0]
else:
with fabric.Connection(host, connect_kwargs=connect_kwargs) as conn:
out = conn.run(f'find -L {d.raw_path} -name "{glob_txt}"', hide="both", warn=True)
if out.return_code != 0:
logging.critical(f"Searching in: {d}")
warnings.warn(f"Could not find any files in {d.raw_path} -> {out.stderr}")
warnings.warn(f"Most likely the OS does not have the 'find' command")
continue
_file_list = out.stdout.splitlines()
file_list += list(map(lambda x: f"{d.uri_prefix}{host}"+x, _file_list))
number_of_files = len(file_list)
if number_of_files == 0:
logging.critical("No files found")
logging.info(f"Found {number_of_files} files")
return file_list

Expand Down
32 changes: 32 additions & 0 deletions cellpy/utils/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,38 @@ def combine_summaries(self, export_to_csv=True, **kwargs) -> None:
else:
self.summary_collector.do(**kwargs)

def plot(self, output_filename=None, backend=None, reload_data=False, **kwargs):
"""Plot the summaries (new version)"""

if reload_data or ("summary_engine" not in self.experiment.memory_dumped):
logging.debug("running summary_collector")
self.summary_collector.do(reset=True)

if backend is None:
backend = prms.Batch.backend

if backend in ["bokeh", "matplotlib", "plotly"]:
prms.Batch.backend = backend

if backend == "bokeh":
print("...Using old plotter - this will soon change")
self.plot_summaries(
output_filename=output_filename,
backend="bokeh",
reload_data=reload_data,
**kwargs)

if backend == "matplotlib":
print("...Using old plotter - this will soon change")
self.plot_summaries(
output_filename=output_filename,
backend="matplotlib",
reload_data=reload_data,
**kwargs)

else:
print(f"backend {backend} not supported yet")

def plot_summaries(
self, output_filename=None, backend=None, reload_data=False, **kwargs
) -> None:
Expand Down

0 comments on commit a05cca5

Please sign in to comment.