mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-22 06:13:19 -07:00
Braid: Add mirror 'linktastic' at 'cbce106'
This commit is contained in:
parent
606aa2d9c9
commit
c0b1dcaa14
5 changed files with 117 additions and 0 deletions
8
.braids
Normal file
8
.braids
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
linktastic:
|
||||||
|
url: git://github.com/berkona/linktastic
|
||||||
|
remote: master/braid/linktastic
|
||||||
|
type: git
|
||||||
|
branch: master
|
||||||
|
squashed: true
|
||||||
|
revision: cbce106163cadb488ace5d5cc9c44c8742a48a0f
|
2
linktastic/.gitignore
vendored
Normal file
2
linktastic/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
build
|
||||||
|
*.py[oc]
|
19
linktastic/README.txt
Normal file
19
linktastic/README.txt
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
Linktastic
|
||||||
|
|
||||||
|
Linktastic is an extension of the os.link and os.symlink functionality provided
|
||||||
|
by the python language since version 2. Python only supports file linking on
|
||||||
|
*NIX-based systems, even though it is relatively simple to engineer a solution
|
||||||
|
to utilize NTFS's built-in linking functionality. Linktastic attempts to unify
|
||||||
|
linking on the windows platform with linking on *NIX-based systems.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
|
||||||
|
Linktastic is a single python module and can be imported as such. Examples:
|
||||||
|
|
||||||
|
# Hard linking src to dest
|
||||||
|
import linktastic
|
||||||
|
linktastic.link(src, dest)
|
||||||
|
|
||||||
|
# Symlinking src to dest
|
||||||
|
import linktastic
|
||||||
|
linktastic.symlink(src, dest)
|
75
linktastic/linktastic.py
Normal file
75
linktastic/linktastic.py
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
# Prevent spaces from messing with us!
|
||||||
|
def _escape_param(param):
|
||||||
|
return '"%s"' % param
|
||||||
|
|
||||||
|
|
||||||
|
# Private function to create link on nt-based systems
|
||||||
|
def _link_windows(src, dest):
|
||||||
|
try:
|
||||||
|
subprocess.check_output(
|
||||||
|
['cmd', '/C', 'mklink', '/H', _escape_param(dest), _escape_param(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', _escape_param(dest), _escape_param(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)
|
13
linktastic/setup.py
Normal file
13
linktastic/setup.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
from distutils.core import setup
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name='Linktastic',
|
||||||
|
version='0.1.0',
|
||||||
|
author='Jon "Berkona" Monroe',
|
||||||
|
author_email='solipsis.dev@gmail.com',
|
||||||
|
py_modules=['linktastic'],
|
||||||
|
url="http://github.com/berkona/linktastic",
|
||||||
|
license='MIT License - See http://opensource.org/licenses/MIT for details',
|
||||||
|
description='Truly platform-independent file linking',
|
||||||
|
long_description=open('README.txt').read(),
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue