Example #1
0
 def __init__(self, conf):
     self.cache = Cache(conf)
     self.conf = conf
     self.logger = logging.getLogger(__class__.__name__)
     self.feed = feeder.Feeder()
     self.bckend = create(conf['global'].get('backend', 'dummy'), conf)
     for f in conf['feed']:
         if f.get('enabled', True):
             self.feed.add_feed(f)
Example #2
0
def load(url, **kws):
    """
    Load from an existing DB.

    :param url: An RFC-1738-style string which specifies the URL to load from.

    :param kws: Additional parameters to parse to the engine.
    """
    _backend = backends.create(url, overwrite=False)
    root_type = _backend.get_root_type()

    cls = get_class(root_type)
    self = cls(datatype=root_type, backend=_backend)

    return self
Example #3
0
def load(url, **kws):
    """
    Load from an existing DB.

    :param url: An RFC-1738-style string which specifies the URL to load from.

    :param kws: Additional parameters to parse to the engine.
    """
    _backend = backends.create(url, overwrite=False)
    root_type = _backend.get_root_type()

    cls = get_class(root_type)
    self = cls(backend=_backend)

    return self
Example #4
0
def create(data={}, url=None, overwrite=True, link_key=None, **kws):
    """
    Create a new empty DB.

    :param data: Initial data. An empty dict if not specified.

    :param url: An RFC-1738-style string which specifies the URL to store into.

    :param overwrite: If is True and the database specified by *url* already exists, it will be truncated.

    :param link_key: Key directive for links in the database.

    :param kws: Additional parameters to parse to the engine.
    """
    _backend = backends.create(url, overwrite=overwrite)

    # guess root type from the data provided.
    root_type = TYPE_MAP.get(type(data))
    if root_type in (BOOL, INT):
        root = int(data)
    elif root_type == FLOAT:
        root = float(data)
    elif root_type in (DICT, LIST):
        root = ''
    else:
        root = data

    cls = get_class(root_type)
    self = cls(datatype=root_type, backend=_backend, link_key=link_key)

    self.backend.insert_root((root_type, root))

    if root_type == DICT:
        for k, v in data.iteritems():
            self.feed({k: v})
    elif root_type == LIST:
        for x in data:
            self.feed(x)

    self.commit()

    return self
Example #5
0
def create(data={}, url=None, overwrite=True, link_key=None, **kws):
    """
    Create a new empty DB.

    :param data: Initial data. An empty dict if not specified.

    :param url: An RFC-1738-style string which specifies the URL to store into.

    :param overwrite: If is True and the database specified by *url* already exists, it will be truncated.

    :param link_key: Key directive for links in the database.

    :param kws: Additional parameters to parse to the engine.
    """
    _backend = backends.create(url, overwrite=overwrite)

    # guess root type from the data provided.
    root_type = TYPE_MAP.get(type(data))
    if root_type in (BOOL, INT):
        root = int(data)
    elif root_type == FLOAT:
        root = float(data)
    elif root_type in (DICT, LIST):
        root = ''
    else:
        root = data

    cls = get_class(root_type)
    self = cls(datatype=root_type, backend=_backend, link_key=link_key)

    self.backend.insert_root((root_type, root))

    if root_type == DICT:
        for k, v in data.iteritems():
            self.feed({k: v})
    elif root_type == LIST:
        for x in data:
            self.feed(x)

    self.commit()

    return self
Example #6
0
    def __init__(self, config="config.json", debug=False, bind="tcp://127.0.0.1:5555"):
        with open(config, "rb") as c:
            self.configuration = json.load(c)

        self.debug = debug
        self.backends = {}
        self.bind = bind

        for backend in self.configuration.get("backends", []):
            if type(backend) is dict:
                backend = backends.create(**backend)
                if self.backends.get(backend.group, False):
                    self.backends.get(backend.group).append(backend)
                    self.backends.get(backend.group).sort(key=lambda b: b.weight, reverse=True)
                else:
                    self.backends.update({backend.group: [backend]})

        if self.debug:
            print("Configuration %s:" % config)

            for group, _backends in self.backends.iteritems():
                print("\tGroup: %s" % group)
                for backend in _backends:
                    print("\t\t%s" % backend)