Browse Source

Primitive 2.6 support added

main
Lakshmi Vyasarajan 14 years ago
parent
commit
5272633e93
11 changed files with 50 additions and 39 deletions
  1. +2
    -6
      hyde/ext/plugins/less.py
  2. +3
    -8
      hyde/ext/plugins/meta.py
  3. +1
    -6
      hyde/ext/plugins/sorter.py
  4. +5
    -5
      hyde/fs.py
  5. +2
    -5
      hyde/generator.py
  6. +2
    -4
      hyde/loader.py
  7. +25
    -0
      hyde/logging.py
  8. +4
    -0
      hyde/plugin.py
  9. +0
    -1
      hyde/server.py
  10. +3
    -4
      hyde/site.py
  11. +3
    -0
      hyde/template.py

+ 2
- 6
hyde/ext/plugins/less.py View File

@@ -9,10 +9,6 @@ import re
import subprocess
import traceback

import logging
from logging import NullHandler
logger = logging.getLogger('hyde.engine')
logger.addHandler(NullHandler())

class LessCSSPlugin(Plugin):
"""
@@ -78,8 +74,8 @@ class LessCSSPlugin(Plugin):
try:
subprocess.check_output([str(less), str(source), str(target)])
except subprocess.CalledProcessError, error:
logger.error(traceback.format_exc())
logger.error(error.output)
self.logger.error(traceback.format_exc())
self.logger.error(error.output)
raise self.template.exception_class(
"Cannot process less css. Error occurred when "
"processing [%s]" % resource.source_file)


+ 3
- 8
hyde/ext/plugins/meta.py View File

@@ -6,11 +6,6 @@ from hyde.model import Expando
from hyde.plugin import Plugin
import yaml

import logging
from logging import NullHandler
logger = logging.getLogger('hyde.engine')
logger.addHandler(NullHandler())


class Metadata(Expando):
"""
@@ -77,13 +72,13 @@ class MetaPlugin(Plugin):
the resource. Load meta data by looking for the marker.
Once loaded, remove the meta area from the text.
"""
logger.info("Trying to load metadata from resource [%s]" % resource)
self.logger.info("Trying to load metadata from resource [%s]" % resource)
yaml_finder = re.compile(
r"^\s*(?:---|===)\s*\n((?:.|\n)+?)\n\s*(?:---|===)\s*\n",
re.MULTILINE)
match = re.match(yaml_finder, text)
if not match:
logger.info("No metadata found in resource [%s]" % resource)
self.logger.info("No metadata found in resource [%s]" % resource)
data = {}
else:
text = text[match.end():]
@@ -96,7 +91,7 @@ class MetaPlugin(Plugin):
else:
resource.meta.update(data)
self.__update_standard_attributes__(resource)
logger.info("Successfully loaded metadata from resource [%s]"
self.logger.info("Successfully loaded metadata from resource [%s]"
% resource)
return text



+ 1
- 6
hyde/ext/plugins/sorter.py View File

@@ -10,11 +10,6 @@ from functools import partial
from itertools import ifilter, izip, tee
from operator import attrgetter

import logging
from logging import NullHandler
logger = logging.getLogger('hyde.engine')
logger.addHandler(NullHandler())

def pairwalk(iterable):
a, b = tee(iterable)
next(b, None)
@@ -110,7 +105,7 @@ class SorterPlugin(Plugin):
return

for name, settings in config.sorter.__dict__.items():
logger.info("Adding sort methods for [%s]" % name)
self.logger.info("Adding sort methods for [%s]" % name)
sort_method_name = 'walk_resources_sorted_by_%s' % name
add_method(Node, sort_method_name, sort_method, settings)
match_method_name = 'is_%s' % name


+ 5
- 5
hyde/fs.py View File

@@ -7,17 +7,17 @@ for common operations to provide a single interface.
"""

import codecs
import logging
from logging import NullHandler
import mimetypes
import os
import shutil
from distutils import dir_util
import functools
# pylint: disable-msg=E0611

logger = logging.getLogger('fs')
logger.addHandler(NullHandler())
from hyde.logging import getLoggerWithNullHandler

logger = getLoggerWithNullHandler('fs')

# pylint: disable-msg=E0611


__all__ = ['File', 'Folder']


+ 2
- 5
hyde/generator.py View File

@@ -8,11 +8,8 @@ from hyde.template import Template

from contextlib import contextmanager

import logging
from logging import NullHandler

logger = logging.getLogger('hyde.engine')
logger.addHandler(NullHandler())
from hyde.logging import getLoggerWithNullHandler
logger = getLoggerWithNullHandler('hyde.engine')


class Generator(object):


+ 2
- 4
hyde/loader.py View File

@@ -5,10 +5,8 @@ import sys

from hyde.exceptions import HydeException

import logging
from logging import NullHandler
logger = logging.getLogger('hyde.engine')
logger.addHandler(NullHandler())
from hyde.logging import getLoggerWithNullHandler
logger = getLoggerWithNullHandler('hyde.engine')

plugins = {}
templates = {}


+ 25
- 0
hyde/logging.py View File

@@ -0,0 +1,25 @@
"""
Module for python 2.6 compatibility.
"""
import logging

try:
from logging import NullHandler
except:
class NullHandler(logging.Handler):
"""
NOOP handler for libraries.
"""
def emit(self, record):
"""
/dev/null
"""
pass

def getLoggerWithNullHandler(logger_name):
"""
Gets the logger initialized with the `logger_name`
and a NullHandler.
"""
logger = logging.getLogger(logger_name)
logger.addHandler(NullHandler())

+ 4
- 0
hyde/plugin.py View File

@@ -5,6 +5,8 @@ Contains definition for a plugin protocol and other utiltities.
import abc
from hyde import loader

from hyde.logging import getLoggerWithNullHandler

class Plugin(object):
"""
The plugin protocol
@@ -14,6 +16,8 @@ class Plugin(object):
def __init__(self, site):
super(Plugin, self).__init__()
self.site = site
self.logger = getLoggerWithNullHandler(self.__class__.__name__)


def template_loaded(self, template):
"""


+ 0
- 1
hyde/server.py View File

@@ -12,7 +12,6 @@ from hyde.site import Site
from hyde.generator import Generator

import logging

logger = logging.getLogger('hyde.server')

import sys


+ 3
- 4
hyde/site.py View File

@@ -7,12 +7,11 @@ from hyde.exceptions import HydeException
from hyde.fs import FS, File, Folder
from hyde.model import Config

import logging
from logging import NullHandler
logger = logging.getLogger('hyde.engine')
logger.addHandler(NullHandler())
from hyde.logging import getLoggerWithNullHandler


logger = getLoggerWithNullHandler('hyde.engine')

class Processable(object):
"""
A node or resource.


+ 3
- 0
hyde/template.py View File

@@ -5,6 +5,8 @@ Abstract classes and utilities for template engines
"""
from hyde.exceptions import HydeException

from hyde.logging import getLoggerWithNullHandler

class Template(object):
"""
Interface for hyde template engines. To use a different template engine,
@@ -13,6 +15,7 @@ class Template(object):

def __init__(self, sitepath):
self.sitepath = sitepath
self.logger = getLoggerWithNullHandler(self.__class__.__name__)

def configure(self, config):
"""


Loading…
Cancel
Save