class CategoryManager(base_manager.BaseManager):
    def __init__(self, db):
    def action(self, language):
    def __name_ok(self, name, language): class ExportManager(base_manager.BaseManager):
    def __init__(self, db):
    def action(self, static_path, image_path, id, recipe_json): class RecipeManager(base_manager.BaseManager):
    HINT_COOKIE = 'show_hint'
    HINT_DELETE = 'delete'
    HINT_EDIT = 'edit'
    HINT_EXISTS = 'exists'
    HINT_NAME = 'last_name'
    HINT_NEW = 'new'
    HINT_NEW_EXISTS = 'new-exists'
    def __init__(self, db):
    def action(self, language, indexer, static_path, image_path, recipe_json,
               id=None):
    def __check_img_extension(self, extension, language):
    def __create_img_dir(static_path, image_root_path):
    def __finalize_recipe(self, recipe, is_new, indexer):
    def __get_image_path(static_path, image_root_path, name, extension):
    def __read_categories(self):
    def __read_images(self, language, static_path, image_root_path):
    def __read_synonyms(self):
    def __read_tags(self):
    def __read_urls(self):
    def __save_image(static_path, image_path, image_bytes):
    def __show_hints(self, language): class TagManager(base_manager.BaseManager):
    def __init__(self, db):
    def action(self, language):
    def __name_ok(self, name, language): class UserManager(base_manager.BaseManager):
    SESSION_COOKIE = 'session'
    USER_NAME_COOKIE = 'user'
    def __init__(self, db):
    def action(self, language, pw_hash_iterations, admin_user):
    def current_user(self):
    def login(self, language, pw_hash_iterations, admin_user):
    def logout(self):
    def validate_login(self, pw_hash_iterations, admin_user):
    def __action_admin(self, language, pw_hash_iterations):
    def __action_user(self, language, pw_hash_iterations):
    def __admin_hash(self, admin_user, iterations):
    def __generate_pw_hash(self, password, salt, iterations):
    def __generate_salt(self): class Category:
    def __init__(self, id=None, name=''):
    def __str__(self):
    def delete(self, db):
    def find_all(db):
    def find_name(db, name):
    def find_pk(db, id):
    def find_recipe(db, recipe):
    def from_row(row):
    def is_new(self):
    def name_exists(db, name):
    def save(self, db):
    def __generic_find(db, query, params): class Recipe:
    def __init__(self, categories=[], description='', id=None, info='',
                 ingredients='', rating=None, serving_size='', title='',
                 tags=[], urls=[], synonyms=[], images=[], author=None):
    def __str__(self):
    def count_all(db):
    def delete(self, db):
    def find_all(db):
    def find_category(db, category):
    def find_pk(db, id):
    def find_random(db, num):
    def from_row(db, row):
    def is_new(self):
    def title_exists(db, title):
    def save(self, db):
    def __delete_images(self, db, force=False):
    def __delete_recipe_has_category(self, db):
    def __delete_recipe_has_tag(self, db):
    def __delete_synonyms(self, db):
    def __delete_urls(self, db):
    def __generic_find(db, query, params): class Tag:
    def __init__(self, id=None, name='', synonym_of=None, synonyms=[]):
    def __str__(self):
    def delete(self, db):
    def find_all(db):
    def find_name(db, name):
    def find_pk(db, id):
    def find_recipe(db, recipe):
    def find_synonyms(self, db):
    def from_row(db, row, find_synonyms=True):
    def is_new(self):
    def name_exists(db, name):
    def save(self, db):
    def __generic_find(db, query, params): class TranslatorNotInitializedError(Exception):
class Translator:
    def current_language(default_language):
    def init(language, path):
    def instance(language): class MigrationManager:
    CONFIG_VERSION = 'version'
    EMPTY_DB_FILE = 'empty-db.sqlite'
    def __init__(self, home, db_file):
    def migrate(self):
    def __create_db(self):
    def __create_tags(self, db, tags):
    def __is_version(self, db, version):
    def __tags_rename_brackets(self, db):
    def __tags_rename_vermouth(self, db):
    def __update_version(self, db, version): class Indexer:
    def __init__(self, index_path):
    def close_index(self):
    def fill_index(writer, recipes):
    def open_index(self, schema):
    def remove_from_index(writer, recipes):
    def remove_index(self):
    def scheme():
    def searcher(self): class Searcher:
    DEFAULT_FIELD = 'titletags'
    def __init__(self, indexer):
    def search(self, db, query_text):
