1
1
""" Hardware devices. """
2
2
3
3
# Standard library imports
4
- from functools import wraps
5
- import logging
6
- import reprlib
7
4
8
5
# Third party imports
9
6
10
7
# Local imports
11
- # from .daq.synthetic import SyntheticDAQ # noqa
12
- # from .camera.synthetic import SyntheticCamera # noqa
13
- # from .filter_wheel.synthetic import SyntheticFilterWheel # noqa
14
- # from .galvo.synthetic import SyntheticGalvo # noqa
15
- # from .remote_focus.synthetic import SyntheticRemoteFocus # noqa
16
- # from .shutter.synthetic import SyntheticShutter # noqa
17
- # from .stages.synthetic import SyntheticStage # noqa
18
- # from .zoom.synthetic import SyntheticZoom # noqa
19
- # from .lasers.synthetic import SyntheticLaser # noqa
20
- # from .mirrors.synthetic import SyntheticMirror # noqa
21
-
22
- def log_initialization (cls ):
23
- """Decorator for logging the initialization of a device class.
24
-
25
- Parameters
26
- ----------
27
- cls : class
28
- The class to be logged.
29
-
30
- Returns
31
- -------
32
- cls : class
33
- The class with the logging decorator.
34
- """
35
- # Set up the reprlib object
36
- mod_repr = reprlib .Repr ()
37
- mod_repr .indent = 4
38
- mod_repr .maxstring = 50
39
- mod_repr .maxother = 50
40
-
41
- # Get the original __init__ method
42
- original_init = cls .__init__
43
-
44
- @wraps (original_init )
45
- def new_init (self , * args , ** kwargs ):
46
- module_location = cls .__module__
47
- logger = logging .getLogger (module_location .split ("." )[1 ])
48
- try :
49
- original_init (self , * args , ** kwargs )
50
- logger .info (f"{ mod_repr .repr (cls .__name__ )} , "
51
- f"{ mod_repr .repr (args )} , "
52
- f"{ mod_repr .repr (kwargs )} "
53
- )
54
- except Exception as e :
55
- logger .error (f"{ mod_repr .repr (cls .__name__ )} Initialization Failed" )
56
- logger .error (f"Input args & kwargs: { args } , { kwargs } " )
57
- logger .error (f"Error: { e } " )
58
- raise e
59
-
60
- # Replace the original __init__ method with the new one
61
- cls .__init__ = new_init
62
- return cls
8
+ from .daq .synthetic import SyntheticDAQ # noqa
9
+ from .camera .synthetic import SyntheticCamera # noqa
10
+ from .filter_wheel .synthetic import SyntheticFilterWheel # noqa
11
+ from .galvo .synthetic import SyntheticGalvo # noqa
12
+ from .remote_focus .synthetic import SyntheticRemoteFocus # noqa
13
+ from .shutter .synthetic import SyntheticShutter # noqa
14
+ from .stages .synthetic import SyntheticStage # noqa
15
+ from .zoom .synthetic import SyntheticZoom # noqa
16
+ from .lasers .synthetic import SyntheticLaser # noqa
17
+ from .mirrors .synthetic import SyntheticMirror # noqa
0 commit comments