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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user