-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable access to resources through the module / tab-complete
- Loading branch information
1 parent
0d41fb1
commit 87a76bc
Showing
3 changed files
with
55 additions
and
7 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
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,27 @@ | ||
from . import _util | ||
|
||
class ResourceList: | ||
def __init__(self, resource_type, list_method, load_method): | ||
self.__resource_type = resource_type | ||
self.__list_method = list_method | ||
self.__load_method = load_method | ||
|
||
def __getattr__(self, name): | ||
resources = self.__list_method() | ||
if name in resources: | ||
return self.__load_method(name) | ||
else: | ||
# Default behaviour | ||
return object.__getattribute__(self, name) | ||
|
||
def __dir__(self): | ||
dirs = dir(self.__class__) | ||
dirs += list(self.__dict__.keys()) | ||
dirs += self.__list_method() | ||
return sorted(dirs) | ||
|
||
fluxes = ResourceList('fluxes', _util.list_fluxes, _util._get_flux_loader) | ||
detectors = ResourceList('detectors', _util.list_detectors, _util._get_detector_loader) | ||
processes = ResourceList('processes', _util.list_processes, _util._get_process_loader) | ||
|
||
del ResourceList |