-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create wrapper class so data.json is only loaded once [RHELDST-4863]
This commit includes the creation of a CdnData class, which holds methods related to the Python implementation of the data. The CdnData class allows for the data set to be loaded once.
- Loading branch information
1 parent
2383bf4
commit b112aeb
Showing
5 changed files
with
34 additions
and
25 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from ._impl import PathAlias, origin_aliases, rhui_aliases, load_data | ||
from ._impl import PathAlias, load_data | ||
from ._impl.cdn_data import CdnData | ||
|
||
__all__ = ["PathAlias", "origin_aliases", "rhui_aliases", "load_data"] | ||
__all__ = ["PathAlias", "load_data", "CdnData"] |
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,26 @@ | ||
from . import load_data, PathAlias | ||
|
||
|
||
class CdnData(object): | ||
def __init__(self, source=None): | ||
self._source = source | ||
self._data = None | ||
|
||
def data(self): | ||
if not self._data: | ||
self._data = load_data(self._source) | ||
return self._data | ||
|
||
def rhui_aliases(self): | ||
"""Returns: | ||
list[:class:`~PathAlias`] | ||
A list of aliases relating to RHUI paths. | ||
""" | ||
return [PathAlias(**elem) for elem in self.data()["rhui_alias"]] | ||
|
||
def origin_aliases(self): | ||
"""Returns: | ||
list[:class:`~PathAlias`] | ||
A list of aliases relating to origin paths. | ||
""" | ||
return [PathAlias(**elem) for elem in self.data()["origin_alias"]] |
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