Merge branch 'jython-support'

Closes #8302
This commit is contained in:
Yen Chi Hsuan 2016-03-03 18:49:32 +08:00
commit 0cae023b24
3 changed files with 28 additions and 6 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
*.pyc *.pyc
*.pyo *.pyo
*.class
*~ *~
*.DS_Store *.DS_Store
wine-py2exe/ wine-py2exe/

View file

@ -3,6 +3,7 @@ all: youtube-dl README.md CONTRIBUTING.md README.txt youtube-dl.1 youtube-dl.bas
clean: clean:
rm -rf youtube-dl.1.temp.md youtube-dl.1 youtube-dl.bash-completion README.txt MANIFEST build/ dist/ .coverage cover/ youtube-dl.tar.gz youtube-dl.zsh youtube-dl.fish *.dump *.part *.info.json *.mp4 *.flv *.mp3 *.avi CONTRIBUTING.md.tmp youtube-dl youtube-dl.exe rm -rf youtube-dl.1.temp.md youtube-dl.1 youtube-dl.bash-completion README.txt MANIFEST build/ dist/ .coverage cover/ youtube-dl.tar.gz youtube-dl.zsh youtube-dl.fish *.dump *.part *.info.json *.mp4 *.flv *.mp3 *.avi CONTRIBUTING.md.tmp youtube-dl youtube-dl.exe
find . -name "*.pyc" -delete find . -name "*.pyc" -delete
find . -name "*.class" -delete
PREFIX ?= /usr/local PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin BINDIR ?= $(PREFIX)/bin

View file

@ -465,6 +465,10 @@ def encodeFilename(s, for_subprocess=False):
if not for_subprocess and sys.platform == 'win32' and sys.getwindowsversion()[0] >= 5: if not for_subprocess and sys.platform == 'win32' and sys.getwindowsversion()[0] >= 5:
return s return s
# Jython assumes filenames are Unicode strings though reported as Python 2.x compatible
if sys.platform.startswith('java'):
return s
return s.encode(get_subprocess_encoding(), 'ignore') return s.encode(get_subprocess_encoding(), 'ignore')
@ -1215,6 +1219,8 @@ if sys.platform == 'win32':
raise OSError('Unlocking file failed: %r' % ctypes.FormatError()) raise OSError('Unlocking file failed: %r' % ctypes.FormatError())
else: else:
# Some platforms, such as Jython, is missing fcntl
try:
import fcntl import fcntl
def _lock_file(f, exclusive): def _lock_file(f, exclusive):
@ -1222,6 +1228,14 @@ else:
def _unlock_file(f): def _unlock_file(f):
fcntl.flock(f, fcntl.LOCK_UN) fcntl.flock(f, fcntl.LOCK_UN)
except ImportError:
UNSUPPORTED_MSG = 'file locking is not supported on this platform'
def _lock_file(f, exclusive):
raise IOError(UNSUPPORTED_MSG)
def _unlock_file(f):
raise IOError(UNSUPPORTED_MSG)
class locked_file(object): class locked_file(object):
@ -1385,6 +1399,12 @@ def fix_xml_ampersands(xml_str):
def setproctitle(title): def setproctitle(title):
assert isinstance(title, compat_str) assert isinstance(title, compat_str)
# ctypes in Jython is not complete
# http://bugs.jython.org/issue2148
if sys.platform.startswith('java'):
return
try: try:
libc = ctypes.cdll.LoadLibrary('libc.so.6') libc = ctypes.cdll.LoadLibrary('libc.so.6')
except OSError: except OSError: