This commit is contained in:
Jon Monroe 2013-02-16 15:39:53 -08:00
commit f273b42e19
2 changed files with 88 additions and 23 deletions

View file

@ -3,7 +3,7 @@
import autoProcessMovie import autoProcessMovie
import autoProcessTV import autoProcessTV
import sys, os, ConfigParser, shutil import sys, os, ConfigParser, shutil
from subprocess import call import linktastic
from nzbToMediaEnv import * from nzbToMediaEnv import *
@ -211,12 +211,7 @@ elif useLink == 1 and packed == 0 and video == 1: ## hardlink
source = os.path.join(dirpath, file) source = os.path.join(dirpath, file)
target = os.path.join(destination, file) target = os.path.join(destination, file)
if os.name == 'nt' linktastic.link(source, target)
subprocess.call(['cmd', '/C', 'mklink', '/H', source, target], stdout=subprocess.PIPE)
elif os.name == 'posix':
os.link(source, target)
else:
print "ERROR: Hardlink failed, cannot determine OS."
elif packed == 1: ## unpack elif packed == 1: ## unpack
## Using Windows? ## Using Windows?

70
linktastic.py Normal file
View file

@ -0,0 +1,70 @@
# Linktastic Module
# - A python2/3 compatible module that can create hardlinks/symlinks on windows-based systems
#
# Linktastic is distributed under the MIT License. The follow are the terms and conditions of using Linktastic.
#
# The MIT License (MIT)
# Copyright (c) 2012 Solipsis Development
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
# associated documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import subprocess
from subprocess import CalledProcessError
import os
# Private function to create link on nt-based systems
def _link_windows(src, dest):
try:
subprocess.check_output(
['cmd', '/C', 'mklink', '/H', dest, src],
stderr=subprocess.STDOUT)
except CalledProcessError as err:
raise IOError(err.output.decode('utf-8'))
# TODO, find out what kind of messages Windows sends us from mklink
# print(stdout)
# assume if they ret-coded 0 we're good
def _symlink_windows(src, dest):
try:
subprocess.check_output(
['cmd', '/C', 'mklink', dest, src],
stderr=subprocess.STDOUT)
except CalledProcessError as err:
raise IOError(err.output.decode('utf-8'))
# TODO, find out what kind of messages Windows sends us from mklink
# print(stdout)
# assume if they ret-coded 0 we're good
# Create a hard link to src named as dest
# This version of link, unlike os.link, supports nt systems as well
def link(src, dest):
if os.name == 'nt':
_link_windows(src, dest)
else:
os.link(src, dest)
# Create a symlink to src named as dest, but don't fail if you're on nt
def symlink(src, dest):
if os.name == 'nt':
_symlink_windows(src, dest)
else:
os.symlink(src, dest)