mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 21:33:13 -07:00
PEP8: Fix formatting
* Remove redundant backslash between brackets * Fix multiple statements on one line * Fix missing/excess whitespace * Fix comments not starting with a single # and a space * Convert tabs to spaces * Use triple-quoted docstring
This commit is contained in:
parent
81ffe0456d
commit
8cd0e76ef8
35 changed files with 1342 additions and 947 deletions
|
@ -10,6 +10,7 @@ from six import string_types, iteritems
|
|||
|
||||
UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB']
|
||||
|
||||
|
||||
def format_size(size):
|
||||
"""
|
||||
Format byte size into IEC prefixes, B, KiB, MiB ...
|
||||
|
@ -21,6 +22,7 @@ def format_size(size):
|
|||
size /= 1024.0
|
||||
return (size, UNITS[i])
|
||||
|
||||
|
||||
def format_speed(size):
|
||||
"""
|
||||
Format bytes per second speed into IEC prefixes, B/s, KiB/s, MiB/s ...
|
||||
|
@ -28,6 +30,7 @@ def format_speed(size):
|
|||
(size, unit) = format_size(size)
|
||||
return (size, unit + '/s')
|
||||
|
||||
|
||||
def format_timedelta(delta):
|
||||
"""
|
||||
Format datetime.timedelta into <days> <hours>:<minutes>:<seconds>.
|
||||
|
@ -36,6 +39,7 @@ def format_timedelta(delta):
|
|||
hours, minutes = divmod(minutes, 60)
|
||||
return '%d %02d:%02d:%02d' % (delta.days, hours, minutes, seconds)
|
||||
|
||||
|
||||
def format_timestamp(timestamp, utc=False):
|
||||
"""
|
||||
Format unix timestamp into ISO date format.
|
||||
|
@ -49,12 +53,14 @@ def format_timestamp(timestamp, utc=False):
|
|||
else:
|
||||
return '-'
|
||||
|
||||
|
||||
class INetAddressError(Exception):
|
||||
"""
|
||||
Error parsing / generating a internet address.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def inet_address(address, default_port, default_address='localhost'):
|
||||
"""
|
||||
Parse internet address.
|
||||
|
@ -84,6 +90,7 @@ def inet_address(address, default_port, default_address='localhost'):
|
|||
raise INetAddressError('Cannot look up address "%s".' % address)
|
||||
return (addr, port)
|
||||
|
||||
|
||||
def rpc_bool(arg):
|
||||
"""
|
||||
Convert between Python boolean and Transmission RPC boolean.
|
||||
|
@ -95,27 +102,31 @@ def rpc_bool(arg):
|
|||
arg = arg.lower() in ['true', 'yes']
|
||||
return 1 if bool(arg) else 0
|
||||
|
||||
|
||||
TR_TYPE_MAP = {
|
||||
'number' : int,
|
||||
'string' : str,
|
||||
'number': int,
|
||||
'string': str,
|
||||
'double': float,
|
||||
'boolean' : rpc_bool,
|
||||
'boolean': rpc_bool,
|
||||
'array': list,
|
||||
'object': dict
|
||||
}
|
||||
|
||||
|
||||
def make_python_name(name):
|
||||
"""
|
||||
Convert Transmission RPC name to python compatible name.
|
||||
"""
|
||||
return name.replace('-', '_')
|
||||
|
||||
|
||||
def make_rpc_name(name):
|
||||
"""
|
||||
Convert python compatible name to Transmission RPC name.
|
||||
"""
|
||||
return name.replace('_', '-')
|
||||
|
||||
|
||||
def argument_value_convert(method, argument, value, rpc_version):
|
||||
"""
|
||||
Check and fix Transmission RPC issues with regards to methods, arguments and values.
|
||||
|
@ -154,6 +165,7 @@ def argument_value_convert(method, argument, value, rpc_version):
|
|||
raise ValueError('Argument "%s" does not exists for method "%s".',
|
||||
(argument, method))
|
||||
|
||||
|
||||
def get_arguments(method, rpc_version):
|
||||
"""
|
||||
Get arguments for method in specified Transmission RPC version.
|
||||
|
@ -175,6 +187,7 @@ def get_arguments(method, rpc_version):
|
|||
accessible.append(argument)
|
||||
return accessible
|
||||
|
||||
|
||||
def add_stdout_logger(level='debug'):
|
||||
"""
|
||||
Add a stdout target for the transmissionrpc logging.
|
||||
|
@ -189,6 +202,7 @@ def add_stdout_logger(level='debug'):
|
|||
loghandler.setLevel(loglevel)
|
||||
trpc_logger.addHandler(loghandler)
|
||||
|
||||
|
||||
def add_file_logger(filepath, level='debug'):
|
||||
"""
|
||||
Add a stdout target for the transmissionrpc logging.
|
||||
|
@ -203,4 +217,5 @@ def add_file_logger(filepath, level='debug'):
|
|||
loghandler.setLevel(loglevel)
|
||||
trpc_logger.addHandler(loghandler)
|
||||
|
||||
|
||||
Field = namedtuple('Field', ['value', 'dirty'])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue