Skip to content

Commit 4f81a8d

Browse files
committed
update to ScanPaths
1 parent 9739b39 commit 4f81a8d

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed
Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
"""
2-
Functions for opening file explorer on the given folders. TODO make a Mac-compatible version if needed (or throw error)
2+
Functions for opening file explorer on the given folders.
3+
4+
TODO make a Mac-compatible version if needed (or throw error)
35
"""
6+
47
from typing import Optional
58
import re
69
import subprocess
710
import configparser
811
from pathlib import Path
9-
from geecs_data_utils import ScanData
12+
from geecs_data_utils import ScanPaths
13+
1014

1115
def open_folder(path_to_folder: Path):
12-
""" Opens Windows file explorer to the specified location """
16+
"""Open Windows file explorer to the specified location."""
1317
subprocess.Popen(f'explorer "{path_to_folder}"')
1418

1519

1620
def open_daily_data_folder(experiment: str):
17-
""" Uses ScanData to find the server's save data location for today, and opens in Windows file explorer """
18-
latest = ScanData.get_daily_scan_folder(experiment=experiment)
21+
"""Use ScanData to find the server's save data location for today, and opens in Windows file explorer."""
22+
latest = ScanPaths.get_daily_scan_folder(experiment=experiment)
1923
latest.mkdir(parents=True, exist_ok=True)
2024
open_folder(path_to_folder=latest)
2125

2226

2327
def iterate_scan_numbers(scan_folder: Path):
24-
"""
25-
:param scan_folder: Daily scan folder path
26-
:return: a generated list of scan numbers within the folder
27-
"""
28-
pattern = re.compile(r'^Scan(\d+)$')
28+
"""Iteraate scan numbers."""
29+
pattern = re.compile(r"^Scan(\d+)$")
2930
if not scan_folder.exists():
3031
return
3132
for p in scan_folder.iterdir():
@@ -34,38 +35,34 @@ def iterate_scan_numbers(scan_folder: Path):
3435

3536

3637
def get_latest_scan_number(experiment: str) -> int:
37-
""" Finds the latest scan number using regular expressions rather than iterating through ScanData scan tags
38+
"""Find the latest scan number using regular expressions rather than iterating through ScanData scan tags.
3839
39-
:return: int for latest scan number, 0 if no scans that day
40+
Return: int
41+
Latest scan number, 0 if no scans that day.
4042
"""
41-
scan_folder = ScanData.get_daily_scan_folder(experiment=experiment)
43+
scan_folder = ScanPaths.get_daily_scan_folder(experiment=experiment)
4244
return max(iterate_scan_numbers(scan_folder), default=0)
4345

4446

4547
def get_experiment_scanlog_url(experiment: str) -> Optional[str]:
46-
"""
47-
Maps an experiment name to a routine used to read the current day's experiment log
48-
49-
:param experiment: The experiment name
50-
:return: a string pointing to the
51-
"""
48+
"""Map an experiment name to a routine used to read the current day's experiment log."""
5249
experiment_to_func = {
53-
'Undulator': get_scanlog_undulator,
50+
"Undulator": get_scanlog_undulator,
5451
}
5552
if func := experiment_to_func.get(experiment, None):
5653
if url := func():
5754
return url
5855

5956

6057
def get_scanlog_undulator() -> Optional[str]:
61-
"""
62-
:return: the Google doc id for HTU's most recent daily experimental scan log
63-
"""
64-
base_folder = Path("Z:\software\control-all-loasis\HTU\Active Version\GEECS-Plugins\LogMaker4GoogleDocs\logmaker_4_googledocs")
58+
"""Get the Google doc id for HTU's most recent daily experimental scan log."""
59+
base_folder = Path(
60+
"Z:\software\control-all-loasis\HTU\Active Version\GEECS-Plugins\LogMaker4GoogleDocs\logmaker_4_googledocs"
61+
)
6562
if not base_folder.exists():
6663
return
6764

68-
config_file = 'HTUparameters.ini'
65+
config_file = "HTUparameters.ini"
6966
config_path = base_folder / config_file
7067

7168
# Load the configuration file
@@ -77,11 +74,11 @@ def get_scanlog_undulator() -> Optional[str]:
7774
return
7875

7976
# Build the url string
80-
document_id = experiment_config['DEFAULT']['logid']
77+
document_id = experiment_config["DEFAULT"]["logid"]
8178
url = f"https://docs.google.com/document/d/{document_id}"
8279
return url
8380

8481

8582
def reload_scan_data_paths():
86-
""" Calls ScanData's function to reset static variables pointing to experiment-specific folders """
87-
ScanData.reload_paths_config()
83+
"""Call ScanData's function to reset static variables pointing to experiment-specific folders."""
84+
ScanPaths.reload_paths_config()

0 commit comments

Comments
 (0)