Put link and symlink in helpers

This commit is contained in:
Ruud
2013-04-30 19:32:11 +02:00
parent 42e19e1e2b
commit 067d6e8514
2 changed files with 18 additions and 17 deletions
+14
View File
@@ -10,6 +10,20 @@ import sys
log = CPLog(__name__) 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(): def getUserDir():
try: try:
import pwd import pwd
+4 -17
View File
@@ -4,7 +4,7 @@ from couchpotato.core.event import addEvent, fireEvent, fireEventAsync
from couchpotato.core.helpers.encoding import toUnicode, ss from couchpotato.core.helpers.encoding import toUnicode, ss
from couchpotato.core.helpers.request import getParams, jsonified from couchpotato.core.helpers.request import getParams, jsonified
from couchpotato.core.helpers.variable import getExt, mergeDicts, getTitle, \ from couchpotato.core.helpers.variable import getExt, mergeDicts, getTitle, \
getImdb getImdb, link, symlink
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin from couchpotato.core.plugins.base import Plugin
from couchpotato.core.settings.model import Library, File, Profile, Release, \ from couchpotato.core.settings.model import Library, File, Profile, Release, \
@@ -19,19 +19,6 @@ import traceback
log = CPLog(__name__) 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): class Renamer(Plugin):
renaming_started = False 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: if forcemove:
shutil.move(old, dest) shutil.move(old, dest)
elif self.conf('file_action') == 'hardlink': elif self.conf('file_action') == 'hardlink':
os.link(old, dest) link(old, dest)
elif self.conf('file_action') == 'symlink': elif self.conf('file_action') == 'symlink':
os.symlink(old, dest) symlink(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') == 'move_symlink':
shutil.move(old, dest) shutil.move(old, dest)
os.symlink(dest, old) symlink(dest, old)
else: else:
shutil.move(old, dest) shutil.move(old, dest)