adds exclude_deleted flag to find()
This commit is contained in:
parent
5ec9e78c42
commit
5261751dc3
4 changed files with 49 additions and 2 deletions
|
@ -11,6 +11,7 @@ Release History
|
||||||
- Adds ``export()`` method to share a file or folder, returning public share URL with key.
|
- Adds ``export()`` method to share a file or folder, returning public share URL with key.
|
||||||
- Adds code, message attrs to RequestError exception, makes message in raised exceptions include more details.
|
- Adds code, message attrs to RequestError exception, makes message in raised exceptions include more details.
|
||||||
- Alters ``create_folder()`` to accept a path including multiple sub directories, adds support to create them all (similar to 'mkdir -p' on unix systems).
|
- Alters ``create_folder()`` to accept a path including multiple sub directories, adds support to create them all (similar to 'mkdir -p' on unix systems).
|
||||||
|
- Adds ``exclude_deleted=True`` optional arg to ``find()`` method, to exclude deleted nodes from results.
|
||||||
|
|
||||||
|
|
||||||
0.9.20 (2019-10-17)
|
0.9.20 (2019-10-17)
|
||||||
|
|
|
@ -116,6 +116,15 @@ Upload a file, and get its public link
|
||||||
m.get_upload_link(file)
|
m.get_upload_link(file)
|
||||||
# see mega.py for destination and filename options
|
# see mega.py for destination and filename options
|
||||||
|
|
||||||
|
Fine a file or folder
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. code:: python
|
||||||
|
|
||||||
|
folder = m.find('my_mega_folder')
|
||||||
|
# Excludes results which are in the Trash folder (i.e. deleted)
|
||||||
|
folder = m.find('my_mega_folder', exclude_deleted=True)
|
||||||
|
|
||||||
Upload a file to a destination folder
|
Upload a file to a destination folder
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Mega(object):
|
||||||
self.sid = None
|
self.sid = None
|
||||||
self.sequence_num = random.randint(0, 0xFFFFFFFF)
|
self.sequence_num = random.randint(0, 0xFFFFFFFF)
|
||||||
self.request_id = make_id(10)
|
self.request_id = make_id(10)
|
||||||
|
self._trash_folder_node_id = None
|
||||||
|
|
||||||
if options is None:
|
if options is None:
|
||||||
options = {}
|
options = {}
|
||||||
|
@ -42,6 +43,7 @@ class Mega(object):
|
||||||
self._login_user(email, password)
|
self._login_user(email, password)
|
||||||
else:
|
else:
|
||||||
self.login_anonymous()
|
self.login_anonymous()
|
||||||
|
self._trash_folder_node_id = self.get_node_by_type(4)[0]
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def _login_user(self, email, password):
|
def _login_user(self, email, password):
|
||||||
|
@ -291,7 +293,7 @@ class Mega(object):
|
||||||
return None
|
return None
|
||||||
return parent_desc
|
return parent_desc
|
||||||
|
|
||||||
def find(self, filename=None, handle=None):
|
def find(self, filename=None, handle=None, exclude_deleted=False):
|
||||||
"""
|
"""
|
||||||
Return file object from given filename
|
Return file object from given filename
|
||||||
"""
|
"""
|
||||||
|
@ -312,11 +314,21 @@ class Mega(object):
|
||||||
file[1]['a'] and file[1]['a']['n'] == filename and
|
file[1]['a'] and file[1]['a']['n'] == filename and
|
||||||
parent_node_id == file[1]['p']
|
parent_node_id == file[1]['p']
|
||||||
):
|
):
|
||||||
|
if (
|
||||||
|
exclude_deleted and
|
||||||
|
self._trash_folder_node_id == file[1]['p']
|
||||||
|
):
|
||||||
|
continue
|
||||||
return file
|
return file
|
||||||
if (
|
if (
|
||||||
filename and
|
filename and
|
||||||
file[1]['a'] and file[1]['a']['n'] == filename
|
file[1]['a'] and file[1]['a']['n'] == filename
|
||||||
):
|
):
|
||||||
|
if (
|
||||||
|
exclude_deleted and
|
||||||
|
self._trash_folder_node_id == file[1]['p']
|
||||||
|
):
|
||||||
|
continue
|
||||||
return file
|
return file
|
||||||
|
|
||||||
def get_files(self):
|
def get_files(self):
|
||||||
|
|
|
@ -97,7 +97,7 @@ class TestExport:
|
||||||
mega.upload(
|
mega.upload(
|
||||||
__file__, dest=dest_node_id, dest_filename='test.py'
|
__file__, dest=dest_node_id, dest_filename='test.py'
|
||||||
)
|
)
|
||||||
path = '{}/test.py'.format(folder_name)
|
path = f'{folder_name}/test.py'
|
||||||
assert mega.find(path)
|
assert mega.find(path)
|
||||||
|
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
|
@ -133,6 +133,31 @@ class TestCreateFolder:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestFind:
|
||||||
|
|
||||||
|
def test_find_file(self, mega, folder_name):
|
||||||
|
folder = mega.find(folder_name)
|
||||||
|
dest_node_id = folder[1]['h']
|
||||||
|
mega.upload(
|
||||||
|
__file__, dest=dest_node_id, dest_filename='test.py'
|
||||||
|
)
|
||||||
|
path = f'{folder_name}/test.py'
|
||||||
|
|
||||||
|
assert mega.find(path)
|
||||||
|
|
||||||
|
def test_path_not_found_returns_none(self, mega):
|
||||||
|
assert mega.find('not_found') is None
|
||||||
|
|
||||||
|
def test_exclude_deleted_files(self, mega, folder_name):
|
||||||
|
folder_node_id = mega.find(folder_name)[0]
|
||||||
|
assert mega.find(folder_name)
|
||||||
|
|
||||||
|
mega.delete(folder_node_id)
|
||||||
|
|
||||||
|
assert mega.find(folder_name)
|
||||||
|
assert not mega.find(folder_name, exclude_deleted=True)
|
||||||
|
|
||||||
|
|
||||||
def test_rename(mega, folder_name):
|
def test_rename(mega, folder_name):
|
||||||
file = mega.find(folder_name)
|
file = mega.find(folder_name)
|
||||||
if file:
|
if file:
|
||||||
|
|
Loading…
Reference in a new issue