-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add content reader to decouple NFS file reads [RHELDST-26339]
The API to read content of the push items strongly depends on their presence as file on NFS or locally-mounted filesystem. However, with advent of new push item sources, it likely that the push items might not be stored as a file or be locally available. Hence, pushitems will have an `opener` that is capable to fetch the corresponding bits and provide them as `content()`. `Source` will define the `opener` while creating the pushitems to get the bit from the specific content source. This will transfer the responsibility to fetch the content from the consumer that is using the content/pushitems to the `Source` and corresponding `pushitem` here, abstracting the reading mechanism from the user and provide flexibility to fetch from different locations/protocols.
- Loading branch information
1 parent
62486a0
commit bf47408
Showing
31 changed files
with
318 additions
and
2 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,23 @@ | ||
from io import BufferedReader, SEEK_SET, UnsupportedOperation | ||
|
||
|
||
class PushItemReader(BufferedReader): | ||
# Internal class to ensure that the file-like content object returned by | ||
# the push items are read-only and non-seekable with a name attribute. | ||
def __init__(self, raw, name=None, **kwargs): | ||
super(PushItemReader, self).__init__(raw, **kwargs) | ||
|
||
# Attempt to assign name from the raw object if none is provided | ||
self._name = name or getattr(super(), "name", None) | ||
if not self._name: | ||
raise ValueError("'name' not provided or availble from 'raw' object") | ||
|
||
@property | ||
def name(self): | ||
return self._name or super().name() | ||
|
||
def seekable(self): | ||
return False | ||
|
||
def seek(self, offset, whence=SEEK_SET): | ||
raise UnsupportedOperation(f"Seek unsupported while reading {self.name}") |
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,5 @@ | ||
def open_src_local(item): | ||
# default opener for the push items | ||
# assumes that the item's 'src' points to the | ||
# locally-accessible file | ||
return open(item.src, "rb") |
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
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.