Replace linktastic with simple ctypes

Linktastic calls the command line interpreter to do linking. This
solution calls the windows API directly. This is faster and cleaner, but
most important of all: it doesn't cause a command window to popup every
time a link is made. This popup asks window focus and thus interrupts a
movie you are watching!!

Hopefully this also works on non-windows systems. I am unable to test
this so please let me know :)
This commit is contained in:
mano3m
2013-04-30 19:24:28 +02:00
committed by Ruud
parent 6b846b91b4
commit 42e19e1e2b
3 changed files with 15 additions and 80 deletions
+15 -4
View File
@@ -10,7 +10,6 @@ from couchpotato.core.plugins.base import Plugin
from couchpotato.core.settings.model import Library, File, Profile, Release, \
ReleaseInfo
from couchpotato.environment import Env
from linktastic.linktastic import link, symlink
import errno
import os
import re
@@ -20,6 +19,18 @@ 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):
@@ -502,14 +513,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':
link(old, dest)
os.link(old, dest)
elif self.conf('file_action') == 'symlink':
symlink(old, dest)
os.symlink(old, dest)
elif self.conf('file_action') == 'copy':
shutil.copy(old, dest)
elif self.conf('file_action') == 'move_symlink':
shutil.move(old, dest)
symlink(dest, old)
os.symlink(dest, old)
else:
shutil.move(old, dest)