mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-16 02:02:53 -07:00
Code cleanup
* Streamline variable assignment * Replace assignment with augmented assignment * Remove unused variables and redundant parentheses
This commit is contained in:
parent
47c585d81c
commit
94e8a45c62
11 changed files with 39 additions and 58 deletions
|
@ -115,7 +115,6 @@ class DBConnection(object):
|
|||
logger.log(u"DB error: " + str(e), logger.ERROR)
|
||||
raise
|
||||
except sqlite3.DatabaseError as e:
|
||||
sqlResult = []
|
||||
if self.connection:
|
||||
self.connection.rollback()
|
||||
logger.log(u"Fatal error executing query: " + str(e), logger.ERROR)
|
||||
|
|
|
@ -58,7 +58,7 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
|
|||
fileName, fileExtension = os.path.splitext(file)
|
||||
|
||||
if fileExtension in core.USER_SCRIPT_MEDIAEXTENSIONS or "ALL" in core.USER_SCRIPT_MEDIAEXTENSIONS:
|
||||
num_files = num_files + 1
|
||||
num_files += 1
|
||||
if core.USER_SCRIPT_RUNONCE == 1 and num_files > 1: # we have already run once, so just continue to get number of files.
|
||||
continue
|
||||
command = [core.USER_SCRIPT]
|
||||
|
@ -103,16 +103,15 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
|
|||
except:
|
||||
logger.error("UserScript %s has failed" % (command[0]), "USERSCRIPT")
|
||||
result = int(1)
|
||||
final_result = final_result + result
|
||||
final_result += result
|
||||
|
||||
num_files_new = 0
|
||||
for dirpath, dirnames, filenames in os.walk(outputDestination):
|
||||
for file in filenames:
|
||||
filePath = core.os.path.join(dirpath, file)
|
||||
fileName, fileExtension = os.path.splitext(file)
|
||||
|
||||
if fileExtension in core.USER_SCRIPT_MEDIAEXTENSIONS or core.USER_SCRIPT_MEDIAEXTENSIONS == "ALL":
|
||||
num_files_new = num_files_new + 1
|
||||
num_files_new += 1
|
||||
|
||||
if core.USER_SCRIPT_CLEAN == int(1) and num_files_new == 0 and final_result == 0:
|
||||
logger.info("All files have been processed. Cleaning outputDirectory %s" % (outputDestination))
|
||||
|
|
|
@ -38,7 +38,7 @@ def reportNzb(failure_link, clientAgent):
|
|||
else:
|
||||
return
|
||||
try:
|
||||
r = requests.post(failure_link, headers=headers, timeout=(30, 300))
|
||||
requests.post(failure_link, headers=headers, timeout=(30, 300))
|
||||
except Exception as e:
|
||||
logger.error("Unable to open URL %s due to %s" % (failure_link, e))
|
||||
return
|
||||
|
@ -202,7 +202,7 @@ def is_minSize(inputName, minSize):
|
|||
|
||||
# audio files we need to check directory size not file size
|
||||
inputSize = os.path.getsize(inputName)
|
||||
if fileExt in (core.AUDIOCONTAINER):
|
||||
if fileExt in core.AUDIOCONTAINER:
|
||||
try:
|
||||
inputSize = getDirSize(os.path.dirname(inputName))
|
||||
except:
|
||||
|
@ -339,7 +339,7 @@ def rmReadOnly(filename):
|
|||
if os.path.isfile(filename):
|
||||
# check first the read-only attribute
|
||||
file_attribute = os.stat(filename)[0]
|
||||
if (not file_attribute & stat.S_IWRITE):
|
||||
if not file_attribute & stat.S_IWRITE:
|
||||
# File is read-only, so make it writeable
|
||||
logger.debug('Read only mode on file ' + filename + ' Will try to make it writeable')
|
||||
try:
|
||||
|
@ -631,11 +631,7 @@ def getDirs(section, subsection, link='hard'):
|
|||
f = guessit.guess_video_info(mediafile)
|
||||
|
||||
# get title
|
||||
title = None
|
||||
try:
|
||||
title = f['series']
|
||||
except:
|
||||
title = f['title']
|
||||
title = f.get('series') or f.get('title')
|
||||
|
||||
if not title:
|
||||
title = os.path.splitext(os.path.basename(mediafile))[0]
|
||||
|
@ -1262,7 +1258,7 @@ class WindowsProcess(object):
|
|||
def alreadyrunning(self):
|
||||
self.mutex = self.CreateMutex(None, 0, self.mutexname)
|
||||
self.lasterror = self.GetLastError()
|
||||
if (self.lasterror == self.ERROR_ALREADY_EXISTS):
|
||||
if self.lasterror == self.ERROR_ALREADY_EXISTS:
|
||||
self.CloseHandle(self.mutex)
|
||||
return True
|
||||
else:
|
||||
|
|
|
@ -23,7 +23,6 @@ class DelugeClient(object):
|
|||
self._request_counter = 0
|
||||
|
||||
def _get_local_auth(self):
|
||||
auth_file = ""
|
||||
username = password = ""
|
||||
if platform.system() in ('Windows', 'Microsoft'):
|
||||
appDataPath = os.environ.get("APPDATA")
|
||||
|
@ -62,9 +61,9 @@ class DelugeClient(object):
|
|||
continue
|
||||
|
||||
if username == "localclient":
|
||||
return (username, password)
|
||||
return username, password
|
||||
|
||||
return ("", "")
|
||||
return "", ""
|
||||
|
||||
def _create_module_method(self, module, method):
|
||||
fullname = "{0}.{1}".format(module, method)
|
||||
|
|
|
@ -10,7 +10,7 @@ class DelugeRPCRequest(object):
|
|||
self.kwargs = kwargs
|
||||
|
||||
def format(self):
|
||||
return (self.request_id, self.method, self.args, self.kwargs)
|
||||
return self.request_id, self.method, self.args, self.kwargs
|
||||
|
||||
|
||||
class DelugeRPCResponse(object):
|
||||
|
|
|
@ -126,39 +126,39 @@ def decode_int(x, f):
|
|||
raise ValueError
|
||||
elif x[f] == '0' and newf != f + 1:
|
||||
raise ValueError
|
||||
return (n, newf + 1)
|
||||
return n, newf + 1
|
||||
|
||||
|
||||
def decode_intb(x, f):
|
||||
f += 1
|
||||
return (struct.unpack('!b', x[f:f + 1])[0], f + 1)
|
||||
return struct.unpack('!b', x[f:f + 1])[0], f + 1
|
||||
|
||||
|
||||
def decode_inth(x, f):
|
||||
f += 1
|
||||
return (struct.unpack('!h', x[f:f + 2])[0], f + 2)
|
||||
return struct.unpack('!h', x[f:f + 2])[0], f + 2
|
||||
|
||||
|
||||
def decode_intl(x, f):
|
||||
f += 1
|
||||
return (struct.unpack('!l', x[f:f + 4])[0], f + 4)
|
||||
return struct.unpack('!l', x[f:f + 4])[0], f + 4
|
||||
|
||||
|
||||
def decode_intq(x, f):
|
||||
f += 1
|
||||
return (struct.unpack('!q', x[f:f + 8])[0], f + 8)
|
||||
return struct.unpack('!q', x[f:f + 8])[0], f + 8
|
||||
|
||||
|
||||
def decode_float32(x, f):
|
||||
f += 1
|
||||
n = struct.unpack('!f', x[f:f + 4])[0]
|
||||
return (n, f + 4)
|
||||
return n, f + 4
|
||||
|
||||
|
||||
def decode_float64(x, f):
|
||||
f += 1
|
||||
n = struct.unpack('!d', x[f:f + 8])[0]
|
||||
return (n, f + 8)
|
||||
return n, f + 8
|
||||
|
||||
|
||||
def decode_string(x, f):
|
||||
|
@ -177,7 +177,7 @@ def decode_string(x, f):
|
|||
s = t
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
return (s, colon + n)
|
||||
return s, colon + n
|
||||
|
||||
|
||||
def decode_list(x, f):
|
||||
|
@ -185,7 +185,7 @@ def decode_list(x, f):
|
|||
while x[f] != CHR_TERM:
|
||||
v, f = decode_func[x[f]](x, f)
|
||||
r.append(v)
|
||||
return (tuple(r), f + 1)
|
||||
return tuple(r), f + 1
|
||||
|
||||
|
||||
def decode_dict(x, f):
|
||||
|
@ -193,19 +193,19 @@ def decode_dict(x, f):
|
|||
while x[f] != CHR_TERM:
|
||||
k, f = decode_func[x[f]](x, f)
|
||||
r[k], f = decode_func[x[f]](x, f)
|
||||
return (r, f + 1)
|
||||
return r, f + 1
|
||||
|
||||
|
||||
def decode_true(x, f):
|
||||
return (True, f + 1)
|
||||
return True, f + 1
|
||||
|
||||
|
||||
def decode_false(x, f):
|
||||
return (False, f + 1)
|
||||
return False, f + 1
|
||||
|
||||
|
||||
def decode_none(x, f):
|
||||
return (None, f + 1)
|
||||
return None, f + 1
|
||||
|
||||
|
||||
decode_func = {
|
||||
|
@ -244,7 +244,7 @@ def make_fixed_length_string_decoders():
|
|||
s = t
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
return (s, f + 1 + slen)
|
||||
return s, f + 1 + slen
|
||||
|
||||
return f
|
||||
|
||||
|
@ -262,7 +262,7 @@ def make_fixed_length_list_decoders():
|
|||
for i in range(slen):
|
||||
v, f = decode_func[x[f]](x, f)
|
||||
r.append(v)
|
||||
return (tuple(r), f)
|
||||
return tuple(r), f
|
||||
|
||||
return f
|
||||
|
||||
|
@ -276,7 +276,7 @@ make_fixed_length_list_decoders()
|
|||
def make_fixed_length_int_decoders():
|
||||
def make_decoder(j):
|
||||
def f(x, f):
|
||||
return (j, f + 1)
|
||||
return j, f + 1
|
||||
|
||||
return f
|
||||
|
||||
|
@ -296,7 +296,7 @@ def make_fixed_length_dict_decoders():
|
|||
for j in range(slen):
|
||||
k, f = decode_func[x[f]](x, f)
|
||||
r[k], f = decode_func[x[f]](x, f)
|
||||
return (r, f)
|
||||
return r, f
|
||||
|
||||
return f
|
||||
|
||||
|
|
|
@ -142,7 +142,6 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
video_cmd = []
|
||||
audio_cmd = []
|
||||
audio_cmd2 = []
|
||||
audio_cmd3 = []
|
||||
sub_cmd = []
|
||||
meta_cmd = []
|
||||
other_cmd = []
|
||||
|
@ -221,10 +220,6 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
except:
|
||||
height = 0
|
||||
scale = core.VRESOLUTION
|
||||
try:
|
||||
framerate = float(fr.split('/')[0]) / float(fr.split('/')[1])
|
||||
except:
|
||||
framerate = 0
|
||||
if codec in core.VCODEC_ALLOW or not core.VCODEC:
|
||||
video_cmd.extend(['-c:v', 'copy'])
|
||||
else:
|
||||
|
@ -431,7 +426,6 @@ def buildCommands(file, newDir, movieName, bitbucket):
|
|||
audio_cmd.extend(audio_cmd3)
|
||||
|
||||
s_mapped = []
|
||||
subs1 = []
|
||||
burnt = 0
|
||||
n = 0
|
||||
for lan in core.SLANGUAGES:
|
||||
|
@ -587,12 +581,10 @@ def extract_subs(file, newfilePath, bitbucket):
|
|||
def processList(List, newDir, bitbucket):
|
||||
remList = []
|
||||
newList = []
|
||||
delList = []
|
||||
combine = []
|
||||
vtsPath = None
|
||||
success = True
|
||||
for item in List:
|
||||
newfile = None
|
||||
ext = os.path.splitext(item)[1].lower()
|
||||
if ext in ['.iso', '.bin', '.img'] and ext not in core.IGNOREEXTENSIONS:
|
||||
logger.debug("Attempting to rip disk image: %s" % (item), "TRANSCODER")
|
||||
|
@ -647,7 +639,6 @@ def ripISO(item, newDir, bitbucket):
|
|||
print_cmd(cmd)
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=bitbucket)
|
||||
out, err = proc.communicate()
|
||||
result = proc.returncode
|
||||
fileList = [re.match(".+(VIDEO_TS[\\\/]VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb])", line).groups()[0] for line in
|
||||
out.splitlines() if re.match(".+VIDEO_TS[\\\/]VTS_[0-9][0-9]_[0-9].[Vv][Oo][Bb]", line)]
|
||||
combined = []
|
||||
|
|
|
@ -409,11 +409,8 @@ class Client(object):
|
|||
pass
|
||||
if might_be_base64:
|
||||
torrent_data = torrent
|
||||
args = {}
|
||||
if torrent_data:
|
||||
args = {'metainfo': torrent_data}
|
||||
else:
|
||||
args = {'filename': torrent}
|
||||
|
||||
args = {'metainfo': torrent_data} if torrent_data else {'filename': torrent}
|
||||
for key, value in iteritems(kwargs):
|
||||
argument = make_rpc_name(key)
|
||||
(arg, val) = argument_value_convert('torrent-add', argument, value, self.rpc_version)
|
||||
|
@ -804,7 +801,7 @@ class Client(object):
|
|||
raise ValueError("Target name cannot contain a path delimiter")
|
||||
args = {'path': location, 'name': name}
|
||||
result = self._request('torrent-rename-path', args, torrent_id, True, timeout=timeout)
|
||||
return (result['path'], result['name'])
|
||||
return result['path'], result['name']
|
||||
|
||||
def queue_top(self, ids, timeout=None):
|
||||
"""Move transfer to the top of the queue."""
|
||||
|
|
|
@ -124,7 +124,6 @@ class Torrent(object):
|
|||
"""
|
||||
Update the torrent data from a Transmission JSON-RPC arguments dictionary
|
||||
"""
|
||||
fields = None
|
||||
if isinstance(other, dict):
|
||||
for key, value in iteritems(other):
|
||||
self._fields[key.replace('-', '_')] = Field(value, False)
|
||||
|
|
|
@ -23,7 +23,7 @@ def format_size(size):
|
|||
while size >= 1024.0 and i < len(UNITS):
|
||||
i += 1
|
||||
size /= 1024.0
|
||||
return (size, UNITS[i])
|
||||
return size, UNITS[i]
|
||||
|
||||
|
||||
def format_speed(size):
|
||||
|
@ -31,7 +31,7 @@ def format_speed(size):
|
|||
Format bytes per second speed into IEC prefixes, B/s, KiB/s, MiB/s ...
|
||||
"""
|
||||
(size, unit) = format_size(size)
|
||||
return (size, unit + '/s')
|
||||
return size, unit + '/s'
|
||||
|
||||
|
||||
def format_timedelta(delta):
|
||||
|
@ -91,7 +91,7 @@ def inet_address(address, default_port, default_address='localhost'):
|
|||
socket.getaddrinfo(addr, port, socket.AF_INET, socket.SOCK_STREAM)
|
||||
except socket.gaierror:
|
||||
raise INetAddressError('Cannot look up address "%s".' % address)
|
||||
return (addr, port)
|
||||
return addr, port
|
||||
|
||||
|
||||
def rpc_bool(arg):
|
||||
|
@ -163,7 +163,7 @@ def argument_value_convert(method, argument, value, rpc_version):
|
|||
raise ValueError(
|
||||
'Method "%s" Argument "%s" does not exist in version %d.'
|
||||
% (method, argument, rpc_version))
|
||||
return (argument, TR_TYPE_MAP[info[0]](value))
|
||||
return argument, TR_TYPE_MAP[info[0]](value)
|
||||
else:
|
||||
raise ValueError('Argument "%s" does not exists for method "%s".',
|
||||
(argument, method))
|
||||
|
|
|
@ -159,12 +159,13 @@ class GitUpdateManager(UpdateManager):
|
|||
|
||||
def _run_git(self, git_path, args):
|
||||
|
||||
output = err = exit_status = None
|
||||
output = None
|
||||
err = None
|
||||
|
||||
if not git_path:
|
||||
logger.log(u"No git specified, can't use git commands", logger.DEBUG)
|
||||
exit_status = 1
|
||||
return (output, err, exit_status)
|
||||
return output, err, exit_status
|
||||
|
||||
cmd = git_path + ' ' + args
|
||||
|
||||
|
@ -203,7 +204,7 @@ class GitUpdateManager(UpdateManager):
|
|||
logger.log(cmd + u" returned : " + output + u", treat as error for now", logger.DEBUG)
|
||||
exit_status = 1
|
||||
|
||||
return (output, err, exit_status)
|
||||
return output, err, exit_status
|
||||
|
||||
def _find_installed_version(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue