Skip to content

Commit

Permalink
open_remote_file: add open_fct argument
Browse files Browse the repository at this point in the history
  • Loading branch information
bouttier committed Sep 22, 2021
1 parent 1d79e2e commit fa7e870
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/utils_flask_sqla/migrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
Si aucun dossier n’est spécifié, un dossier temporaire, supprimé à la fin de la migration, est utilisé.
"""
class open_remote_file(ExitStack):
def __init__(self, base_url, filename):
def __init__(self, base_url, filename, open_fct=lzma.open):
super().__init__()
self.base_url = base_url
self.filename = filename
self.file_extension = filename.split('.')[-1]
self.open_fct = open_fct
self.data_dir = context.get_x_argument(as_dictionary=True).get('data-directory')

def __enter__(self):
Expand All @@ -38,10 +38,4 @@ def __enter__(self):
with urlopen('{}{}'.format(self.base_url, self.filename)) as response, \
open(remote_file_path, 'wb') as remote_file:
copyfileobj(response, remote_file)
# test des extension
f = None
if self.filename.endswith('.xz'):
f = lzma.open(remote_file_path)
else:
f = open(remote_file_path)
return stack.enter_context(f)
return stack.enter_context(self.open_fct(remote_file_path))

0 comments on commit fa7e870

Please sign in to comment.