示例#1
0
文件: logger.py 项目: bazsi/codega
def prepare(level=None):
    import logging

    levels = {
        "trace": TRACE,
        "debug": DEBUG,
        "info": INFO,
        "warning": WARNING,
        "error": ERROR,
        "critical": CRITICAL,
        "5": TRACE,
        "4": DEBUG,
        "3": INFO,
        "2": WARNING,
        "1": ERROR,
        "0": CRITICAL,
    }

    logging.basicConfig(format="%(asctime)s %(levelname) -10s %(message)s")

    levelname = None
    if level is None:
        for ndx, opt in enumerate(sys.argv):
            if opt == "-v" or opt == "--verbosity":
                levelname = sys.argv[ndx + 1]
                del sys.argv[ndx : ndx + 2]
                break

    else:
        levelname = level

    if levelname is not None:
        try:
            loglevel = levels[levelname]

        except KeyError:
            print >>sys.stderr, "Unknown log level %s" % opt
            exit(1)

    else:
        loglevel = ERROR

    logging.getLogger().setLevel(loglevel)
    use_global_python_log(PyErrorLog())
示例#2
0
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
import json, logging, pprint, re, StringIO, urllib, urllib2, urlparse
import requests
from lxml import etree


#Added to avoid the following errors:
#Cannot convert lxml.etree._RotatingErrorLog to lxml.etree._BaseErrorLog
class Logger(etree.PyErrorLog):
    def log(self, entry, message, *args):
        pass
etree.use_global_python_log(Logger())


logging.basicConfig(
    filename='', level='DEBUG',
    format='[%(asctime)s] %(levelname)s [%(module)s-%(funcName)s()::%(lineno)d] %(message)s',
    datefmt='%d/%b/%Y %H:%M:%S'
    )
logger = logging.getLogger(__name__)
logger.debug( 'link360.py START' )


SERSOL_KEY = None

#Make the OpenURL for passing on.
SERSOL_MAP = {
    'journal': {
        'title': 'atitle',
示例#3
0
import urllib
from lxml import etree
import urlparse


#Added to avoid the following errors:
#Cannot convert lxml.etree._RotatingErrorLog to lxml.etree._BaseErrorLog
class Logger(etree.PyErrorLog):
    def log(self, entry, message, *args):
        pass


etree.use_global_python_log(Logger())

SERSOL_KEY = None

#Make the OpenURL for passing on.
SERSOL_MAP = {
    'journal': {
        'title': 'atitle',
        'creatorLast': 'aulast',
        'creator': 'au',
        'creatorFirst': 'aufirst',
        'creatorMiddle': 'auinitm',
        'source': 'jtitle',
        'date': 'date',
        #issns are tricky - handle in application logic
        'issn': 'issn',
        'eissn': 'eissn',
        'isbn': 'isbn',
        'volume': 'volume',
    if prefix:
        params['id-prefix'] = prefix
    stylesheets = [CNXML_AUTOID_XSL]
    if source and stylesheets and transformable:
        try:
            doc = XMLService.parseString(source)   # may error if malformed
            # TODO: if slow, we could replace with Expat 2-pass method
            result = XMLService.xsltPipeline(doc, stylesheets, **params)
            return result
        except XMLService.XMLParserError:
            pass  # just stopping on parse error is okay; it'll send us to the fallback below
    return source

## error logging/handling

etree.use_global_python_log(etree.PyErrorLog())

class CNXMLFileError(Exception):
    pass

class XPathError(Exception):
    pass

## and, finally, the class...
def manage_addCNXMLFile(self,id,file='',title='',precondition='', content_type='text/xml', REQUEST=None):
    """Add a new CNXML File object.
    Creates a new CNXML File object 'id' with the contents of 'file'
    """

    id=str(id)
    title=str(title)
        params['id-prefix'] = prefix
    stylesheets = [CNXML_AUTOID_XSL]
    if source and stylesheets and transformable:
        try:
            doc = XMLService.parseString(source)  # may error if malformed
            # TODO: if slow, we could replace with Expat 2-pass method
            result = XMLService.xsltPipeline(doc, stylesheets, **params)
            return result
        except XMLService.XMLParserError:
            pass  # just stopping on parse error is okay; it'll send us to the fallback below
    return source


## error logging/handling

etree.use_global_python_log(etree.PyErrorLog())


class CNXMLFileError(Exception):
    pass


class XPathError(Exception):
    pass


## and, finally, the class...
def manage_addCNXMLFile(self,
                        id,
                        file='',
                        title='',