# Path: peanut/model.py
# class Post(BaseModel):
#     """Post model
#     """
# 
#     layout = 'post'
# 
#     def __init__(self, title, slug, raw=None, content=None, meta=None):
#         self.title = title
#         self.slug = url_safe(slug)
#         self.content = content
#         self.raw = raw
# 
#         meta = meta or {}
#         self.date = meta.pop('date', None) or datetime.now()
#         self.publish = meta.pop('publish', True)
#         self.layout = meta.pop('layout', Post.layout)
#         self.top = meta.pop('top', False)
#         self.tag_titles = meta.pop('tags', [])
# 
#         image = meta.pop('image', None)
#         if isinstance(image, dict):
#             self.image = image.get('feature', None)
#         else:
#             self.image = image
# 
#         self.meta = meta
# 
#     @property
#     def tags(self):
#         return [Tag(t) for t in self.tag_titles]
# 
#     def __getattr__(self, key):
#         try:
#             return super(Post, self).__getattr__(key)
#         except:
#             pass
#         return self.meta.get(key)
# 
#     def __lt__(self, other):
#         return self.date < other.date
# 
# Path: peanut/options.py
# class ValidationError(Exception):
# class LoadingError(ValidationError):
# class Option(dict):
#     def __init__(self, msg=None):
#     def __init__(self, *args, **kwargs):
#     def __setitem__(self, key, value):
#     def __getitem__(self, name):
#     def __delitem__(self, name):
#     def __real_update(self, key, value):
#     def update(self, *args, **kwargs):
# def verify_path():
# def verify_theme():
# def verify_configs():
# def load_yaml(path):
# def load_configs(path):
# 
# Path: peanut/options.py
# class ValidationError(Exception):
#     """Configs validation exception"""
#     def __init__(self, msg=None):
#         super(ValidationError, self).__init__(msg)
#         self.msg = msg
# 
# Path: peanut/template.py
# class Template(object):
#     """Template"""
# 
#     def __init__(self, path, filters=None, **kwargs):
#         loader = ChoiceLoader([
#             SmartLoader(path),
#             SmartLoader(get_resource('themes/default')),
#         ])
#         self.env = jinja2.Environment(
#             loader=loader,
#             lstrip_blocks=True,
#             trim_blocks=True,
#         )
#         # Update filters
#         if isinstance(filters, dict):
#             self.env.filters.update(filters)
# 
#         # Update global namesapce
#         self.env.globals.update(kwargs)
# 
#     def update_context(self, **kwargs):
#         """Update global context
#         """
#         self.env.globals.update(kwargs)
# 
#     def render(self, name, **context):
#         """Render template with name and context
#         """
#         template = self.env.get_template(name)
#         return template.render(**context)
# 
# Path: peanut/context.py
# def get_filters(config):
#     """Get all filters
#     """
#     return {
#         'asset': partial(asset, config),
#         'strftime': strftime,
#         'abs_url': partial(abs_url, config),
#     }
# 
# Path: peanut/utils.py
# def list_dir(path):
#     """List all unhidden files
#     """
#     for filename in os.listdir(path):
#         if filename.startswith('.'):
#             continue
#         if os.path.isdir(filename):
#             continue
#         yield to_u(os.path.join(path, filename))
# 
# def get_resource(relative_path):
#     package_path = os.path.abspath(os.path.split(__file__)[0])
#     return os.path.join(package_path, relative_path)
# 
# Path: peanut/ghost.py
# def get_token(url, user, password):
#     if not url or not user or not password:
#         logging.error('Invalid url/username/password')
#         return None
# 
#     headers = {'Content-Type': 'application/x-www-form-urlencoded'}
#     data = ('grant_type=password'
#             '&username={}'
#             '&password={}'
#             '&client_id=ghost-admin'
#             '&client_secret=8b4a248000cd').format(user, password)
# 
#     path = api_path(url, 'authentication/token')
#     r = session.post(path, data=data, headers=headers)
#     if r.status_code != 200:
#         logging.error('Failed to get token, please check your username or password')
#         return None
# 
#     return r.json()['access_token']
# 
# def push(url, token, posts):
#     headers = {
#         'Authorization': 'Bearer '+token,
#         'Content-Type': 'application/json'
#     }
#     
#     path = api_path(url, 'posts/')
#     
#     for post in posts:
#         logging.info('Pushing %s', post.title, prefix='   ↳  ')
#         posts_json = {'posts': [post_to_json(post)]}
#         r = session.post(path, headers=headers, json=posts_json)
#         if r.status_code != 201:
#             logging.error('Push post failed, status code: {}, {}'.format(r.status_code, r.text))


import os
import six
import shutil
import logging
import peanut
import peanut.reader as reader
import peanut.writer as writer
from peanut.model import Post
from peanut.options import configs, load_configs, verify_configs
from peanut.options import ValidationError
from peanut.template import Template
from peanut.context import get_filters
from peanut.utils import list_dir, get_resource
from peanut.ghost import get_token, push
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import unicode_literals




try:
    FileNotFoundError
except:

# Path: peanut/model.py
# class Post(BaseModel):
#     """Post model
#     """
# 
#     layout = 'post'
# 
#     def __init__(self, title, slug, raw=None, content=None, meta=None):
#         self.title = title
#         self.slug = url_safe(slug)
#         self.content = content
#         self.raw = raw
# 
#         meta = meta or {}
#         self.date = meta.pop('date', None) or datetime.now()
#         self.publish = meta.pop('publish', True)
#         self.layout = meta.pop('layout', Post.layout)
#         self.top = meta.pop('top', False)
#         self.tag_titles = meta.pop('tags', [])
# 
#         image = meta.pop('image', None)
#         if isinstance(image, dict):
#             self.image = image.get('feature', None)
#         else:
#             self.image = image
# 
#         self.meta = meta
# 
#     @property
#     def tags(self):
#         return [Tag(t) for t in self.tag_titles]
# 
#     def __getattr__(self, key):
#         try:
#             return super(Post, self).__getattr__(key)
#         except:
#             pass
#         return self.meta.get(key)
# 
#     def __lt__(self, other):
#         return self.date < other.date
# 
# Path: peanut/options.py
# class ValidationError(Exception):
# class LoadingError(ValidationError):
# class Option(dict):
#     def __init__(self, msg=None):
#     def __init__(self, *args, **kwargs):
#     def __setitem__(self, key, value):
#     def __getitem__(self, name):
#     def __delitem__(self, name):
#     def __real_update(self, key, value):
#     def update(self, *args, **kwargs):
# def verify_path():
# def verify_theme():
# def verify_configs():
# def load_yaml(path):
# def load_configs(path):
# 
# Path: peanut/options.py
# class ValidationError(Exception):
#     """Configs validation exception"""
#     def __init__(self, msg=None):
#         super(ValidationError, self).__init__(msg)
#         self.msg = msg
# 
# Path: peanut/template.py
# class Template(object):
#     """Template"""
# 
#     def __init__(self, path, filters=None, **kwargs):
#         loader = ChoiceLoader([
#             SmartLoader(path),
#             SmartLoader(get_resource('themes/default')),
#         ])
#         self.env = jinja2.Environment(
#             loader=loader,
#             lstrip_blocks=True,
#             trim_blocks=True,
#         )
#         # Update filters
#         if isinstance(filters, dict):
#             self.env.filters.update(filters)
# 
#         # Update global namesapce
#         self.env.globals.update(kwargs)
# 
#     def update_context(self, **kwargs):
#         """Update global context
#         """
#         self.env.globals.update(kwargs)
# 
#     def render(self, name, **context):
#         """Render template with name and context
#         """
#         template = self.env.get_template(name)
#         return template.render(**context)
# 
# Path: peanut/context.py
# def get_filters(config):
#     """Get all filters
#     """
#     return {
#         'asset': partial(asset, config),
#         'strftime': strftime,
#         'abs_url': partial(abs_url, config),
#     }
# 
# Path: peanut/utils.py
# def list_dir(path):
#     """List all unhidden files
#     """
#     for filename in os.listdir(path):
#         if filename.startswith('.'):
#             continue
#         if os.path.isdir(filename):
#             continue
#         yield to_u(os.path.join(path, filename))
# 
# def get_resource(relative_path):
#     package_path = os.path.abspath(os.path.split(__file__)[0])
#     return os.path.join(package_path, relative_path)
# 
# Path: peanut/ghost.py
# def get_token(url, user, password):
#     if not url or not user or not password:
#         logging.error('Invalid url/username/password')
#         return None
# 
#     headers = {'Content-Type': 'application/x-www-form-urlencoded'}
#     data = ('grant_type=password'
#             '&username={}'
#             '&password={}'
#             '&client_id=ghost-admin'
#             '&client_secret=8b4a248000cd').format(user, password)
# 
#     path = api_path(url, 'authentication/token')
#     r = session.post(path, data=data, headers=headers)
#     if r.status_code != 200:
#         logging.error('Failed to get token, please check your username or password')
#         return None
# 
#     return r.json()['access_token']
# 
# def push(url, token, posts):
#     headers = {
#         'Authorization': 'Bearer '+token,
#         'Content-Type': 'application/json'
#     }
#     
#     path = api_path(url, 'posts/')
#     
#     for post in posts:
#         logging.info('Pushing %s', post.title, prefix='   ↳  ')
#         posts_json = {'posts': [post_to_json(post)]}
#         r = session.post(path, headers=headers, json=posts_json)
#         if r.status_code != 201:
#             logging.error('Push post failed, status code: {}, {}'.format(r.status_code, r.text))


# Path: peanut/site.py
import os
import six
import shutil
import logging
import peanut
import peanut.reader as reader
import peanut.writer as writer
from peanut.model import Post
from peanut.options import configs, load_configs, verify_configs
from peanut.options import ValidationError
from peanut.template import Template
from peanut.context import get_filters
from peanut.utils import list_dir, get_resource
from peanut.ghost import get_token, push

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import unicode_literals




try:
    FileNotFoundError
except:

    FileNotFoundError = IOError