Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from DiamondLightSource/implicit-factory
Implicit factory
- Loading branch information
Showing
16 changed files
with
107 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ conf/config.cfg | |
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
.pytest_cache | ||
|
||
# C extensions | ||
*.so | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import importlib | ||
|
||
class factory_mixin(): | ||
def _get_data_area(self, module, classname): | ||
'''Helper function to instantiate a data area or return a cached instance.''' | ||
if hasattr(self, '_cache_' + module): | ||
return getattr(self, '_cache_' + module) | ||
da_mod = importlib.import_module('%s.%s' % (self.get_data_area_package(), module)) | ||
DAClass = getattr(da_mod, classname) | ||
da = DAClass() | ||
da.set_connection(self) | ||
setattr(self, '_cache_' + module, da) | ||
return da | ||
|
||
@property | ||
def core(self): | ||
'''Core part of the database schema''' | ||
return self._get_data_area('core', 'Core') | ||
|
||
@property | ||
def mx_acquisition(self): | ||
'''MX acquisition tables''' | ||
return self._get_data_area('mxacquisition', 'MXAcquisition') | ||
|
||
@property | ||
def em_acquisition(self): | ||
'''EM acquisition tables''' | ||
return self._get_data_area('emacquisition', 'EMAcquisition') | ||
|
||
@property | ||
def mx_processing(self): | ||
'''MX processing tables''' | ||
return self._get_data_area('mxprocessing', 'MXProcessing') | ||
|
||
@property | ||
def mx_screening(self): | ||
'''MX screening tables''' | ||
return self._get_data_area('mxscreening', 'MXScreening') | ||
|
||
@property | ||
def shipping(self): | ||
'''Shipping tables''' | ||
return self._get_data_area('shipping', 'Shipping') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.