1+ from recorder .io import yaml_dump
2+
13from typing import Dict
24from pathlib import Path
5+ from warnings import warn
6+ from datetime import datetime
37from abc import ABC , ABCMeta , abstractmethod
48
59
610class MetaDevice (ABCMeta ):
711
8- def __str__ (cls ):
12+ def __str__ (cls ) -> str :
913 return cls .__name__
1014
15+ def __repr__ (cls ) -> str :
16+ return cls .__name__ .lower ()
17+
1118
1219class Device (ABC , metaclass = MetaDevice ):
1320
14- def __init__ (self , _index : int , output_folder : Path , * args , ** kwargs ):
15- self .name = kwargs .get ('name' , 'unknown' )
16- self .output_file = output_folder / f'{ self .__name__ .lower ()} { _index } '
21+ def __init__ (self , index : int , output_folder : Path , config : dict ):
22+ self .config = config
23+ assert 'start_timestamp' not in self .config
24+ assert 'end_timestamp' not in self .config
25+ self .index = index
26+ self .name = self .config .get ('name' , 'unknown' )
27+ self .output_file = output_folder / f'{ repr (self )} '
1728
1829 def __str__ (self ) -> str :
1930 return self .name
2031
32+ def __repr__ (self ) -> str :
33+ return f'{ repr (type (self ))} { self .index } '
34+
35+ def __del__ (self ):
36+ yaml_dump (self .config , to_file = self .output_file .with_suffix ('.yaml' ))
37+
2138 @classmethod
2239 @abstractmethod
2340 def find (cls ) -> Dict [int , dict ]:
@@ -29,20 +46,27 @@ def find(cls) -> Dict[int, dict]:
2946 """
3047 pass
3148
32- @abstractmethod
3349 def start (self ) -> None :
34- """Starts recording.
50+ # Starts recording storing the start timestamp in configuration
51+ self .config ['start_timestamp' ] = datetime .now ().timestamp ()
52+ self ._start ()
3553
36- Returns:
37- None
38- """
54+ @ abstractmethod
55+ def _start ( self ) -> None :
56+ # Starts recording.
3957 pass
4058
41- @abstractmethod
42- def stop (self ) -> None :
43- """Stops recording.
59+ def stop (self ):
60+ # Stops recording storing the end timestamp in configuration
61+ self ._stop ()
62+ self .config ['end_timestamp' ] = datetime .now ().timestamp ()
4463
45- Returns:
46- None
47- """
64+ @ abstractmethod
65+ def _stop ( self ):
66+ # Stops recording
4867 pass
68+
69+ @classmethod
70+ @abstractmethod
71+ def show_results (cls , from_folder ):
72+ pass
0 commit comments