Fix name shadows builtin

This commit is contained in:
Labrys of Knossos 2018-12-26 12:28:18 -05:00 committed by Lizband
commit ad3fb4519d
7 changed files with 74 additions and 74 deletions

View file

@ -413,8 +413,8 @@ class Movie(object):
# Gather release info and return it back, no need to narrow results # Gather release info and return it back, no need to narrow results
if release_id: if release_id:
try: try:
id = result[section]['_id'] cur_id = result[section]['_id']
results[id] = result[section] results[cur_id] = result[section]
return results return results
except Exception: except Exception:
pass pass
@ -438,9 +438,9 @@ class Movie(object):
if download_id.lower() != release['download_info']['id'].lower(): if download_id.lower() != release['download_info']['id'].lower():
continue continue
id = release['_id'] cur_id = release['_id']
results[id] = release results[cur_id] = release
results[id]['title'] = movie['title'] results[cur_id]['title'] = movie['title']
except Exception: except Exception:
continue continue
@ -456,10 +456,10 @@ class Movie(object):
# Search downloads on clients for a match to try and narrow our results down to 1 # Search downloads on clients for a match to try and narrow our results down to 1
if len(results) > 1: if len(results) > 1:
for id, x in results.items(): for cur_id, x in results.items():
try: try:
if not find_download(str(x['download_info']['downloader']).lower(), x['download_info']['id']): if not find_download(str(x['download_info']['downloader']).lower(), x['download_info']['id']):
results.pop(id) results.pop(cur_id)
except Exception: except Exception:
continue continue

View file

@ -102,11 +102,11 @@ def extract(file_path, output_destination):
orig_files = [] orig_files = []
orig_dirs = [] orig_dirs = []
for dir, subdirs, files in os.walk(output_destination): for directory, subdirs, files in os.walk(output_destination):
for subdir in subdirs: for subdir in subdirs:
orig_dirs.append(os.path.join(dir, subdir)) orig_dirs.append(os.path.join(directory, subdir))
for file in files: for file in files:
orig_files.append(os.path.join(dir, file)) orig_files.append(os.path.join(directory, file))
pwd = os.getcwd() # Get our Present Working Directory pwd = os.getcwd() # Get our Present Working Directory
os.chdir(output_destination) # Not all unpack commands accept full paths, so just extract into this directory os.chdir(output_destination) # Not all unpack commands accept full paths, so just extract into this directory
@ -160,17 +160,17 @@ def extract(file_path, output_destination):
# sleep to let files finish writing to disk # sleep to let files finish writing to disk
sleep(3) sleep(3)
perms = stat.S_IMODE(os.lstat(os.path.split(file_path)[0]).st_mode) perms = stat.S_IMODE(os.lstat(os.path.split(file_path)[0]).st_mode)
for dir, subdirs, files in os.walk(output_destination): for directory, subdirs, files in os.walk(output_destination):
for subdir in subdirs: for subdir in subdirs:
if not os.path.join(dir, subdir) in orig_files: if not os.path.join(directory, subdir) in orig_files:
try: try:
os.chmod(os.path.join(dir, subdir), perms) os.chmod(os.path.join(directory, subdir), perms)
except Exception: except Exception:
pass pass
for file in files: for file in files:
if not os.path.join(dir, file) in orig_files: if not os.path.join(directory, file) in orig_files:
try: try:
shutil.copymode(file_path, os.path.join(dir, file)) shutil.copymode(file_path, os.path.join(directory, file))
except Exception: except Exception:
pass pass
return True return True

View file

@ -274,8 +274,8 @@ class SchemaUpgrade(object):
def has_column(self, table_name, column): def has_column(self, table_name, column):
return column in self.connection.table_info(table_name) return column in self.connection.table_info(table_name)
def add_column(self, table, column, type="NUMERIC", default=0): def add_column(self, table, column, data_type="NUMERIC", default=0):
self.connection.action("ALTER TABLE {0} ADD {1} {2}".format(table, column, type)) self.connection.action("ALTER TABLE {0} ADD {1} {2}".format(table, column, data_type))
self.connection.action("UPDATE {0} SET {1} = ?".format(table, column), (default,)) self.connection.action("UPDATE {0} SET {1} = ?".format(table, column), (default,))
def check_db_version(self): def check_db_version(self):

View file

@ -121,11 +121,11 @@ def reverse_filename(filename, dirname, name):
def rename_script(dirname): def rename_script(dirname):
rename_file = "" rename_file = ""
for dir, dirs, files in os.walk(dirname): for directory, directories, files in os.walk(dirname):
for file in files: for file in files:
if re.search(r'(rename\S*\.(sh|bat)$)', file, re.IGNORECASE): if re.search(r'(rename\S*\.(sh|bat)$)', file, re.IGNORECASE):
rename_file = os.path.join(dir, file) rename_file = os.path.join(directory, file)
dirname = dir dirname = directory
break break
if rename_file: if rename_file:
rename_lines = [line.strip() for line in open(rename_file)] rename_lines = [line.strip() for line in open(rename_file)]

View file

@ -124,7 +124,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
if 'concat:' in file: if 'concat:' in file:
file = file.split('|')[0].replace('concat:', '') file = file.split('|')[0].replace('concat:', '')
video_details, result = get_video_details(file) video_details, result = get_video_details(file)
dir, name = os.path.split(file) directory, name = os.path.split(file)
name, ext = os.path.splitext(name) name, ext = os.path.splitext(name)
check = re.match("VTS_([0-9][0-9])_[0-9]+", name) check = re.match("VTS_([0-9][0-9])_[0-9]+", name)
if check and core.CONCAT: if check and core.CONCAT:
@ -133,7 +133,7 @@ def build_commands(file, new_dir, movie_name, bitbucket):
name = ('{0}.cd{1}'.format(movie_name, check.groups()[0])) name = ('{0}.cd{1}'.format(movie_name, check.groups()[0]))
elif core.CONCAT and re.match("(.+)[cC][dD][0-9]", name): elif core.CONCAT and re.match("(.+)[cC][dD][0-9]", name):
name = re.sub('([ ._=:-]+[cC][dD][0-9])', "", name) name = re.sub('([ ._=:-]+[cC][dD][0-9])', "", name)
if ext == core.VEXTENSION and new_dir == dir: # we need to change the name to prevent overwriting itself. if ext == core.VEXTENSION and new_dir == directory: # we need to change the name to prevent overwriting itself.
core.VEXTENSION = '-transcoded{ext}'.format(ext=core.VEXTENSION) # adds '-transcoded.ext' core.VEXTENSION = '-transcoded{ext}'.format(ext=core.VEXTENSION) # adds '-transcoded.ext'
else: else:
img, data = next(iteritems(file)) img, data = next(iteritems(file))
@ -521,10 +521,10 @@ def get_subs(file):
filepaths = [] filepaths = []
sub_ext = ['.srt', '.sub', '.idx'] sub_ext = ['.srt', '.sub', '.idx']
name = os.path.splitext(os.path.split(file)[1])[0] name = os.path.splitext(os.path.split(file)[1])[0]
dir = os.path.split(file)[0] path = os.path.split(file)[0]
for dirname, dirs, filenames in os.walk(dir): for directory, directories, filenames in os.walk(path):
for filename in filenames: for filename in filenames:
filepaths.extend([os.path.join(dirname, filename)]) filepaths.extend([os.path.join(directory, filename)])
subfiles = [item for item in filepaths if os.path.splitext(item)[1] in sub_ext and name in item] subfiles = [item for item in filepaths if os.path.splitext(item)[1] in sub_ext and name in item]
return subfiles return subfiles

View file

@ -476,15 +476,15 @@ def convert_to_ascii(input_name, dir_name):
encoded, input_name = char_replace(input_name) encoded, input_name = char_replace(input_name)
dir, base = os.path.split(dir_name) directory, base = os.path.split(dir_name)
if not base: # ended with "/" if not base: # ended with "/"
dir, base = os.path.split(dir) directory, base = os.path.split(directory)
encoded, base2 = char_replace(base) encoded, base2 = char_replace(base)
if encoded: if encoded:
dir_name = os.path.join(dir, base2) dir_name = os.path.join(directory, base2)
logger.info("Renaming directory to: {0}.".format(base2), 'ENCODER') logger.info("Renaming directory to: {0}.".format(base2), 'ENCODER')
os.rename(os.path.join(dir, base), dir_name) os.rename(os.path.join(directory, base), dir_name)
if 'NZBOP_SCRIPTDIR' in os.environ: if 'NZBOP_SCRIPTDIR' in os.environ:
print("[NZB] DIRECTORY={0}".format(dir_name)) print("[NZB] DIRECTORY={0}".format(dir_name))
@ -579,32 +579,32 @@ def parse_transmission(args):
def parse_vuze(args): def parse_vuze(args):
# vuze usage: C:\full\path\to\nzbToMedia\TorrentToMedia.py "%D%N%L%I%K%F" # vuze usage: C:\full\path\to\nzbToMedia\TorrentToMedia.py "%D%N%L%I%K%F"
try: try:
input = args[1].split(',') cur_input = args[1].split(',')
except Exception: except Exception:
input = [] cur_input = []
try: try:
input_directory = os.path.normpath(input[0]) input_directory = os.path.normpath(cur_input[0])
except Exception: except Exception:
input_directory = '' input_directory = ''
try: try:
input_name = input[1] input_name = cur_input[1]
except Exception: except Exception:
input_name = '' input_name = ''
try: try:
input_category = input[2] input_category = cur_input[2]
except Exception: except Exception:
input_category = '' input_category = ''
try: try:
input_hash = input[3] input_hash = cur_input[3]
except Exception: except Exception:
input_hash = '' input_hash = ''
try: try:
input_id = input[3] input_id = cur_input[3]
except Exception: except Exception:
input_id = '' input_id = ''
try: try:
if input[4] == 'single': if cur_input[4] == 'single':
input_name = input[5] input_name = cur_input[5]
except Exception: except Exception:
pass pass
@ -614,27 +614,27 @@ def parse_vuze(args):
def parse_qbittorrent(args): def parse_qbittorrent(args):
# qbittorrent usage: C:\full\path\to\nzbToMedia\TorrentToMedia.py "%D|%N|%L|%I" # qbittorrent usage: C:\full\path\to\nzbToMedia\TorrentToMedia.py "%D|%N|%L|%I"
try: try:
input = args[1].split('|') cur_input = args[1].split('|')
except Exception: except Exception:
input = [] cur_input = []
try: try:
input_directory = os.path.normpath(input[0].replace('"', '')) input_directory = os.path.normpath(cur_input[0].replace('"', ''))
except Exception: except Exception:
input_directory = '' input_directory = ''
try: try:
input_name = input[1].replace('"', '') input_name = cur_input[1].replace('"', '')
except Exception: except Exception:
input_name = '' input_name = ''
try: try:
input_category = input[2].replace('"', '') input_category = cur_input[2].replace('"', '')
except Exception: except Exception:
input_category = '' input_category = ''
try: try:
input_hash = input[3].replace('"', '') input_hash = cur_input[3].replace('"', '')
except Exception: except Exception:
input_hash = '' input_hash = ''
try: try:
input_id = input[3].replace('"', '') input_id = cur_input[3].replace('"', '')
except Exception: except Exception:
input_id = '' input_id = ''
@ -732,12 +732,12 @@ def get_dirs(section, subsection, link='hard'):
# removeEmptyFolders(path, removeRoot=False) # removeEmptyFolders(path, removeRoot=False)
if os.listdir(text_type(path)): if os.listdir(text_type(path)):
for dir in [os.path.join(path, o) for o in os.listdir(text_type(path)) if for directory in [os.path.join(path, o) for o in os.listdir(text_type(path)) if
os.path.isdir(os.path.join(path, o))]: os.path.isdir(os.path.join(path, o))]:
sync = [o for o in os.listdir(text_type(dir)) if os.path.splitext(o)[1] in ['.!sync', '.bts']] sync = [o for o in os.listdir(text_type(directory)) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
if len(sync) > 0 or len(os.listdir(text_type(dir))) == 0: if len(sync) > 0 or len(os.listdir(text_type(directory))) == 0:
continue continue
folders.extend([dir]) folders.extend([directory])
return folders return folders
try: try:
@ -924,8 +924,8 @@ def find_download(client_agent, download_id):
if client_agent == 'transmission': if client_agent == 'transmission':
torrents = core.TORRENT_CLASS.get_torrents() torrents = core.TORRENT_CLASS.get_torrents()
for torrent in torrents: for torrent in torrents:
hash = torrent.hashString torrent_hash = torrent.hashString
if hash == download_id: if torrent_hash == download_id:
return True return True
if client_agent == 'deluge': if client_agent == 'deluge':
return False return False

View file

@ -62,59 +62,59 @@ class UTorrentClient(object):
def start(self, *hashes): def start(self, *hashes):
params = [('action', 'start'), ] params = [('action', 'start'), ]
for hash in hashes: for cur_hash in hashes:
params.append(('hash', hash)) params.append(('hash', cur_hash))
return self._action(params) return self._action(params)
def stop(self, *hashes): def stop(self, *hashes):
params = [('action', 'stop'), ] params = [('action', 'stop'), ]
for hash in hashes: for cur_hash in hashes:
params.append(('hash', hash)) params.append(('hash', cur_hash))
return self._action(params) return self._action(params)
def pause(self, *hashes): def pause(self, *hashes):
params = [('action', 'pause'), ] params = [('action', 'pause'), ]
for hash in hashes: for cur_hash in hashes:
params.append(('hash', hash)) params.append(('hash', cur_hash))
return self._action(params) return self._action(params)
def forcestart(self, *hashes): def forcestart(self, *hashes):
params = [('action', 'forcestart'), ] params = [('action', 'forcestart'), ]
for hash in hashes: for cur_hash in hashes:
params.append(('hash', hash)) params.append(('hash', cur_hash))
return self._action(params) return self._action(params)
def getfiles(self, hash): def getfiles(self, cur_hash):
params = [('action', 'getfiles'), ('hash', hash)] params = [('action', 'getfiles'), ('hash', cur_hash)]
return self._action(params) return self._action(params)
def getprops(self, hash): def getprops(self, cur_hash):
params = [('action', 'getprops'), ('hash', hash)] params = [('action', 'getprops'), ('hash', cur_hash)]
return self._action(params) return self._action(params)
def setprops(self, hash, **kvpairs): def setprops(self, cur_hash, **kvpairs):
params = [('action', 'setprops'), ('hash', hash)] params = [('action', 'setprops'), ('hash', cur_hash)]
for k, v in iteritems(kvpairs): for k, v in iteritems(kvpairs):
params.append(("s", k)) params.append(("s", k))
params.append(("v", v)) params.append(("v", v))
return self._action(params) return self._action(params)
def setprio(self, hash, priority, *files): def setprio(self, cur_hash, priority, *files):
params = [('action', 'setprio'), ('hash', hash), ('p', str(priority))] params = [('action', 'setprio'), ('hash', cur_hash), ('p', str(priority))]
for file_index in files: for file_index in files:
params.append(('f', str(file_index))) params.append(('f', str(file_index)))
return self._action(params) return self._action(params)
def addfile(self, filename, filepath=None, bytes=None): def addfile(self, filename, filepath=None, data=None):
params = [('action', 'add-file')] params = [('action', 'add-file')]
form = MultiPartForm() form = MultiPartForm()
if filepath is not None: if filepath is not None:
file_handler = open(filepath, 'rb') file_handler = open(filepath, 'rb')
else: else:
file_handler = StringIO(bytes) file_handler = StringIO(data)
form.add_file('torrent_file', filename.encode('utf-8'), file_handler) form.add_file('torrent_file', filename.encode('utf-8'), file_handler)
@ -126,14 +126,14 @@ class UTorrentClient(object):
def remove(self, *hashes): def remove(self, *hashes):
params = [('action', 'remove'), ] params = [('action', 'remove'), ]
for hash in hashes: for cur_hash in hashes:
params.append(('hash', hash)) params.append(('hash', cur_hash))
return self._action(params) return self._action(params)
def removedata(self, *hashes): def removedata(self, *hashes):
params = [('action', 'removedata'), ] params = [('action', 'removedata'), ]
for hash in hashes: for cur_hash in hashes:
params.append(('hash', hash)) params.append(('hash', cur_hash))
return self._action(params) return self._action(params)
def _action(self, params, body=None, content_type=None): def _action(self, params, body=None, content_type=None):