Put link and symlink in helpers
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user