From 067d6e8514e96f356941afc19a4ac4359a3af27d Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 30 Apr 2013 19:32:11 +0200 Subject: [PATCH] Put link and symlink in helpers --- couchpotato/core/helpers/variable.py | 14 ++++++++++++++ couchpotato/core/plugins/renamer/main.py | 21 ++++----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index ff1043bb..25def9ae 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -10,6 +10,20 @@ import sys log = CPLog(__name__) +def link(src, dst): + if os.name == 'nt': + import ctypes + if ctypes.windll.kernel32.CreateHardLinkW(unicode(dst), unicode(src), 0) == 0: raise ctypes.WinError() + else: + os.link(src, dst) + +def symlink(src, dst): + if os.name == 'nt': + import ctypes + if ctypes.windll.kernel32.CreateSymbolicLinkW(unicode(dst), unicode(src), 1 if os.path.isdir(src) else 0) in [0, 1280]: raise ctypes.WinError() + else: + os.symlink(src, dst) + def getUserDir(): try: import pwd diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 1932cf07..30a57a7b 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -4,7 +4,7 @@ from couchpotato.core.event import addEvent, fireEvent, fireEventAsync from couchpotato.core.helpers.encoding import toUnicode, ss from couchpotato.core.helpers.request import getParams, jsonified from couchpotato.core.helpers.variable import getExt, mergeDicts, getTitle, \ - getImdb + getImdb, link, symlink from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import Library, File, Profile, Release, \ @@ -19,19 +19,6 @@ import traceback log = CPLog(__name__) -# Windows hack for (sym)links -def winLink(src, dst): - import ctypes - if ctypes.windll.kernel32.CreateHardLinkW(unicode(dst), unicode(src), 0) == 0: raise ctypes.WinError() - -def winSymlink(src, dst): - import ctypes - if ctypes.windll.kernel32.CreateSymbolicLinkW(unicode(dst), unicode(src), 1 if os.path.isdir(src) else 0) in [0, 1280]: raise ctypes.WinError() - -if os.name == 'nt': - os.link = winLink - os.symlink = winSymlink - class Renamer(Plugin): renaming_started = False @@ -513,14 +500,14 @@ Remove it if you want it to be renamed (again, or at least let it try again) if forcemove: shutil.move(old, dest) elif self.conf('file_action') == 'hardlink': - os.link(old, dest) + link(old, dest) elif self.conf('file_action') == 'symlink': - os.symlink(old, dest) + symlink(old, dest) elif self.conf('file_action') == 'copy': shutil.copy(old, dest) elif self.conf('file_action') == 'move_symlink': shutil.move(old, dest) - os.symlink(dest, old) + symlink(dest, old) else: shutil.move(old, dest)