Ejemplo n.º 1
0
 def __init__(self, site, settings, message):
     super(Publisher, self).__init__()
     self.logger = getLoggerWithNullHandler('hyde.engine.%s' %
                                            self.__class__.__name__)
     self.site = site
     self.message = message
     self.initialize(settings)
Ejemplo n.º 2
0
    def load_publisher(site, publisher, message):
        logger = getLoggerWithNullHandler('hyde.engine.publisher')
        try:
            settings = attrgetter("publisher.%s" % publisher)(site.config)
        except AttributeError:
            settings = False

        if not settings:
            # Find the first configured publisher
            try:
                publisher = site.config.publisher.__dict__.iterkeys().next()
                logger.warning("No default publisher configured. Using: %s" %
                               publisher)
                settings = attrgetter("publisher.%s" % publisher)(site.config)
            except (AttributeError, StopIteration):
                logger.error("Cannot find the publisher configuration: %s" %
                             publisher)
                raise

        if not hasattr(settings, 'type'):
            logger.error("Publisher type not specified: %s" % publisher)
            raise Exception("Please specify the publisher type in config.")

        pub_class = load_python_object(settings.type)
        return pub_class(site, settings, message)
Ejemplo n.º 3
0
    def load_publisher(site, publisher, message):
        logger = getLoggerWithNullHandler('hyde.engine.publisher')
        try:
            settings = attrgetter("publisher.%s" % publisher)(site.config)
        except AttributeError:
            settings = False

        if not settings:
            # Find the first configured publisher
            try:
                publisher = site.config.publisher.__dict__.iterkeys().next()
                logger.warning("No default publisher configured. Using: %s" % publisher)
                settings = attrgetter("publisher.%s" % publisher)(site.config)
            except (AttributeError, StopIteration):
                logger.error(
                    "Cannot find the publisher configuration: %s" % publisher)
                raise

        if not hasattr(settings, 'type'):
            logger.error(
                "Publisher type not specified: %s" % publisher)
            raise Exception("Please specify the publisher type in config.")

        pub_class = load_python_object(settings.type)
        return pub_class(site, settings, message)
Ejemplo n.º 4
0
 def __init__(self, site, settings, message):
     super(Publisher, self).__init__()
     self.logger = getLoggerWithNullHandler(
                         'hyde.engine.%s' % self.__class__.__name__)
     self.site = site
     self.message = message
     self.initialize(settings)
Ejemplo n.º 5
0
 def load_publisher(site, publisher, message):
     try:
         settings = attrgetter("publisher.%s" % publisher)(site.config)
     except AttributeError:
         logger = getLoggerWithNullHandler('hyde.engine.publisher')
         logger.error("Cannot find the publisher configuration: %s" %
                      publisher)
         raise
     if not hasattr(settings, 'type'):
         logger.error("Publisher type not specified: %s" % publisher)
         raise Exception("Please specify the publisher type in config.")
     pub_class = load_python_object(settings.type)
     return pub_class(site, settings, message)
Ejemplo n.º 6
0
    def __init__(self, site):
        super(Plugin, self).__init__()
        self.site = site
        self.logger = getLoggerWithNullHandler(
                            'hyde.engine.%s' % self.__class__.__name__)
        self.template = None


        opts = Expando({})
        try:
            opts = getattr(self.site.config, self.plugin_name)
        except AttributeError:
            pass
        self.settings = opts
Ejemplo n.º 7
0
 def load_publisher(site, publisher, message):
     try:
         settings = attrgetter("publisher.%s" % publisher)(site.config)
     except AttributeError:
         logger = getLoggerWithNullHandler('hyde.engine.publisher')
         logger.error(
             "Cannot find the publisher configuration: %s" % publisher)
         raise
     if not hasattr(settings, 'type'):
         logger.error(
             "Publisher type not specified: %s" % publisher)
         raise Exception("Please specify the publisher type in config.")
     pub_class = load_python_object(settings.type)
     return pub_class(site, settings, message)
Ejemplo n.º 8
0
Archivo: server.py Proyecto: dcode/hyde
"""
import os
import select
import threading
import urlparse
import urllib
from datetime import datetime
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
from hyde.fs import File, Folder
from hyde.site import Site
from hyde.generator import Generator
from hyde.exceptions import HydeException

from hyde.util import getLoggerWithNullHandler
logger = getLoggerWithNullHandler('hyde.server')

class HydeRequestHandler(SimpleHTTPRequestHandler):
    """
    Serves files by regenerating the resource (or)
    everything when a request is issued.
    """

    def do_GET(self):
        """
        Identify the requested path. If the query string
        contains `refresh`, regenerat the entire site.
        Otherwise, regenerate only the requested resource
        and serve.
        """
        self.server.request_time = datetime.now()
Ejemplo n.º 9
0
"""
Jinja template utilties
"""

from hyde.fs import File, Folder
from hyde.model import Expando
from hyde.template import HtmlWrap, Template
from hyde.site import Resource
from hyde.util import getLoggerWithNullHandler, getLoggerWithConsoleHandler

from jinja2 import contextfunction, Environment, FileSystemLoader
from jinja2 import environmentfilter, Markup, Undefined, nodes
from jinja2.ext import Extension
from jinja2.exceptions import TemplateError

logger = getLoggerWithNullHandler('Jinja2')

class SilentUndefined(Undefined):
    """
    A redefinition of undefined that eats errors.
    """
    def __getattr__(self, name):
        return self

    __getitem__ = __getattr__

    def __call__(self, *args, **kwargs):
        return self

@contextfunction
def media_url(context, path):
Ejemplo n.º 10
0
Archivo: syntax.py Proyecto: rlz/hyde
Interpret files `*.html.rst` as reStructuredText sources, `*.html.md`, as Markdown
and `*.html.tx` as Textile.

Replace content of a file by

    {% filter <filtername> %}
    ...
    {% endfilter %}

"""

from hyde.plugin import Plugin

from hyde.util import getLoggerWithNullHandler

logger = getLoggerWithNullHandler('hyde.ext.plugins.syntax')


class SyntaxPlugin(Plugin):
    """The plugin class for rendering sphinx-generated documentation."""

    extensions_map = {
        "rst": "restructuredtext",
        "md": "markdown",
        "tx": "textile"
    }
    extensions = [".html." + i for i in extensions_map.keys()]

    def __init__(self, site):
        self.generators = {}
        super(SyntaxPlugin, self).__init__(site)
Ejemplo n.º 11
0
fnamtch, shutil and distutils. This module attempts to make the right choices
for common operations to provide a single interface.
"""

import codecs
from datetime import datetime
import mimetypes
import os
import shutil
from distutils import dir_util
import functools
import fnmatch

from hyde.util import getLoggerWithNullHandler

logger = getLoggerWithNullHandler('fs')

# pylint: disable-msg=E0611

__all__ = ['File', 'Folder']


class FS(object):
    """
    The base file system object
    """
    def __init__(self, path):
        super(FS, self).__init__()
        if path == os.sep:
            self.path = path
        else:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""
import datetime
import email
import mimetypes
import optparse
import os
import sys
import time

from hyde.fs import File, Folder
from hyde.publisher import Publisher

from hyde.util import getLoggerWithNullHandler
logger = getLoggerWithNullHandler('hyde.ext.publishers.aws')

# Make sure boto is available
try:
    import boto
    import boto.exception
except ImportError:
    raise ImportError, "The boto Python library is not installed."
    
try:
    from fs.osfs import OSFS
    from fs.path import pathjoin
    from fs.opener import fsopendir
except ImportError:
    logger.error("The AWS publisher requires PyFilesystem v0.4 or later.")
    logger.error("`pip install -U fs` to get it.")
Ejemplo n.º 13
0
#  We need absolute import so that we can import the main "sphinx"
#  module even though this module is also called "sphinx". Ugh.
from __future__ import absolute_import

import os
import sys
import json
import tempfile 

from hyde.plugin import Plugin
from hyde.fs import File, Folder
from hyde.model import Expando
from hyde.ext.plugins.meta import MetaPlugin as _MetaPlugin

from hyde.util import getLoggerWithNullHandler
logger = getLoggerWithNullHandler('hyde.ext.plugins.sphinx')

try:
    import sphinx
    from sphinx.builders.html import JSONHTMLBuilder
    from sphinx.util.osutil import SEP
except ImportError:
    logger.error("The sphinx plugin requires sphinx.")
    logger.error("`pip install -U sphinx` to get it.")
    raise


class SphinxPlugin(Plugin):
    """The plugin class for rendering sphinx-generated documentation."""

    def __init__(self, site):
Ejemplo n.º 14
0
 def __init__(self, sitepath):
     self.sitepath = sitepath
     self.logger = getLoggerWithNullHandler(self.__class__.__name__)
Ejemplo n.º 15
0
"""

import os
import getpass
import zipfile
import tempfile
import httplib
import urlparse
from base64 import standard_b64encode
import ConfigParser

from hyde.fs import File, Folder
from hyde.publisher import Publisher

from hyde.util import getLoggerWithNullHandler
logger = getLoggerWithNullHandler('hyde.ext.publishers.pypi')


class PyPI(Publisher):
    def initialize(self, settings):
        self.settings = settings
        self.project = settings.project
        self.url = getattr(settings, "url", "https://pypi.python.org/pypi/")
        self.username = getattr(settings, "username", None)
        self.password = getattr(settings, "password", None)
        self.prompt_for_credentials()

    def prompt_for_credentials(self):
        pypirc_file = os.path.expanduser("~/.pypirc")
        if not os.path.isfile(pypirc_file):
            pypirc = None
Ejemplo n.º 16
0
import itertools
from urllib import quote, unquote

from hyde.fs import File, Folder
from hyde.model import Expando
from hyde.template import HtmlWrap, Template
from hyde.util import getLoggerWithNullHandler
from operator import attrgetter

from jinja2 import contextfunction, Environment
from jinja2 import FileSystemLoader, FileSystemBytecodeCache
from jinja2 import contextfilter, environmentfilter, Markup, Undefined, nodes
from jinja2.ext import Extension
from jinja2.exceptions import TemplateError

logger = getLoggerWithNullHandler('hyde.engine.Jinja2')


class SilentUndefined(Undefined):
    """
    A redefinition of undefined that eats errors.
    """
    def __getattr__(self, name):
        return self

    __getitem__ = __getattr__

    def __call__(self, *args, **kwargs):
        return self

Ejemplo n.º 17
0
 def __init__(self, site):
     super(Plugin, self).__init__()
     self.site = site
     self.logger = getLoggerWithNullHandler(self.__class__.__name__)
Ejemplo n.º 18
0
Archivo: docdirs.py Proyecto: rlz/hyde
#  We need absolute import so that we can import the main "sphinx"
#  module even though this module is also called "sphinx". Ugh.
from __future__ import absolute_import

import os
import json
import tempfile

from hyde.plugin import Plugin
from hyde.fs import File, Folder
from hyde.ext.plugins.meta import  Metadata

from hyde.util import getLoggerWithNullHandler

logger = getLoggerWithNullHandler('hyde.ext.plugins.docdirs')

try:
    from sphinx.application import Sphinx
    from sphinx.builders.html import JSONHTMLBuilder
    from sphinx.util.osutil import SEP
except ImportError:
    logger.error("The sphinx plugin requires sphinx.")
    logger.error("`pip install -U sphinx` to get it.")
    raise


class SphinxGenerator(object):
    def __init__(self, node, settings):
        self.__node = node
        self.__config = None
Ejemplo n.º 19
0
 def __init__(self, site):
     super(Plugin, self).__init__()
     self.site = site
     self.logger = getLoggerWithNullHandler(
                         'hyde.engine.%s' % self.__class__.__name__)
     self.template = None
Ejemplo n.º 20
0
generated from hyde.
"""
import os
import select
import threading
import urlparse
import urllib
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
from hyde.fs import File, Folder
from hyde.site import Site
from hyde.generator import Generator
from hyde.exceptions import HydeException

from hyde.util import getLoggerWithNullHandler
logger = getLoggerWithNullHandler('hyde.server')

from datetime import datetime


class HydeRequestHandler(SimpleHTTPRequestHandler):
    """
    Serves files by regenerating the resource (or)
    everything when a request is issued.
    """
    def do_GET(self):
        """
        Identify the requested path. If the query string
        contains `refresh`, regenerat the entire site.
        Otherwise, regenerate only the requested resource
        and serve.
Ejemplo n.º 21
0
import itertools
from urllib import quote, unquote

from hyde.fs import File, Folder
from hyde.model import Expando
from hyde.template import HtmlWrap, Template
from hyde.util import getLoggerWithNullHandler
from operator import attrgetter

from jinja2 import contextfunction, Environment
from jinja2 import FileSystemLoader, FileSystemBytecodeCache
from jinja2 import contextfilter, environmentfilter, Markup, Undefined, nodes
from jinja2.ext import Extension
from jinja2.exceptions import TemplateError

logger = getLoggerWithNullHandler('hyde.engine.Jinja2')

class SilentUndefined(Undefined):
    """
    A redefinition of undefined that eats errors.
    """
    def __getattr__(self, name):
        return self

    __getitem__ = __getattr__

    def __call__(self, *args, **kwargs):
        return self

@contextfunction
def media_url(context, path, safe=None):
Ejemplo n.º 22
0
fnamtch, shutil and distutils. This module attempts to make the right choices
for common operations to provide a single interface.
"""

import codecs
from datetime import datetime
import mimetypes
import os
import shutil
from distutils import dir_util
import functools
import fnmatch

from hyde.util import getLoggerWithNullHandler

logger = getLoggerWithNullHandler('fs')

# pylint: disable-msg=E0611


__all__ = ['File', 'Folder']


class FS(object):
    """
    The base file system object
    """

    def __init__(self, path):
        super(FS, self).__init__()
        if path == os.sep:
Ejemplo n.º 23
0
# -*- coding: utf-8 -*-
"""
Contains data structures and utilities for hyde.
"""
from hyde.fs import File, Folder

import codecs
import yaml
from datetime import datetime
from UserDict import IterableUserDict

from hyde.util import getLoggerWithNullHandler
logger = getLoggerWithNullHandler('hyde.engine')

class Expando(object):
    """
    A generic expando class that creates attributes from
    the passed in dictionary.
    """

    def __init__(self, d):
        super(Expando, self).__init__()
        self.update(d)

    def __iter__(self):
        """
        Returns an iterator for all the items in the
        dictionary as key value pairs.
        """
        return self.__dict__.iteritems()
Ejemplo n.º 24
0
from hyde import loader

from hyde.exceptions import HydeException
from hyde.fs import File
from hyde.util import getLoggerWithNullHandler, first_match
from hyde.model import Expando

from functools import partial

import re
import subprocess
import traceback


logger = getLoggerWithNullHandler("hyde.engine")


class PluginProxy(object):
    """
    A proxy class to raise events in registered  plugins
    """

    def __init__(self, site):
        super(PluginProxy, self).__init__()
        self.site = site

    def __getattr__(self, method_name):
        if hasattr(Plugin, method_name):

            def __call_plugins__(*args):