Browse Source

Add reverse symlink support to renamer

pull/7262/head
michalskrivanek 7 years ago
parent
commit
b95b726af2
  1. 26
      couchpotato/core/plugins/renamer.py

26
couchpotato/core/plugins/renamer.py

@ -839,7 +839,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
if use_default: if use_default:
move_type = self.conf('default_file_action') move_type = self.conf('default_file_action')
if move_type not in ['copy', 'link']: if move_type not in ['copy', 'link', 'symlink_reversed']:
try: try:
log.info('Moving "%s" to "%s"', (old, dest)) log.info('Moving "%s" to "%s"', (old, dest))
shutil.move(old, dest) shutil.move(old, dest)
@ -856,6 +856,16 @@ Remove it if you want it to be renamed (again, or at least let it try again)
elif move_type == 'copy': elif move_type == 'copy':
log.info('Copying "%s" to "%s"', (old, dest)) log.info('Copying "%s" to "%s"', (old, dest))
shutil.copy(old, dest) shutil.copy(old, dest)
elif move_type == 'symlink_reversed':
log.info('Reverse symlink "%s" to "%s"', (old, dest))
try:
shutil.move(old, dest)
except:
log.error('Moving "%s" to "%s" went wrong: %s', (old, dest, traceback.format_exc()))
try:
symlink(dest, old)
except:
log.error('Error while linking "%s" back to "%s": %s', (dest, old, traceback.format_exc()))
else: else:
log.info('Linking "%s" to "%s"', (old, dest)) log.info('Linking "%s" to "%s"', (old, dest))
# First try to hardlink # First try to hardlink
@ -863,7 +873,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
log.debug('Hardlinking file "%s" to "%s"...', (old, dest)) log.debug('Hardlinking file "%s" to "%s"...', (old, dest))
link(old, dest) link(old, dest)
except: except:
# Try to simlink next # Try to symlink next
log.debug('Couldn\'t hardlink file "%s" to "%s". Symlinking instead. Error: %s.', (old, dest, traceback.format_exc())) log.debug('Couldn\'t hardlink file "%s" to "%s". Symlinking instead. Error: %s.', (old, dest, traceback.format_exc()))
shutil.copy(old, dest) shutil.copy(old, dest)
try: try:
@ -1115,10 +1125,10 @@ Remove it if you want it to be renamed (again, or at least let it try again)
for release_download in scan_releases: for release_download in scan_releases:
# Ask the renamer to scan the item # Ask the renamer to scan the item
if release_download['scan']: if release_download['scan']:
if release_download['pause'] and self.conf('file_action') == 'link': if release_download['pause'] and self.conf('file_action') in ['link', "symlink_reversed"]:
fireEvent('download.pause', release_download = release_download, pause = True, single = True) fireEvent('download.pause', release_download = release_download, pause = True, single = True)
self.scan(release_download = release_download) self.scan(release_download = release_download)
if release_download['pause'] and self.conf('file_action') == 'link': if release_download['pause'] and self.conf('file_action') in ['link', "symlink_reversed"]:
fireEvent('download.pause', release_download = release_download, pause = False, single = True) fireEvent('download.pause', release_download = release_download, pause = False, single = True)
if release_download['process_complete']: if release_download['process_complete']:
# First make sure the files were successfully processed # First make sure the files were successfully processed
@ -1171,7 +1181,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
return src in group['before_rename'] return src in group['before_rename']
def moveTypeIsLinked(self): def moveTypeIsLinked(self):
return self.conf('default_file_action') in ['copy', 'link'] return self.conf('default_file_action') in ['copy', 'link', "symlink_reversed"]
def statusInfoComplete(self, release_download): def statusInfoComplete(self, release_download):
return release_download.get('id') and release_download.get('downloader') and release_download.get('folder') return release_download.get('id') and release_download.get('downloader') and release_download.get('folder')
@ -1507,9 +1517,9 @@ config = [{
'label': 'Default File Action', 'label': 'Default File Action',
'default': 'move', 'default': 'move',
'type': 'dropdown', 'type': 'dropdown',
'values': [('Link', 'link'), ('Copy', 'copy'), ('Move', 'move')], 'values': [('Link', 'link'), ('Copy', 'copy'), ('Move', 'move'), ('Reverse Symlink', 'symlink_reversed')],
'description': ('<strong>Link</strong>, <strong>Copy</strong> or <strong>Move</strong> after download completed.', 'description': ('<strong>Link</strong>, <strong>Copy</strong> or <strong>Move</strong> after download completed.',
'Link first tries <a href="http://en.wikipedia.org/wiki/Hard_link" target="_blank">hard link</a>, then <a href="http://en.wikipedia.org/wiki/Sym_link" target="_blank">sym link</a> and falls back to Copy.'), 'Link first tries <a href="http://en.wikipedia.org/wiki/Hard_link" target="_blank">hard link</a>, then <a href="http://en.wikipedia.org/wiki/Sym_link" target="_blank">sym link</a> and falls back to Copy. Reverse Symlink moves the file and creates symlink to it in the original location'),
'advanced': True, 'advanced': True,
}, },
{ {
@ -1517,7 +1527,7 @@ config = [{
'label': 'Torrent File Action', 'label': 'Torrent File Action',
'default': 'link', 'default': 'link',
'type': 'dropdown', 'type': 'dropdown',
'values': [('Link', 'link'), ('Copy', 'copy'), ('Move', 'move')], 'values': [('Link', 'link'), ('Copy', 'copy'), ('Move', 'move'), ('Reverse Symlink', 'symlink_reversed')],
'description': 'See above. It is prefered to use link when downloading torrents as it will save you space, while still being able to seed.', 'description': 'See above. It is prefered to use link when downloading torrents as it will save you space, while still being able to seed.',
'advanced': True, 'advanced': True,
}, },

Loading…
Cancel
Save