Remove empty and processed folders
This commit is contained in:
@@ -67,6 +67,8 @@ class Renamer(Plugin):
|
|||||||
nfo_name = self.conf('nfo_name')
|
nfo_name = self.conf('nfo_name')
|
||||||
separator = self.conf('separator')
|
separator = self.conf('separator')
|
||||||
|
|
||||||
|
db = get_session()
|
||||||
|
|
||||||
for group_identifier in groups:
|
for group_identifier in groups:
|
||||||
|
|
||||||
group = groups[group_identifier]
|
group = groups[group_identifier]
|
||||||
@@ -125,7 +127,7 @@ class Renamer(Plugin):
|
|||||||
# Move nfo depending on settings
|
# Move nfo depending on settings
|
||||||
if file_type is 'nfo' and not self.conf('rename_nfo'):
|
if file_type is 'nfo' and not self.conf('rename_nfo'):
|
||||||
log.debug('Skipping, renaming of %s disabled' % file_type)
|
log.debug('Skipping, renaming of %s disabled' % file_type)
|
||||||
if self.conf('clean_up'):
|
if self.conf('cleanup'):
|
||||||
for current_file in group['files'][file_type]:
|
for current_file in group['files'][file_type]:
|
||||||
remove_files.append(current_file)
|
remove_files.append(current_file)
|
||||||
continue
|
continue
|
||||||
@@ -225,7 +227,6 @@ class Renamer(Plugin):
|
|||||||
cd += 1
|
cd += 1
|
||||||
|
|
||||||
# Before renaming, remove the lower quality files
|
# Before renaming, remove the lower quality files
|
||||||
db = get_session()
|
|
||||||
|
|
||||||
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
||||||
done_status = fireEvent('status.get', 'done', single = True)
|
done_status = fireEvent('status.get', 'done', single = True)
|
||||||
@@ -310,11 +311,26 @@ class Renamer(Plugin):
|
|||||||
if isinstance(src, File):
|
if isinstance(src, File):
|
||||||
src = src.path
|
src = src.path
|
||||||
|
|
||||||
log.info('(fake) Removing "%s"' % src)
|
log.info('Removing "%s"' % src)
|
||||||
|
try:
|
||||||
|
os.remove(src)
|
||||||
|
except:
|
||||||
|
log.error('Failed removing %s: %s', (src, traceback.format_exc()))
|
||||||
|
|
||||||
# Remove matching releases
|
# Remove matching releases
|
||||||
for release in remove_releases:
|
for release in remove_releases:
|
||||||
log.info('(fake) Removing release %s' % release.identifier)
|
log.debug('Removing release %s' % release.identifier)
|
||||||
|
try:
|
||||||
|
db.delete(release)
|
||||||
|
except:
|
||||||
|
log.error('Failed removing %s: %s', (release.identifier, traceback.format_exc()))
|
||||||
|
|
||||||
|
if group['dirname'] and group['parentdir']:
|
||||||
|
try:
|
||||||
|
log.info('Deleting folder: %s' % group['parentdir'])
|
||||||
|
self.deleteEmptyFolder(group['parentdir'])
|
||||||
|
except:
|
||||||
|
log.error('Failed removing %s: %s', (group['parentdir'], traceback.format_exc()))
|
||||||
|
|
||||||
# Search for trailers etc
|
# Search for trailers etc
|
||||||
fireEventAsync('renamer.after', group)
|
fireEventAsync('renamer.after', group)
|
||||||
@@ -380,3 +396,20 @@ class Renamer(Plugin):
|
|||||||
|
|
||||||
def replaceDoubles(self, string):
|
def replaceDoubles(self, string):
|
||||||
return string.replace(' ', ' ').replace(' .', '.')
|
return string.replace(' ', ' ').replace(' .', '.')
|
||||||
|
|
||||||
|
def deleteEmptyFolder(self, folder):
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(folder):
|
||||||
|
|
||||||
|
for dir_name in dirs:
|
||||||
|
full_path = os.path.join(root, dir_name)
|
||||||
|
if len(os.listdir(full_path)) == 0:
|
||||||
|
try:
|
||||||
|
os.rmdir(full_path)
|
||||||
|
except:
|
||||||
|
log.error('Couldn\'t remove empty directory %s: %s' % (full_path, traceback.format_exc()))
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.rmdir(folder)
|
||||||
|
except:
|
||||||
|
log.error('Couldn\'t remove empty directory %s: %s' % (folder, traceback.format_exc()))
|
||||||
|
|||||||
Reference in New Issue
Block a user