mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 12:59:36 -07:00
Refactor process_dir to use generators
This commit is contained in:
parent
a888d741d3
commit
648ecd4048
1 changed files with 51 additions and 18 deletions
|
@ -82,14 +82,32 @@ def process_dir(path, link):
|
||||||
folders = []
|
folders = []
|
||||||
|
|
||||||
logger.info('Searching {0} for mediafiles to post-process ...'.format(path))
|
logger.info('Searching {0} for mediafiles to post-process ...'.format(path))
|
||||||
sync = [o for o in os.listdir(text_type(path)) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
|
dir_contents = os.listdir(text_type(path))
|
||||||
|
|
||||||
# search for single files and move them into their own folder for post-processing
|
# search for single files and move them into their own folder for post-processing
|
||||||
for mediafile in [os.path.join(path, o) for o in os.listdir(text_type(path)) if
|
|
||||||
os.path.isfile(os.path.join(path, o))]:
|
# Generate list of sync files
|
||||||
if len(sync) > 0:
|
sync_files = (
|
||||||
break
|
item for item in dir_contents
|
||||||
if os.path.split(mediafile)[1] in ['Thumbs.db', 'thumbs.db']:
|
if os.path.splitext(item)[1] in ['.!sync', '.bts']
|
||||||
continue
|
)
|
||||||
|
|
||||||
|
# Generate a list of file paths
|
||||||
|
filepaths = (
|
||||||
|
os.path.join(path, item) for item in dir_contents
|
||||||
|
if item not in ['Thumbs.db', 'thumbs.db']
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generate a list of media files
|
||||||
|
mediafiles = (
|
||||||
|
item for item in filepaths
|
||||||
|
if os.path.isfile(item)
|
||||||
|
)
|
||||||
|
|
||||||
|
if any(sync_files):
|
||||||
|
logger.info('')
|
||||||
|
else:
|
||||||
|
for mediafile in mediafiles:
|
||||||
try:
|
try:
|
||||||
move_file(mediafile, path, link)
|
move_file(mediafile, path, link)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -97,13 +115,28 @@ def process_dir(path, link):
|
||||||
|
|
||||||
# removeEmptyFolders(path, removeRoot=False)
|
# removeEmptyFolders(path, removeRoot=False)
|
||||||
|
|
||||||
if os.listdir(text_type(path)):
|
# Generate all path contents
|
||||||
for directory in [os.path.join(path, o) for o in os.listdir(text_type(path)) if
|
path_contents = (
|
||||||
os.path.isdir(os.path.join(path, o))]:
|
os.path.join(path, item)
|
||||||
sync = [o for o in os.listdir(text_type(directory)) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
|
for item in os.listdir(text_type(path))
|
||||||
if len(sync) > 0 or len(os.listdir(text_type(directory))) == 0:
|
)
|
||||||
|
|
||||||
|
# Generate all directories from path contents
|
||||||
|
directories = (
|
||||||
|
path for path in path_contents
|
||||||
|
if os.path.isdir(path)
|
||||||
|
)
|
||||||
|
|
||||||
|
for directory in directories:
|
||||||
|
dir_contents = os.listdir(directory)
|
||||||
|
sync_files = (
|
||||||
|
item for item in dir_contents
|
||||||
|
if os.path.splitext(item)[1] in ['.!sync', '.bts']
|
||||||
|
)
|
||||||
|
if not any(dir_contents) or any(sync_files):
|
||||||
continue
|
continue
|
||||||
folders.extend([directory])
|
folders.append(directory)
|
||||||
|
|
||||||
return folders
|
return folders
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue