11import json
22import os
3+ from pathlib import Path
4+ from logging import getLogger
35
4- from typing import Dict , Any , Union , Optional , List
6+ from typing import Dict , Any , Union , Optional , List , Iterator
57from typing_extensions import Literal
68from functools import lru_cache
79
2628
2729LoadedConfiguration = Dict [str , Union [str , Dict [str , Any ]]]
2830
31+ LOG = getLogger (__name__ )
2932
3033def _get_configuration_dictionary (
3134 config_type : Literal ["general" , "geometry" , "liquid" ],
@@ -95,6 +98,11 @@ def _physical(
9598) -> LoadedConfiguration :
9699 return _get_configuration_dictionary ("general" , channels , model , version )
97100
101+ def _dirs_in (path : Path ) -> Iterator [Path ]:
102+ for child in path .iterdir ():
103+ if child .is_dir ():
104+ yield child
105+
98106
99107@lru_cache (maxsize = None )
100108def load_serial_lookup_table () -> Dict [str , str ]:
@@ -112,23 +120,27 @@ def load_serial_lookup_table() -> Dict[str, str]:
112120 "eight_channel" : "multi" ,
113121 }
114122 _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 )
123135 if (
124136 model_dir == "p300"
125137 and int (version_list [0 ]) == 1
126138 and int (version_list [1 ]) == 0
127139 ):
128140 # Well apparently, we decided to switch the shorthand of the p300 depending
129141 # 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 ]} "
132144 _lookup_table [serial_shorthand ] = built_model
133145 return _lookup_table
134146
0 commit comments