extract tableofcontents from existing pdfs

This commit is contained in:
j 2016-01-12 14:59:09 +05:30
parent de984a344e
commit e3f0064157

View file

@ -180,6 +180,10 @@ PRAGMA journal_mode=WAL
create_default_lists() create_default_lists()
def upgrade_db(old, new=None): def upgrade_db(old, new=None):
def run_after(v):
return old <= v and new > v
if new: if new:
if old <= '20140525-92-eac91e7' and new > '20140525-92-eac91e7': if old <= '20140525-92-eac91e7' and new > '20140525-92-eac91e7':
with db.session(): with db.session():
@ -330,7 +334,7 @@ def upgrade_db(old, new=None):
if u.id != settings.USER_ID: if u.id != settings.USER_ID:
Metadata.get_or_create(u.id, i.id, i.meta, False) Metadata.get_or_create(u.id, i.id, i.meta, False)
session.commit() session.commit()
if old <= '20160111-617-206e39c' and new > '20160111-617-206e39c': if run_after('20160111-617-206e39c'):
from item.models import File from item.models import File
import media import media
with db.session() as session: with db.session() as session:
@ -344,6 +348,20 @@ def upgrade_db(old, new=None):
session.add(f.item) session.add(f.item)
session.add(f) session.add(f)
session.commit() session.commit()
if run_after('20160112-651-de984a3'):
from item.models import File
import media
with db.session() as session:
for f in File.query:
if f.info.get('extension') == 'pdf':
if not 'tableofcontents' in f.item.meta:
f.info = media.metadata(f.fullpath())
if 'tableofcontents' in f.info:
f.item.meta['tableofcontents'] = f.info['tableofcontents']
f.item.update()
session.add(f.item)
session.add(f)
session.commit()
if old <= '20140527-120-3cb9819': if old <= '20140527-120-3cb9819':
run_sql('CREATE INDEX ix_find_findvalue ON find (findvalue)') run_sql('CREATE INDEX ix_find_findvalue ON find (findvalue)')