Browse Source

Simplify linking

Thanks @mano3m
pull/1977/merge
Ruud 12 years ago
parent
commit
8e9e7b49ea
  1. 6
      couchpotato/core/plugins/renamer/__init__.py
  2. 30
      couchpotato/core/plugins/renamer/main.py

6
couchpotato/core/plugins/renamer/__init__.py

@ -120,10 +120,10 @@ config = [{
{ {
'name': 'file_action', 'name': 'file_action',
'label': 'Torrent File Action', 'label': 'Torrent File Action',
'default': 'move', 'default': 'link',
'type': 'dropdown', 'type': 'dropdown',
'values': [('Move', 'move'), ('Copy', 'copy'), ('Hard link', 'hardlink'), ('Move & Sym link', 'move_symlink')], 'values': [('Link', 'link'), ('Copy', 'copy'), ('Move', 'move')],
'description': 'Define which kind of file operation you want to use for torrents. Before you start using <a href="http://en.wikipedia.org/wiki/Hard_link">hard links</a> or <a href="http://en.wikipedia.org/wiki/Sym_link">sym links</a>, PLEASE read about their possible drawbacks.', 'description': '<strong>Link</strong> or <strong>Copy</strong> after downloading completed (and allow for seeding), or <strong>Move</strong> after seeding completed. Link first tries <a href="http://en.wikipedia.org/wiki/Hard_link">hard link</a>, then <a href="http://en.wikipedia.org/wiki/Sym_link">sym link</a> and falls back to Copy.',
'advanced': True, 'advanced': True,
}, },
{ {

30
couchpotato/core/plugins/renamer/main.py

@ -548,21 +548,23 @@ Remove it if you want it to be renamed (again, or at least let it try again)
try: try:
if forcemove: if forcemove:
shutil.move(old, dest) shutil.move(old, dest)
elif self.conf('file_action') == 'hardlink':
try:
link(old, dest)
except:
log.error('Couldn\'t hardlink file "%s" to "%s". Copying instead. Error: %s. ', (old, dest, traceback.format_exc()))
shutil.copy(old, dest)
elif self.conf('file_action') == 'copy': elif self.conf('file_action') == 'copy':
shutil.copy(old, dest) shutil.copy(old, dest)
elif self.conf('file_action') == 'move_symlink': elif self.conf('file_action') == 'link':
shutil.move(old, dest) # First try to hardlink
try: try:
symlink(dest, old) log.debug('Hardlinking file "%s" to "%s"...', (old, dest))
link(old, dest)
except: except:
log.error('Couldn\'t symlink file "%s" to "%s". Copying the file back. Error: %s. ', (old, dest, traceback.format_exc())) # Try to simlink next
shutil.copy(dest, old) log.debug('Couldn\'t hardlink file "%s" to "%s". Simlinking instead. Error: %s. ', (old, dest, traceback.format_exc()))
shutil.copy(old, dest)
try:
symlink(dest, old + '.link')
os.unlink(old)
os.rename(old + '.link', old)
except:
log.error('Couldn\'t symlink file "%s" to "%s". Copied instead. Error: %s. ', (old, dest, traceback.format_exc()))
else: else:
shutil.move(old, dest) shutil.move(old, dest)
@ -767,10 +769,10 @@ Remove it if you want it to be renamed (again, or at least let it try again)
for item in scan_items: for item in scan_items:
# Ask the renamer to scan the item # Ask the renamer to scan the item
if item['scan']: if item['scan']:
if item['pause'] and self.conf('file_action') == 'move_symlink': if item['pause'] and self.conf('file_action') == 'link':
fireEvent('download.pause', item = item, pause = True, single = True) fireEvent('download.pause', item = item, pause = True, single = True)
fireEvent('renamer.scan', download_info = item) fireEvent('renamer.scan', download_info = item)
if item['pause'] and self.conf('file_action') == 'move_symlink': if item['pause'] and self.conf('file_action') == 'link':
fireEvent('download.pause', item = item, pause = False, single = True) fireEvent('download.pause', item = item, pause = False, single = True)
if item['process_complete']: if item['process_complete']:
#First make sure the files were succesfully processed #First make sure the files were succesfully processed
@ -829,6 +831,6 @@ Remove it if you want it to be renamed (again, or at least let it try again)
def statusInfoComplete(self, item): def statusInfoComplete(self, item):
return item['id'] and item['downloader'] and item['folder'] return item['id'] and item['downloader'] and item['folder']
def movieInFromFolder(self, movie_folder): def movieInFromFolder(self, movie_folder):
return movie_folder and self.conf('from') in movie_folder or not movie_folder return movie_folder and self.conf('from') in movie_folder or not movie_folder

Loading…
Cancel
Save