Skip to content

Commit

Permalink
client: add ImageFile.new() to ease use from various storage methods
Browse files Browse the repository at this point in the history
Signed-off-by: Cedric Hombourger <cedric.hombourger@siemens.com>
  • Loading branch information
chombourger committed Nov 17, 2023
1 parent f1eb59c commit 5cf1586
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions mtda/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ def storage_write_image(self, path, callback=None):
impl = self._impl
session = self._session

if path.startswith('s3:'):
file = ImageS3(path, impl, session, blksz, callback)
else:
file = ImageLocal(path, impl, session, blksz, callback)
# Get file handler from specified path
file = ImageFile.new(path, impl, session, blksz, callback)

# Open the shared storage device so we own it
# It also prevents us from loading a new bmap file while
Expand Down Expand Up @@ -381,6 +379,12 @@ def video_url(self, host="", opts=None):
class ImageFile:
""" Base class for image files (local or remote) """

def new(path, agent, session, blksz, callback=None):
if path.startswith('s3:'):
return ImageS3(path, agent, session, blksz, callback)
else:
return ImageLocal(path, agent, session, blksz, callback)

def __init__(self, path, agent, session, blksz, callback=None):
self._agent = agent
self._blksz = blksz
Expand Down Expand Up @@ -426,8 +430,8 @@ def flush(self):
def path(self):
return self._path

def prepare(self, output_size=None):
compr = self.compression()
def prepare(self, output_size=None, compression=None):
compr = self.compression() if compression is None else compression
self._inputsize = self.size()
self._outputsize = None
if output_size is None:
Expand Down

0 comments on commit 5cf1586

Please sign in to comment.