Rewrite get_transfer_quota.
I believe the original implementation of get_quota was confusing disk vs bandwidth quota, considering get_storage_space already exists and get_quota was checking the same mstrg attributes etc. This clearly renames the get_quota method to get_transfer_quota and checks the mxfer/tah to see bandwidth usage.
This commit is contained in:
parent
c39094a8df
commit
d0cd38e5c5
1 changed files with 29 additions and 25 deletions
|
@ -535,13 +535,40 @@ class Mega:
|
||||||
node_id = i['h']
|
node_id = i['h']
|
||||||
return node_id
|
return node_id
|
||||||
|
|
||||||
def get_quota(self):
|
def get_transfer_quota(self):
|
||||||
"""
|
"""
|
||||||
Get total and remaining disk space.
|
Get transfer quota usage and maximum.
|
||||||
"""
|
"""
|
||||||
request = {
|
request = {
|
||||||
'a': 'uq',
|
'a': 'uq',
|
||||||
'xfer': 1,
|
'xfer': 1,
|
||||||
|
'v': 1
|
||||||
|
}
|
||||||
|
json_resp = self._api_request(request)
|
||||||
|
if json_resp['utype'] == 0:
|
||||||
|
# For free accounts, there is no specified limit and your bandwidth
|
||||||
|
# is measured in a 6-hour rolling window.
|
||||||
|
response = {
|
||||||
|
'total': None,
|
||||||
|
'used': sum(json_resp['tah']),
|
||||||
|
'remaining': None,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# For Pro users, bandwidth limits are clearly defined by the
|
||||||
|
# account and the response contains simple integers for total, used.
|
||||||
|
response = {
|
||||||
|
'total': json_resp['mxfer'],
|
||||||
|
'used': json_resp['caxfer'],
|
||||||
|
'remaining': json_resp['mxfer'] - json_resp['caxfer'],
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
|
||||||
|
def get_storage_quota(self):
|
||||||
|
"""
|
||||||
|
Get disk quota usage and maximum.
|
||||||
|
"""
|
||||||
|
request = {
|
||||||
|
'a': 'uq',
|
||||||
'strg': 1,
|
'strg': 1,
|
||||||
'v': 1
|
'v': 1
|
||||||
}
|
}
|
||||||
|
@ -553,29 +580,6 @@ class Mega:
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def get_storage_space(self, giga=False, mega=False, kilo=False):
|
|
||||||
"""
|
|
||||||
Get the current storage space.
|
|
||||||
Return a dict containing at least:
|
|
||||||
'used' : the used space on the account
|
|
||||||
'total' : the maximum space allowed with current plan
|
|
||||||
All storage space are in bytes unless asked differently.
|
|
||||||
"""
|
|
||||||
if sum(bool(x) for x in (kilo, mega, giga)) > 1:
|
|
||||||
raise ValueError("Only one unit prefix can be specified")
|
|
||||||
unit_coef = 1
|
|
||||||
if kilo:
|
|
||||||
unit_coef = 1024
|
|
||||||
if mega:
|
|
||||||
unit_coef = 1048576
|
|
||||||
if giga:
|
|
||||||
unit_coef = 1073741824
|
|
||||||
json_resp = self._api_request({'a': 'uq', 'xfer': 1, 'strg': 1})
|
|
||||||
return {
|
|
||||||
'used': json_resp['cstrg'] / unit_coef,
|
|
||||||
'total': json_resp['mstrg'] / unit_coef,
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_balance(self):
|
def get_balance(self):
|
||||||
"""
|
"""
|
||||||
Get account monetary balance, Pro accounts only
|
Get account monetary balance, Pro accounts only
|
||||||
|
|
Loading…
Reference in a new issue