postupdate, pdf osx fixes

This commit is contained in:
j 2014-05-20 02:08:28 +02:00
parent 2c5fe9db09
commit 326a8f75c6
5 changed files with 70 additions and 37 deletions

8
ctl
View File

@ -83,6 +83,8 @@ if [ "$1" == "ui" ]; then
exit $?
fi
if [ "$1" == "update" ]; then
cd $BASE/$NAME
OLD=`$0 version`
cd $BASE/platform
echo Update platform..
git pull
@ -90,8 +92,10 @@ if [ "$1" == "update" ]; then
cd $BASE/$NAME
git pull
find . -name '*.pyc' -exec rm "{}" \;
python2 oml setup
python2 oml update_static > /dev/null
$0 setup
$0 update_static > /dev/null
NEW=`$0 version`
$0 postupdate -o $OLD -n $NEW
exit
fi
if [ "$1" == "python" ]; then

View File

@ -45,6 +45,8 @@ manager.add_command('update', commands.Update)
#manager.add_command('start', commands.Start)
#manager.add_command('stop', commands.Stop)
manager.add_command('setup', commands.Setup)
manager.add_command('version', commands.Version)
manager.add_command('postupdate', commands.PostUpdate)
manager.add_command('shell', Shell)
manager.add_command('update_static', commands.UpdateStatic)

View File

@ -3,17 +3,48 @@
from __future__ import division
import subprocess
from os.path import join, exists, dirname
import os
from flask.ext.script import Command
from flask.ext.script import Command, Option
import settings
root_dir = dirname(settings.base_dir)
def run(*cmd):
p = subprocess.Popen(cmd)
p.wait()
return p.returncode
def get(*cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, error = p.communicate()
return stdout
def r(*cmd):
print ' '.join(cmd)
return subprocess.call(cmd)
def version(module):
os.chdir(join(root_dir, module))
version = get('git', 'log', '-1', '--format=%cd', '--date=iso').split(' ')[0].replace('-', '')
version += '-' + get('git', 'rev-list', 'HEAD', '--count').strip()
version += '-' + get('git', 'describe', '--always').strip()
os.chdir(root_dir)
return version
class Version(Command):
"""
Print current version
"""
def run(self):
print version('openmedialibrary')
class Debug(Command):
"""
Start Open Media Library in debug mode
Start in debug mode
"""
def run(self):
pass
@ -39,25 +70,35 @@ class Update(Command):
def run(self):
pass
class PostUpdate(Command):
"""
Called by update to fix stuff
"""
def get_options(self):
return [
Option('-o', '--old', dest='old'),
Option('-n', '--new', dest='new'),
]
def run(selfi, old, new):
pass
class Setup(Command):
"""
setup new node
Setup new node
"""
def run(self):
r('./ctl', 'db', 'upgrade')
import setup
import settings
setup.create_default_lists()
settings.db.session.connection().execute("PRAGMA journal_mode=WAL")
settings.db.session.commit()
class UpdateStatic(Command):
"""
update static files
Update static files
"""
def run(self):
import settings
oxjs = os.path.join(settings.static_path, 'oxjs')
if not os.path.exists(oxjs):
r('git', 'clone', 'https://git.0x2620.org/oxjs.git', oxjs)
@ -68,39 +109,17 @@ class UpdateStatic(Command):
class Release(Command):
"""
release new version
Release new version
"""
def run(self):
print 'checking...'
import settings
import os
import subprocess
import json
import hashlib
import ed25519
from os.path import join, exists, dirname
root_dir = dirname(settings.base_dir)
os.chdir(root_dir)
def run(*cmd):
p = subprocess.Popen(cmd)
p.wait()
return p.returncode
def get(*cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, error = p.communicate()
return stdout
def version(module):
os.chdir(join(root_dir, module))
version = get('git', 'log', '-1', '--format=%cd', '--date=iso').split(' ')[0].replace('-', '')
version += '-' + get('git', 'rev-list', 'HEAD', '--count').strip()
version += '-' + get('git', 'describe', '--always').strip()
os.chdir(root_dir)
return version
with open(os.path.expanduser('~/Private/openmedialibrary_release.key')) as fd:
SIG_KEY=ed25519.SigningKey(fd.read())
SIG_ENCODING='base64'

View File

@ -37,13 +37,17 @@ def ql_cover(pdf):
]
p = subprocess.Popen(cmd)
p.wait()
image = glob('%s/*' % tmp)[0]
with open(image, 'rb') as fd:
data = fd.read()
image = glob('%s/*' % tmp)
if image:
image = image[0]
with open(image, 'rb') as fd:
data = fd.read()
else:
logger.debug('qlmanage did not create cover for %s', pdf)
data = None
shutil.rmtree(tmp)
return data
def page(pdf, page):
image = tempfile.mkstemp('.jpg')[1]
cmd = [
@ -133,7 +137,10 @@ def extract_text(pdf):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if sys.platform == 'darwin':
stdout = stderr.split('kMDItemTextContent = "')[-1].split('\n')[0][:-2]
if 'kMDItemTextContent' in stderr:
stdout = stderr.split('kMDItemTextContent = "')[-1].split('\n')[0][:-2]
else:
stdout = ''
return stdout.strip()
def extract_isbn(text):

View File

@ -232,6 +232,7 @@ def sortLists(data):
n += 1
models.db.session.add(l)
models.db.session.commit()
logger.debug('FIXME: broadcast orderlist event here')
return {}
actions.register(sortLists, cache=False)