Skip to content

Commit

Permalink
RemoteData: Add the is_cleaned property (#6101)
Browse files Browse the repository at this point in the history
This is a convenience method that will return the `KEY_EXTRA_CLEANED`
extra, which is set to `True` when the `clean` method is called. The
`is_empty` method is also updated to use this new property and shortcut
if set to `True`. This saves the method from having to open a transport
connection.
  • Loading branch information
unkcpz committed Aug 14, 2023
1 parent d082df7 commit 2a2353d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions aiida/orm/nodes/data/remote/base.py
Expand Up @@ -37,11 +37,19 @@ def get_remote_path(self):
def set_remote_path(self, val):
self.base.attributes.set('remote_path', val)

@property
def is_cleaned(self):
"""Return whether the remote folder has been cleaned."""
return self.base.extras.get(self.KEY_EXTRA_CLEANED, False)

@property
def is_empty(self):
"""
Check if remote folder is empty
"""
if self.is_cleaned:
return True

authinfo = self.get_authinfo()
transport = authinfo.get_transport()

Expand Down
3 changes: 2 additions & 1 deletion tests/orm/nodes/data/test_remote.py
Expand Up @@ -27,7 +27,8 @@ def remote_data(tmp_path, aiida_localhost):
def test_clean(remote_data):
"""Test the :meth:`aiida.orm.nodes.data.remote.base.RemoteData.clean` method."""
assert not remote_data.is_empty
assert not remote_data.is_cleaned

remote_data._clean() # pylint: disable=protected-access
assert remote_data.is_empty
assert remote_data.base.attributes.get(RemoteData.KEY_EXTRA_CLEANED, True)
assert remote_data.is_cleaned

0 comments on commit 2a2353d

Please sign in to comment.