@@ -16,14 +16,29 @@ def load(cls, root_dirpath : str, download : bool = True, *args, **kwargs) -> Pa
1616 root_dirpath = os .path .abspath (root_dirpath )
1717
1818 if not os .path .isdir (root_dirpath ) and download :
19- tmp_fpath = tempfile .mktemp (suffix = '.zip' )
20- OpXRD ._download_zenodo_opxrd (output_fpath = tmp_fpath )
21- OpXRD ._unzip_file (tmp_fpath , output_dir = root_dirpath )
22-
19+ cls ._prepare_files (root_dirpath = root_dirpath )
2320
2421 print (f'- Loading patterns from local files' )
2522 return super ().load (dirpath = root_dirpath , strict = True )
2623
24+
25+ @classmethod
26+ def as_database_list (cls , root_dirpath : str , download : bool = True ) -> list [PatternDB ]:
27+ if not os .path .isdir (root_dirpath ) and download :
28+ cls ._prepare_files (root_dirpath = root_dirpath )
29+
30+ pattern_dbs = []
31+ for d in os .listdir (path = root_dirpath ):
32+ db = PatternDB .load (dirpath = os .path .join (root_dirpath , d ), strict = True )
33+ pattern_dbs .append (db )
34+ return pattern_dbs
35+
36+ @classmethod
37+ def _prepare_files (cls , root_dirpath : str ):
38+ tmp_fpath = tempfile .mktemp (suffix = '.zip' )
39+ OpXRD ._download_zenodo_opxrd (output_fpath = tmp_fpath )
40+ OpXRD ._unzip_file (tmp_fpath , output_dir = root_dirpath )
41+
2742 @classmethod
2843 def _download_zenodo_opxrd (cls , output_fpath : str ):
2944 zenodo_url = f'https://zenodo.org/api/records/{ cls .get_record_id ()} '
@@ -48,7 +63,7 @@ def _unzip_file(zip_fpath : str, output_dir : str):
4863 print (f'- Unziping downloaded files to { output_dir } ' )
4964 with zipfile .ZipFile (zip_fpath , 'r' ) as zip_ref :
5065 zip_ref .extractall (output_dir )
51- return f"Files extracted to { output_dir } "
66+ return f"- Files extracted to { output_dir } "
5267
5368 @classmethod
5469 def get_record_id (cls ) -> int :
0 commit comments