Skip to content

Commit

Permalink
[IMP] fs_storage : Allow to choose different method to check connection
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-dacosta committed Apr 5, 2024
1 parent fa95079 commit ae728cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion fs_storage/models/fs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ def __init__(self, env, ids=(), prefetch_ids=()):
compute="_compute_options_properties",
store=False,
)
check_connection_method = fields.Selection(
[
("marker_file", "Create Marker file"),
("ls", "List File"),
],
default="marker_file",
required=True,
)

_sql_constraints = [
(
Expand Down Expand Up @@ -269,12 +277,21 @@ def _compute_options_properties(self) -> None:
def _get_marker_file_name(self):
return ".odoo_fs_storage_%s.marker" % self.id

def _check_connection(self, fs):
def _marker_file_check_connection(self, fs):

Check warning on line 280 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L280

Added line #L280 was not covered by tests
marker_file_name = self._get_marker_file_name()
try:
fs.info(marker_file_name)
except FileNotFoundError:
fs.touch(marker_file_name)

def _ls_check_connection(self, fs):

Check warning on line 287 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L287

Added line #L287 was not covered by tests
fs.ls("", detail=False)

def _check_connection(self, fs):
if self.check_connection_method == "marker_file":

Check warning on line 291 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L291

Added line #L291 was not covered by tests
self._marker_file_check_connection(fs)
elif self.check_connection_method == "ls":
self._ls_check_connection(fs)

Check warning on line 294 in fs_storage/models/fs_storage.py

View check run for this annotation

Codecov / codecov/patch

fs_storage/models/fs_storage.py#L293-L294

Added lines #L293 - L294 were not covered by tests
return True

@property
Expand Down
1 change: 1 addition & 0 deletions fs_storage/views/fs_storage_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
options="{'mode': 'python'}"
placeholder="Enter you fsspec options here."
/>
<field name="check_connection_method" />
</group>
<group>
<notebook colspan="2">
Expand Down

0 comments on commit ae728cb

Please sign in to comment.