use os.sep

This commit is contained in:
j 2015-10-09 16:09:39 +03:00
parent dc90e04fdf
commit 96eabd9c8f
3 changed files with 31 additions and 35 deletions

View file

@ -29,7 +29,7 @@ __version__ = pkg_resources.require("pandora_client")[0].version
socket.setdefaulttimeout(300) socket.setdefaulttimeout(300)
CHUNK_SIZE = 1024*1024 CHUNK_SIZE = 1024*1024
default_media_cache = os.environ.get('oxMEDIA', '~/.ox/media') default_media_cache = os.environ.get('oxMEDIA', os.path.join(utils.basedir(), 'media'))
DOCUMENT_FORMATS = ('jpg', 'pdf', 'png') DOCUMENT_FORMATS = ('jpg', 'pdf', 'png')
@ -93,9 +93,10 @@ def parse_path(client, path):
''' '''
if not isinstance(path, unicode): if not isinstance(path, unicode):
path = path.decode('utf-8') path = path.decode('utf-8')
path = path.replace(os.sep, '/')
parts = path.split('/') parts = path.split('/')
if len(parts) >= client.folderdepth and parts[client.folderdepth-1] == 'Documents': if len(parts) >= client.folderdepth and parts[client.folderdepth-1] == 'Documents':
info = ox.movie.parse_path(u''.join( info = ox.movie.parse_path(u'/'.join(
parts[:client.folderdepth-1] + [parts[client.folderdepth-2]] parts[:client.folderdepth-1] + [parts[client.folderdepth-2]]
)) ))
else: else:
@ -115,8 +116,8 @@ def ignore_file(client, path):
if filename.startswith('._') \ if filename.startswith('._') \
or filename in ('.DS_Store', 'Thumbs.db') \ or filename in ('.DS_Store', 'Thumbs.db') \
or filename.endswith('~') \ or filename.endswith('~') \
or 'Extras/' in path \ or 'Extras' + os.sep in path \
or 'Versions/' in path \ or 'Versions' + os.sep in path \
or not os.path.exists(path) \ or not os.path.exists(path) \
or os.stat(path).st_size == 0: or os.stat(path).st_size == 0:
return True return True
@ -149,7 +150,7 @@ class Client(object):
except ValueError: except ValueError:
print "Failed to parse config at", config print "Failed to parse config at", config
sys.exit(1) sys.exit(1)
base = self._config.get('plugin.d', '~/.ox/client.d') base = self._config.get('plugin.d', os.path.join(utils.basedir(), 'client.d'))
self.load_plugins(base) self.load_plugins(base)
else: else:
self._config = config self._config = config
@ -216,10 +217,10 @@ class Client(object):
c.execute(i) c.execute(i)
conn.commit() conn.commit()
def load_plugins(self, base='~/.ox/client.d'): def load_plugins(self, base=os.path.join(utils.basedir(), 'client.d')):
global parse_path, example_path, ignore_file, encode global parse_path, example_path, ignore_file, encode
base = os.path.expanduser(base) base = os.path.expanduser(base)
for path in sorted(glob('%s/*.py' % base)): for path in sorted(glob('%s%s*.py' % (base, os.sep))):
with open(path) as fp: with open(path) as fp:
module = imp.load_source(os.path.basename(path).split('.')[0], base, fp) module = imp.load_source(os.path.basename(path).split('.')[0], base, fp)
if hasattr(module, 'parse_path'): if hasattr(module, 'parse_path'):
@ -449,15 +450,15 @@ class Client(object):
#install required programs #install required programs
if sys.platform == 'darwin': if sys.platform == 'darwin':
osext = 'macosx' osext = 'macosx'
elif sys.platform == 'win32': elif sys.platform.startswith('win'):
osext = 'exe' osext = 'exe'
else: else:
osext = 'linux' osext = 'linux'
bindir = os.path.expanduser('~/.ox/bin') bindir = os.path.join(utils.basedir(), 'bin')
ox.makedirs(bindir) ox.makedirs(bindir)
for p in ('ffmpeg', 'ffmpeg2theora'): for p in ('ffmpeg', 'ffmpeg2theora'):
path = os.path.join(bindir, p) path = os.path.join(bindir, p)
if sys.platform == 'win32': if sys.platform.startswith('win'):
p += '.exe' p += '.exe'
if not os.path.exists(path) or update: if not os.path.exists(path) or update:
print "installing %s in %s" % (p, bindir) print "installing %s in %s" % (p, bindir)
@ -471,8 +472,8 @@ class Client(object):
sys.exit(1) sys.exit(1)
name = args[0] name = args[0]
path = os.path.abspath(args[1]) path = os.path.abspath(args[1])
if not path.endswith('/'): if not path.endswith(os.sep):
path += '/' path += os.sep
if os.path.isdir(path): if os.path.isdir(path):
if name in self._config['volumes']: if name in self._config['volumes']:
print "updated %s to %s" % (name, path) print "updated %s to %s" % (name, path)
@ -490,8 +491,8 @@ class Client(object):
for name in sorted(self._config['volumes']): for name in sorted(self._config['volumes']):
path = self._config['volumes'][name] path = self._config['volumes'][name]
path = os.path.normpath(path) path = os.path.normpath(path)
if not path.endswith('/'): if not path.endswith(os.sep):
path += '/' path += os.sep
if isinstance(path, str): if isinstance(path, str):
path = path.decode('utf-8') path = path.decode('utf-8')
if os.path.exists(path): if os.path.exists(path):
@ -574,8 +575,8 @@ class Client(object):
for name in self._config['volumes']: for name in self._config['volumes']:
path = self._config['volumes'][name] path = self._config['volumes'][name]
path = os.path.normpath(path) path = os.path.normpath(path)
if not path.endswith('/'): if not path.endswith(os.sep):
path += '/' path += os.sep
if os.path.exists(path): if os.path.exists(path):
files += self.files(path)['info'] files += self.files(path)['info']
else: else:

View file

@ -4,25 +4,20 @@
# GPL 2010 # GPL 2010
from __future__ import division, with_statement from __future__ import division, with_statement
import fractions
from glob import glob
import json
import os import os
import re
import sqlite3
import subprocess import subprocess
import sys import sys
import shutil import shutil
import tempfile
import time
import ox import ox
from utils import avinfo, AspectRatio, run_command from utils import AspectRatio, run_command, basedir
def command(program): def command(program):
local = os.path.expanduser('~/.ox/bin/%s' % program) local = os.path.join(basedir(), 'bin', program)
if sys.platform.startswith('win'):
local += '.exe'
if os.path.exists(local): if os.path.exists(local):
program = local program = local
return program return program
@ -49,7 +44,7 @@ def frame(video, target, position):
cmd = ['mplayer', '-noautosub', video, '-ss', str(position), '-frames', '2', '-vo', 'png:z=9', '-ao', 'null'] cmd = ['mplayer', '-noautosub', video, '-ss', str(position), '-frames', '2', '-vo', 'png:z=9', '-ao', 'null']
print cmd print cmd
r = run_command(cmd) r = run_command(cmd)
images = glob('%s/*.png' % framedir) images = glob('%s%s*.png' % (framedir, os.sep))
if images: if images:
shutil.move(images[-1], target) shutil.move(images[-1], target)
r = 0 r = 0
@ -306,7 +301,7 @@ def video(video, target, profile, info):
if format == 'mp4': if format == 'mp4':
cmd = [command('qt-faststart'), "%s.mp4" % target, target] cmd = [command('qt-faststart'), "%s.mp4" % target, target]
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=open('/dev/null', 'w'), stdout=subprocess.PIPE if sys.platform.startswith('win') else open('/dev/null', 'w'),
stderr=subprocess.STDOUT) stderr=subprocess.STDOUT)
p.communicate() p.communicate()
os.unlink("%s.mp4" % target) os.unlink("%s.mp4" % target)

View file

@ -5,15 +5,9 @@
from __future__ import division, with_statement from __future__ import division, with_statement
import fractions import fractions
from glob import glob
import json
import os import os
import re
import sqlite3
import subprocess
import sys import sys
import shutil import subprocess
import tempfile
import time import time
import ox import ox
@ -90,3 +84,9 @@ def cleanup_tree(root):
if again: if again:
cleanup_tree(root) cleanup_tree(root)
def basedir():
base = os.path.join(os.path.expanduser('~'), '.ox')
if sys.platform.startswith('win'):
base = os.path.join(sys.environ['APPDATA'], 'pandora_client')
return base