use os.sep
This commit is contained in:
parent
dc90e04fdf
commit
96eabd9c8f
3 changed files with 31 additions and 35 deletions
|
@ -29,7 +29,7 @@ __version__ = pkg_resources.require("pandora_client")[0].version
|
|||
|
||||
socket.setdefaulttimeout(300)
|
||||
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')
|
||||
|
||||
|
@ -93,9 +93,10 @@ def parse_path(client, path):
|
|||
'''
|
||||
if not isinstance(path, unicode):
|
||||
path = path.decode('utf-8')
|
||||
path = path.replace(os.sep, '/')
|
||||
parts = path.split('/')
|
||||
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]]
|
||||
))
|
||||
else:
|
||||
|
@ -115,8 +116,8 @@ def ignore_file(client, path):
|
|||
if filename.startswith('._') \
|
||||
or filename in ('.DS_Store', 'Thumbs.db') \
|
||||
or filename.endswith('~') \
|
||||
or 'Extras/' in path \
|
||||
or 'Versions/' in path \
|
||||
or 'Extras' + os.sep in path \
|
||||
or 'Versions' + os.sep in path \
|
||||
or not os.path.exists(path) \
|
||||
or os.stat(path).st_size == 0:
|
||||
return True
|
||||
|
@ -149,7 +150,7 @@ class Client(object):
|
|||
except ValueError:
|
||||
print "Failed to parse config at", config
|
||||
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)
|
||||
else:
|
||||
self._config = config
|
||||
|
@ -216,10 +217,10 @@ class Client(object):
|
|||
c.execute(i)
|
||||
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
|
||||
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:
|
||||
module = imp.load_source(os.path.basename(path).split('.')[0], base, fp)
|
||||
if hasattr(module, 'parse_path'):
|
||||
|
@ -449,15 +450,15 @@ class Client(object):
|
|||
#install required programs
|
||||
if sys.platform == 'darwin':
|
||||
osext = 'macosx'
|
||||
elif sys.platform == 'win32':
|
||||
elif sys.platform.startswith('win'):
|
||||
osext = 'exe'
|
||||
else:
|
||||
osext = 'linux'
|
||||
bindir = os.path.expanduser('~/.ox/bin')
|
||||
bindir = os.path.join(utils.basedir(), 'bin')
|
||||
ox.makedirs(bindir)
|
||||
for p in ('ffmpeg', 'ffmpeg2theora'):
|
||||
path = os.path.join(bindir, p)
|
||||
if sys.platform == 'win32':
|
||||
if sys.platform.startswith('win'):
|
||||
p += '.exe'
|
||||
if not os.path.exists(path) or update:
|
||||
print "installing %s in %s" % (p, bindir)
|
||||
|
@ -471,8 +472,8 @@ class Client(object):
|
|||
sys.exit(1)
|
||||
name = args[0]
|
||||
path = os.path.abspath(args[1])
|
||||
if not path.endswith('/'):
|
||||
path += '/'
|
||||
if not path.endswith(os.sep):
|
||||
path += os.sep
|
||||
if os.path.isdir(path):
|
||||
if name in self._config['volumes']:
|
||||
print "updated %s to %s" % (name, path)
|
||||
|
@ -490,8 +491,8 @@ class Client(object):
|
|||
for name in sorted(self._config['volumes']):
|
||||
path = self._config['volumes'][name]
|
||||
path = os.path.normpath(path)
|
||||
if not path.endswith('/'):
|
||||
path += '/'
|
||||
if not path.endswith(os.sep):
|
||||
path += os.sep
|
||||
if isinstance(path, str):
|
||||
path = path.decode('utf-8')
|
||||
if os.path.exists(path):
|
||||
|
@ -574,8 +575,8 @@ class Client(object):
|
|||
for name in self._config['volumes']:
|
||||
path = self._config['volumes'][name]
|
||||
path = os.path.normpath(path)
|
||||
if not path.endswith('/'):
|
||||
path += '/'
|
||||
if not path.endswith(os.sep):
|
||||
path += os.sep
|
||||
if os.path.exists(path):
|
||||
files += self.files(path)['info']
|
||||
else:
|
||||
|
|
|
@ -4,25 +4,20 @@
|
|||
# GPL 2010
|
||||
from __future__ import division, with_statement
|
||||
|
||||
import fractions
|
||||
from glob import glob
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sqlite3
|
||||
import subprocess
|
||||
import sys
|
||||
import shutil
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
import ox
|
||||
|
||||
from utils import avinfo, AspectRatio, run_command
|
||||
from utils import AspectRatio, run_command, basedir
|
||||
|
||||
|
||||
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):
|
||||
program = local
|
||||
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']
|
||||
print cmd
|
||||
r = run_command(cmd)
|
||||
images = glob('%s/*.png' % framedir)
|
||||
images = glob('%s%s*.png' % (framedir, os.sep))
|
||||
if images:
|
||||
shutil.move(images[-1], target)
|
||||
r = 0
|
||||
|
@ -306,7 +301,7 @@ def video(video, target, profile, info):
|
|||
if format == 'mp4':
|
||||
cmd = [command('qt-faststart'), "%s.mp4" % target, target]
|
||||
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)
|
||||
p.communicate()
|
||||
os.unlink("%s.mp4" % target)
|
||||
|
|
|
@ -5,15 +5,9 @@
|
|||
from __future__ import division, with_statement
|
||||
|
||||
import fractions
|
||||
from glob import glob
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sqlite3
|
||||
import subprocess
|
||||
import sys
|
||||
import shutil
|
||||
import tempfile
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
import ox
|
||||
|
@ -90,3 +84,9 @@ def cleanup_tree(root):
|
|||
if again:
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue