Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/core/saving/simple.py: 0%

37 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-14 02:13 +0000

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3from dataclasses import dataclass 

4import logging 

5import os 

6from typing import Optional 

7 

8from daiquiri.core.saving.base import SavingHandler 

9 

10logger = logging.getLogger(__name__) 

11 

12 

13@dataclass 

14class ScanSaving: 

15 base_path: Optional[str] = None 

16 template: Optional[str] = None 

17 data_filename: Optional[str] = None 

18 

19 @property 

20 def root_path(self): 

21 return os.path.join(self.base_path, self.template) 

22 

23 @property 

24 def filename(self): 

25 return os.path.join(self.root_path, self.data_filename) + ".h5" 

26 

27 

28class SimpleSavingHandler(SavingHandler): 

29 def __init__(self, *args, **kwargs): 

30 super().__init__(*args, **kwargs) 

31 self._scan_saving = ScanSaving() 

32 

33 @property 

34 def scan_saving(self): 

35 return self._scan_saving 

36 

37 def _set_filename(self, base_path=None, template=None, data_filename=None): 

38 self.scan_saving.base_path = base_path 

39 self.scan_saving.template = os.path.join(template, data_filename) 

40 self.scan_saving.data_filename = data_filename 

41 

42 @property 

43 def filename(self): 

44 return self.scan_saving.filename 

45 

46 def create_root_path(self, wait_exists=False, wait_timeout=360): 

47 if not os.path.exists(self._scan_saving.root_path): 

48 os.makedirs(self._scan_saving.root_path) 

49 

50 def create_path(self, path): 

51 if not os.path.exists(path): 

52 os.makedirs(path)