import bottle
import bottle_sqlite as sqlite
import configparser
import collections
import os
import random
import sqlite3
from action import category_manager
from action import export_manager
from action import recipe_manager
from action import tag_manager
from action import user_manager
from entity import category
from entity import recipe
from entity import tag
from helper import translator
from migration import migration_manager
from search import indexer as indexer_class
from search import searcher as searcher_class
#!/usr/bin/python
# -*- coding: utf-8 -*-



# Configuration ################################################################
config = configparser.ConfigParser()
config.read('default.config')
ADMIN_USER = config.get('Default', 'ADMIN_USER')
DB_FILE = config.get('Default', 'DB_FILE')
DEBUG = config.getboolean('Default', 'DEBUG')
ENABLE_USERS = config.getboolean('Default', 'ENABLE_USERS')
HOME = config.get('Default', 'HOME')
HOST = config.get('Default', 'HOST')
INDEX_PATH = config.get('Default', 'INDEX_PATH')
LANGUAGE = config.get('Default', 'LANGUAGE')
PORT = config.getint('Default', 'PORT')
PW_HASH_ITERATIONS = config.getint('Default', 'PW_HASH_ITERATIONS')
RANDOM_RECIPES = config.getint('Default', 'RANDOM_RECIPES')
RENEW_INDEX = config.getboolean('Default', 'RENEW_INDEX')
STATIC_PATH = config.get('Default', 'STATIC_PATH')
TRANSLATION_PATH = config.get('Default', 'TRANSLATION_PATH')

if os.path.exists('user.config'):
    config.read('user.config')
    ADMIN_USER = config.get('Default', 'ADMIN_USER', fallback=ADMIN_USER)
    DB_FILE = config.get('Default', 'DB_FILE', fallback=DB_FILE)
    DEBUG = config.getboolean('Default', 'DEBUG', fallback=DEBUG)
    ENABLE_USERS = config.getboolean('Default', 'ENABLE_USERS', fallback=ENABLE_USERS)
    HOME = config.get('Default', 'HOME', fallback=HOME)
    HOST = config.get('Default', 'HOST', fallback=HOST)
    INDEX_PATH = config.get('Default', 'INDEX_PATH', fallback=INDEX_PATH)
    LANGUAGE = config.get('Default', 'LANGUAGE', fallback=LANGUAGE)
    PORT = config.getint('Default', 'PORT', fallback=PORT)
    PW_HASH_ITERATIONS = config.getint('Default', 'PW_HASH_ITERATIONS', fallback=PW_HASH_ITERATIONS)
    RANDOM_RECIPES = config.getint('Default', 'RANDOM_RECIPES', fallback=RANDOM_RECIPES)
    RENEW_INDEX = config.getboolean('Default', 'RENEW_INDEX', fallback=RENEW_INDEX)
    STATIC_PATH = config.get('Default', 'STATIC_PATH', fallback=STATIC_PATH)
    TRANSLATION_PATH = config.get('Default', 'TRANSLATION_PATH', fallback=TRANSLATION_PATH)

IMAGE_PATH = '/img/upload/'
INDEX_PATH += '/'
RECIPE_JSON = 'recipe.json'


# Initialization ###############################################################
app = bottle.Bottle()

# Plugins
sqlPlugin = sqlite.Plugin(dbfile=HOME+DB_FILE)
app.install(sqlPlugin)

# Migration
migration = migration_manager.MigrationManager(HOME, DB_FILE)
migration.migrate()

# Translation
LANGUAGES = collections.OrderedDict()
LANGUAGES['de_DE'] = 'Deutsch'
LANGUAGES['sw_DE'] = 'Deutsch (Schwäbisch)'
LANGUAGES['de_CH'] = 'Deutsch (Schweiz)'
LANGUAGES['en_US'] = 'English'
LANGUAGES['fr_FR'] = 'Français'
LANGUAGES['fi_FI'] = 'Suomi'
for locale in LANGUAGES:

    translator.Translator.init(locale, TRANSLATION_PATH)