Commit bb7063a5 authored by Patrick van der Leer's avatar Patrick van der Leer
Browse files

Fixes a lot and more :)

parent 3977ae7b
......@@ -4,6 +4,9 @@ from logging.handlers import RotatingFileHandler
from flask import Flask
from flask_cors import CORS
import safrs
from safrs import SAFRSAPI
from safrs import SAFRSJSONEncoder
from eBookHub.config import ProdConfig
......@@ -46,10 +49,10 @@ def configure_blueprints(app):
def create_api(app, host='localhost', port=5000, api_prefix=''):
from safrs import SAFRSAPI
from .models import Author, Book, BookEdition, BookSerie, Genre, Publisher, User
safrs.DB = ext.db
api = SAFRSAPI(app, host='{}:{}'.format(host, port), prefix=api_prefix)
api = SAFRSAPI(app, host='{}:{}'.format(host, port), prefix=api_prefix, description="eBookHUB backend API")
app.json_encoder = SAFRSJSONEncoder
api.expose_object(Author)
......
import glob
import os
import time
from threading import RLock
from eBookHub.parser.filename import FilenameParser
lock = RLock()
def process_blackhole(blackhole_path):
print("1 " + time.strftime("%A, %d. %B %Y %I:%M:%S %p"))
time.sleep(1)
print("2 " + time.strftime("%A, %d. %B %Y %I:%M:%S %p"))
parser = FilenameParser()
for file in glob.iglob('{}/*'.format(blackhole_path), recursive=True):
ff = parser.parse(file)
def process_blackhole_job(blackhole_path):
......
......@@ -4,5 +4,12 @@ from apscheduler.schedulers.background import BackgroundScheduler
class Scheduler(BackgroundScheduler):
app = None
def init_app(self, app):
self.app = app
atexit.register(lambda: self.shutdown())
def start(self, *args, **kwargs):
if self._thread and not self._thread.is_alive():
super().start(*args, **kwargs)
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, prompt_bool
from flask_script import Manager
from eBookHub import init, db
from eBookHub.utils import get_config
database_manager = Manager(usage="Perform database operations")
@database_manager.command
def drop():
"""Drops database tables"""
if prompt_bool("Are you sure you want to lose all your data"):
db.drop_all()
@database_manager.command
def create(default_data=True, sample_data=False):
"""Creates database tables from sqlalchemy models"""
db.create_all()
@database_manager.command
def recreate(default_data=True, sample_data=False):
"""Recreates database tables (same as issuing 'drop' and then 'create')"""
drop()
create(default_data, sample_data)
from managers import database_manager, parser_manager
app = init(get_config())
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', database_manager)
manager.add_command('database', database_manager)
manager.add_command('parser', parser_manager)
manager.add_command('alembic', MigrateCommand)
if __name__ == "__main__":
......
from .db import database_manager
from .parser import parser_manager
__all__ = (
database_manager,
parser_manager
)
from flask import current_app
from flask_script import Manager, prompt_bool
from eBookHub import db
database_manager = Manager(current_app, usage="Perform database operations")
@database_manager.command
def drop():
"""Drops database tables"""
if prompt_bool("Are you sure you want to lose all your data"):
db.drop_all()
@database_manager.command
def create(default_data=True, sample_data=False):
"""Creates database tables from sqlalchemy models"""
db.create_all()
@database_manager.command
def recreate(default_data=True, sample_data=False):
"""Recreates database tables (same as issuing 'drop' and then 'create')"""
drop()
create(default_data, sample_data)
from flask import current_app
from flask_script import Manager
from eBookHub.jobs.blackhole import process_blackhole
parser_manager = Manager(current_app, usage="Perform parser tests/operations")
@parser_manager.command
@parser_manager.option('-p', '--path', dest='path', default=None)
def process_blackhole(path=None):
if path is None:
app = parser_manager.app
path = app.config['BLACKHOLE_PATH']
process_blackhole(path)
......@@ -33,22 +33,6 @@ class ModelTestCase(MyTestCase):
"""Test factory instance"""
self.assertEqual(type(self.factory()), self.model)
def test_get_by(self):
"""Get model via get_by"""
inst = self.factory()
inst.save()
retrieved = self.model.get_by(id=inst.id)
assert retrieved == inst
def test_get_by_id(self):
"""Get model by ID"""
inst = self.factory()
inst.save()
retrieved = self.model.get(id=inst.id)
assert retrieved == inst
def test_delete(self):
"""Save and delete model from factory"""
inst = self.factory()
......@@ -66,8 +50,3 @@ class ModelTestCase(MyTestCase):
assert self.model.get(pk).deleted
inst.delete(hard_delete=True)
assert self.model.get(pk) is None
def test_serialize(self):
"""Serialize model"""
inst = self.factory()
inst.serialize()
# -*- coding: utf-8 -*-
import glob
import os
from unittest import TestCase
from eBookHub.parser.filename import FilenameParser
......@@ -40,7 +42,17 @@ class FileNameParserTestCase(TestCase):
else:
self.assertEqual(value, verified_data[key])
def test_parser(self):
def test_parser_files(self):
for file in glob.iglob('testfiles/books/*', recursive=True):
if not os.path.isfile(file):
continue
ext = os.path.splitext(file)[:-1]
if ext not in ["epub, pdf"]:
continue
self.parser.parse(file.lstrip("testfiles/books/"))
def test_parser_lines(self):
lines = [
'Aardenburg, A van - [Bas Banning 03] Bas Banning en de Geheimzinnige Kabelbaan',
'Aardenburg, A van/Bas Banning 03/Bas Banning en de Geheimzinnige Kabelbaan',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment