1
1
import json
2
2
import os
3
+ from pathlib import Path
4
+ from logging import getLogger
3
5
4
- from typing import Dict , Any , Union , Optional , List
6
+ from typing import Dict , Any , Union , Optional , List , Iterator
5
7
from typing_extensions import Literal
6
8
from functools import lru_cache
7
9
26
28
27
29
LoadedConfiguration = Dict [str , Union [str , Dict [str , Any ]]]
28
30
31
+ LOG = getLogger (__name__ )
29
32
30
33
def _get_configuration_dictionary (
31
34
config_type : Literal ["general" , "geometry" , "liquid" ],
@@ -95,6 +98,11 @@ def _physical(
95
98
) -> LoadedConfiguration :
96
99
return _get_configuration_dictionary ("general" , channels , model , version )
97
100
101
+ def _dirs_in (path : Path ) -> Iterator [Path ]:
102
+ for child in path .iterdir ():
103
+ if child .is_dir ():
104
+ yield child
105
+
98
106
99
107
@lru_cache (maxsize = None )
100
108
def load_serial_lookup_table () -> Dict [str , str ]:
@@ -112,23 +120,27 @@ def load_serial_lookup_table() -> Dict[str, str]:
112
120
"eight_channel" : "multi" ,
113
121
}
114
122
_model_shorthand = {"p1000" : "p1k" , "p300" : "p3h" }
115
- for channel_dir in os .listdir (config_path ):
116
- for model_dir in os .listdir (config_path / channel_dir ):
117
- for version_file in os .listdir (config_path / channel_dir / model_dir ):
118
- version_list = version_file .split (".json" )[0 ].split ("_" )
119
- built_model = f"{ model_dir } _{ _channel_model_str [channel_dir ]} _v{ version_list [0 ]} .{ version_list [1 ]} "
120
-
121
- model_shorthand = _model_shorthand .get (model_dir , model_dir )
122
-
123
+ for channel_dir in _dirs_in (config_path ):
124
+ for model_dir in _dirs_in (channel_dir ):
125
+ for version_file in model_dir .iterdir ():
126
+ if version_file .suffix != '.json' :
127
+ continue
128
+ try :
129
+ version_list = version_file .stem .split ("_" )
130
+ built_model = f"{ model_dir .stem } _{ _channel_model_str [channel_dir .stem ]} _v{ version_list [0 ]} .{ version_list [1 ]} "
131
+ except IndexError :
132
+ LOG .warning (f'Pipette def with bad name { version_file } ignored' )
133
+ continue
134
+ model_shorthand = _model_shorthand .get (model_dir .stem , model_dir .stem )
123
135
if (
124
136
model_dir == "p300"
125
137
and int (version_list [0 ]) == 1
126
138
and int (version_list [1 ]) == 0
127
139
):
128
140
# Well apparently, we decided to switch the shorthand of the p300 depending
129
141
# on whether it's a "V1" model or not...so...here is the lovely workaround.
130
- model_shorthand = model_dir
131
- serial_shorthand = f"{ model_shorthand .upper ()} { _channel_shorthand [channel_dir ]} V{ version_list [0 ]} { version_list [1 ]} "
142
+ model_shorthand = model_dir . stem
143
+ serial_shorthand = f"{ model_shorthand .upper ()} { _channel_shorthand [channel_dir . stem ]} V{ version_list [0 ]} { version_list [1 ]} "
132
144
_lookup_table [serial_shorthand ] = built_model
133
145
return _lookup_table
134
146
0 commit comments