Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
mega.py
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
richardARPANET
mega.py
Commits
a75b6811
Commit
a75b6811
authored
Nov 26, 2019
by
richardARPANET
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
dc360ebe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
11 deletions
+33
-11
src/mega/mega.py
src/mega/mega.py
+22
-10
src/tests/test_mega.py
src/tests/test_mega.py
+11
-1
No files found.
src/mega/mega.py
View file @
a75b6811
...
...
@@ -26,6 +26,10 @@ from .crypto import (
logger
=
logging
.
getLogger
(
__name__
)
def
_log_request_failed
():
logger
.
info
(
'Request failed, sleeping then retrying...'
)
class
Mega
:
def
__init__
(
self
,
options
=
None
):
self
.
schema
=
'https'
...
...
@@ -141,7 +145,8 @@ class Mega:
@
retry
(
retry
=
retry_if_exception_type
(
RuntimeError
),
wait
=
wait_exponential
(
multiplier
=
2
,
min
=
2
,
max
=
60
)
wait
=
wait_exponential
(
multiplier
=
2
,
min
=
2
,
max
=
60
),
before_sleep
=
_log_request_failed
,
)
def
_api_request
(
self
,
data
):
params
=
{
'id'
:
self
.
sequence_num
}
...
...
@@ -164,9 +169,7 @@ class Mega:
json_resp
=
json
.
loads
(
req
.
text
)
if
isinstance
(
json_resp
,
int
):
if
json_resp
==
-
3
:
msg
=
'Request failed, retrying'
logger
.
info
(
msg
)
raise
RuntimeError
(
msg
)
raise
RuntimeError
(
'Request failed, retrying'
)
raise
RequestError
(
json_resp
)
return
json_resp
[
0
]
...
...
@@ -301,6 +304,10 @@ class Mega:
"""
Return file object from given filename
"""
def
found
(
cloud_filename
,
search_filename
):
return
cloud_filename
==
search_filename
files
=
self
.
get_files
()
if
handle
:
return
files
[
handle
]
...
...
@@ -308,6 +315,12 @@ class Mega:
filename
=
path
.
name
parent_dir_name
=
path
.
parent
.
name
for
file
in
list
(
files
.
items
()):
try
:
cloud_file_name
=
file
[
1
][
'a'
][
'n'
]
cloud_file_parent_node_id
=
file
[
1
][
'p'
]
except
(
KeyError
,
TypeError
):
logger
.
debug
(
'Filename attribute not found, skipping
%
s'
,
file
)
continue
parent_node_id
=
None
if
parent_dir_name
:
parent_node_id
=
self
.
find_path_descriptor
(
...
...
@@ -315,22 +328,21 @@ class Mega:
)
if
(
filename
and
parent_node_id
and
f
ile
[
1
][
'a'
]
and
file
[
1
][
'a'
][
'n'
]
==
filename
and
parent_node_id
==
file
[
1
][
'p'
]
f
ound
(
cloud_file_name
,
filename
)
and
parent_node_id
==
cloud_file_parent_node_id
):
if
(
exclude_deleted
and
self
.
_trash_folder_node_id
==
file
[
1
][
'p'
]
self
.
_trash_folder_node_id
==
cloud_file_parent_node_id
):
continue
return
file
if
(
filename
and
file
[
1
][
'a'
]
and
file
[
1
][
'a'
][
'n'
]
==
filename
filename
and
found
(
cloud_file_name
,
filename
)
):
if
(
exclude_deleted
and
self
.
_trash_folder_node_id
==
file
[
1
][
'p'
]
self
.
_trash_folder_node_id
==
cloud_file_parent_node_id
):
continue
return
file
...
...
src/tests/test_mega.py
View file @
a75b6811
...
...
@@ -20,7 +20,7 @@ def folder_name():
@
pytest
.
fixture
def
mega
(
folder_name
):
mega_
=
Mega
()
mega_
=
Mega
(
{
'verbose'
:
True
}
)
mega_
.
login
(
email
=
os
.
environ
[
'EMAIL'
],
password
=
os
.
environ
[
'PASS'
])
created_nodes
=
mega_
.
create_folder
(
folder_name
)
yield
mega_
...
...
@@ -154,6 +154,16 @@ class TestFind:
assert
mega
.
find
(
path
)
def
test_find_file2
(
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}/te*.py'
assert
mega
.
find
(
path
)
def
test_path_not_found_returns_none
(
self
,
mega
):
assert
mega
.
find
(
'not_found'
)
is
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment