Example #1
0
 def __init__(self):
     log.debug(self)
     path = os.path.dirname(__file__)
     for f in os.listdir(path):
         if fnmatch.fnmatch(f, "*.py") and (f[0] != "_"):
             (modname, ext) = os.path.basename(f).rsplit(".", 1)
             try:
                 importlib.import_module("." + modname, "yaki.plugins")
             except ImportError as e:
                 log.error(tb())
                 pass
Example #2
0
 def __init__(self):
     log.debug(self)
     path = os.path.dirname(__file__)
     for f in os.listdir(path):
         if fnmatch.fnmatch(f, "*.py") and (f[0] != '_'):
             (modname,ext) = os.path.basename(f).rsplit('.', 1)
             try:
                 importlib.import_module('.' + modname, 'plugins')
             except ImportError as e:
                 log.error("%s: %s",modname,tb())
                 pass
Example #3
0
def agnostic_shortener(url):
    """A more flexible URL shortener"""
    
    services = {
        'tinyurl.com':'/api-create.php?url=',
        'is.gd'      :'/api.php?longurl=',
        #'api.bit.ly':"http://api.bit.ly/shorten?version=2.0.1&%s&format=text&longUrl=" % BITLY_AUTH,
        'api.tr.im'  :'/api/trim_simple?url='
    }
  
    for shortener in self.services.keys():
        try:
            res = fetch(self.services[shortener] + urllib.quote(url))
            shorturl = res['data'].strip()
            if ("Error" not in shorturl) and ("http://" + urlparse.urlparse(shortener)[1] in shorturl):
                return shorturl
            else:
                continue
        except:
            log.warn("%s: %s" % (tb(),url))
            pass
    return url
Example #4
0
def agnostic_shortener(url):
    """A more flexible URL shortener"""

    services = {
        'tinyurl.com': '/api-create.php?url=',
        'is.gd': '/api.php?longurl=',
        #'api.bit.ly':"http://api.bit.ly/shorten?version=2.0.1&%s&format=text&longUrl=" % BITLY_AUTH,
        'api.tr.im': '/api/trim_simple?url='
    }

    for shortener in self.services.keys():
        try:
            res = fetch(self.services[shortener] + urllib.quote(url))
            shorturl = res['data'].strip()
            if ("Error" not in shorturl) and (
                    "http://" + urlparse.urlparse(shortener)[1] in shorturl):
                return shorturl
            else:
                continue
        except:
            log.warn("%s: %s" % (tb(), url))
            pass
    return url
Example #5
0
Description: Shared configuration data
License: MIT (see LICENSE.md for details)
"""

import os, sys, platform, logging.config
from utils.core import get_config, path_for, tb

try:
    settings
except NameError:
    for host in [platform.node(), 'default']:
        try:
            settings = get_config(
                path_for(os.path.join('etc', '%s.json' % host)))
        except IOError:
            continue
        except Exception as e:
            tb = tb()
            print tb
            if sys.stderr.isatty():
                print >> sys.stderr, (
                    "Error while loading %(host)s.json: %(tb)s" % locals())
            else:
                log.error("Error while loading %(host)s.json: %(tb)s" %
                          locals())
            sys.exit(2)
        logging.config.dictConfig(dict(settings.logging))
        log = logging.getLogger()
        log.info("Configuration for %s loaded." % host)
        break
Example #6
0
# -*- coding: utf-8 -*-
"""
Copyright (c) 2012, Rui Carmo
Description: Shared configuration data
License: MIT (see LICENSE.md for details)
"""

import os, sys, platform, logging.config
from utils.core import get_config, path_for, tb

try:
    settings
except NameError:
    for host in [platform.node(), 'default']:
        try:
            settings = get_config(path_for(os.path.join('etc','%s.json' % host)))
        except IOError:
            continue
        except Exception as e:
            tb = tb()
            print tb
            if sys.stderr.isatty():
                print >> sys.stderr, ("Error while loading %(host)s.json: %(tb)s" % locals())
            else:
                log.error("Error while loading %(host)s.json: %(tb)s" % locals())
            sys.exit(2)
        logging.config.dictConfig(dict(settings.logging))
        log = logging.getLogger()
        log.info("Configuration for %s loaded." % host)
        break