# Path: rophako/settings.py
# class ConfigHandler(object):
#     def load_settings(self):
#     def print_settings(self):
#     def load_plugins(self):
#     def __getattr__(self, section):
# 
# Path: rophako/log.py
# class LogHandler(logging.Handler):
#     def emit(self, record):


from flask import g
from rophako.settings import Config
from rophako.log import logger
import time
import re
import glob
import os
import sys
import rophako.jsondb as JsonDB

def get_entry(post_id):
    """Load a full blog entry."""
    if not JsonDB.exists("blog/entries/{}".format(post_id)):
        return None

    db = JsonDB.get("blog/entries/{}".format(post_id))

    # If no FID, set it to the ID.
    if len(db["fid"]) == 0:
        db["fid"] = str(post_id)

    # If no "format" option, set it to HTML (legacy)
    if db.get("format", "") == "":
        db["format"] = "html"

    return db


def post_entry(post_id, fid, epoch, author, subject, avatar, categories,
               privacy, ip, emoticons, sticky, comments, format, body):
    """Post (or update) a blog entry."""

    # Fetch the index.
    index = get_index(drafts=True)

    # Editing an existing post?
    if not post_id:
        post_id = get_next_id(index)


# Path: rophako/settings.py
# class ConfigHandler(object):
#     def load_settings(self):
#     def print_settings(self):
#     def load_plugins(self):
#     def __getattr__(self, section):
# 
# Path: rophako/log.py
# class LogHandler(logging.Handler):
#     def emit(self, record):


# Path: rophako/model/blog.py
from flask import g
from rophako.settings import Config
from rophako.log import logger
import time
import re
import glob
import os
import sys
import rophako.jsondb as JsonDB


def get_entry(post_id):
    """Load a full blog entry."""
    if not JsonDB.exists("blog/entries/{}".format(post_id)):
        return None

    db = JsonDB.get("blog/entries/{}".format(post_id))

    # If no FID, set it to the ID.
    if len(db["fid"]) == 0:
        db["fid"] = str(post_id)

    # If no "format" option, set it to HTML (legacy)
    if db.get("format", "") == "":
        db["format"] = "html"

    return db


def post_entry(post_id, fid, epoch, author, subject, avatar, categories,
               privacy, ip, emoticons, sticky, comments, format, body):
    """Post (or update) a blog entry."""

    # Fetch the index.
    index = get_index(drafts=True)

    # Editing an existing post?
    if not post_id:
        post_id = get_next_id(index)


    logger.debug("Posting blog post ID {}".format(post_id))