Ejemplo n.º 1
0
def test_get_cube():
    ' args: cube, path '
    from metrique.utils import get_cube

    cwd = os.path.dirname(os.path.abspath(__file__))
    cube = 'eg_csvfile'
    path = os.path.join(cwd, 'cubes')
    get_cube(cube=cube, path=path)
Ejemplo n.º 2
0
def test_get_cube():
    ' args: cube, path '
    from metrique.utils import get_cube

    # expected to be available (built-ins)
    get_cube('csvdata_rows')
    get_cube('jsondata_objs')
    get_cube('sqldata_generic')
    get_cube('sqldata_teiid')

    # test pulling from arbitrary path/pkg
    paths = [os.path.dirname(os.path.abspath(__file__))]
    cube = 'csvcube_local'
    pkgs = ['testcubes']
    get_cube(cube=cube, pkgs=pkgs, cube_paths=paths)
Ejemplo n.º 3
0
def cube_cli(cube_cls=None):
    """
    :param class cube_cls:
        The cube class to initiatlize

    Available options::

        --debug: 0/False (OFF), 1/True (INFO), 2 (DEBUG)
        --force: set to pass this option to extract()
        --cube-config-file: api config file name
        --cube-config-dir: config dir path
        --cube-init-kwargs-config-file: load additional __init__ kwargs
    """
    if not cube_cls:
        cube_cls = get_cube(cube_cls)
    args = _cube_args.parse_args()
    kwargs = {}
    kwargs["debug"] = args.debug
    kwargs["config_file"] = args.cube_config_file
    kwargs["host"] = args.api_host
    kwargs["port"] = args.api_port
    kwargs["username"] = args.api_username
    kwargs["password"] = args.api_password

    cube = cube_cls(**kwargs)

    if not args.no_login:
        cube.login(cube.config.username, cube.config.password)

    return args.func(args, cube)
Ejemplo n.º 4
0
def test_get_cube():
    ' args: cube, path '
    from metrique.utils import get_cube

    # expected to be available (built-ins)
    get_cube('csvdata_rows')
    get_cube('sqldata_generic')

    # test pulling from arbitrary path/pkg
    paths = [os.path.dirname(os.path.abspath(__file__))]
    cube = 'csvcube_local'
    pkgs = ['testcubes']
    get_cube(cube=cube, pkgs=pkgs, cube_paths=paths)

    get_cube(cube=cube, pkgs=pkgs, cube_paths=paths, init=True)

    try:
        get_cube(cube='DOES_NOT_EXIST')
    except RuntimeError:
        pass
    else:
        assert False
Ejemplo n.º 5
0
def test_get_cube():
    ' args: cube, path '
    from metrique.utils import get_cube

    # expected to be available (built-ins)
    get_cube('csvdata_rows')
    get_cube('sqldata_generic')

    # test pulling from arbitrary path/pkg
    paths = [os.path.dirname(os.path.abspath(__file__))]
    cube = 'csvcube_local'
    pkgs = ['testcubes']
    get_cube(cube=cube, pkgs=pkgs, cube_paths=paths)

    get_cube(cube=cube, pkgs=pkgs, cube_paths=paths, init=True)

    try:
        get_cube(cube='DOES_NOT_EXIST')
    except RuntimeError:
        pass
    else:
        assert False
Ejemplo n.º 6
0
    def get_cube(self, cube, init=True, name=None, **kwargs):
        """wrapper for :func:`metriqueu.utils.get_cube`

        Locates and loads a metrique cube

        :param cube: name of cube to load
        :param init: (bool) initialize cube before returning?
        :param name: override the name of the cube
        :param kwargs: additional :func:`metriqueu.utils.get_cube`
        """
        config = copy(self.config)
        # don't apply the name to the current obj, but to the object
        # we get back from get_cube
        return get_cube(cube=cube, init=init, config=config, name=name, **kwargs)
Ejemplo n.º 7
0
    def __new__(cls, *args, **kwargs):
        """
        Return the specific cube class, if specified. Its
        expected the cube will be available in sys.path.

        If the cube fails to import, just move on.

            >>> import pyclient
            >>> c = pyclient(cube='git_commit')
                <type HTTPClient(...)>
        """
        if "cube" in kwargs and kwargs["cube"]:
            cls = get_cube(kwargs["cube"])
        else:
            cls = cls
        return object.__new__(cls)
Ejemplo n.º 8
0
    def get_cube(self, cube, init=True, name=None, copy_config=True, **kwargs):
        '''wrapper for :func:`metrique.utils.get_cube`

        Locates and loads a metrique cube

        :param cube: name of cube to load
        :param init: (bool) initialize cube before returning?
        :param name: override the name of the cube
        :param copy_config: apply config of calling cube to new?
                            Implies init=True.
        :param kwargs: additional :func:`metrique.utils.get_cube`
        '''
        name = name or cube
        config = copy(self.config) if copy_config else {}
        config_file = self.config_file
        container = type(self.container)
        container_config = copy(self.container_config)
        proxy = str(type(self.proxy))
        return get_cube(cube=cube, init=init, name=name, config=config,
                        config_file=config_file, container=container,
                        container_config=container_config,
                        proxy=proxy, proxy_config=self.proxy_config, **kwargs)
Ejemplo n.º 9
0
 def __new__(cls, *args, **kwargs):
     if "cube" in kwargs and kwargs["cube"]:
         cls = get_cube(cube=kwargs["cube"], init=False)
     else:
         cls = cls
     return object.__new__(cls)
Ejemplo n.º 10
0
#!/usr/bin/env python
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
# Author: "Chris Ward <*****@*****.**>

import os

from metrique.utils import get_cube
jsondata_objs = get_cube('jsondata_objs')

tmp = os.path.expanduser('~/.metrique/tmp/')

cwd = os.path.dirname(os.path.abspath(__file__))
here = '/'.join(cwd.split('/')[0:-2])
test_file_path = 'meps.json'
JSON_FILE = os.path.join(here, test_file_path)


class Local(jsondata_objs):
    name = 'tests_jsondata'

    def get_objects(self, uri=JSON_FILE, save=False, autosnap=False,
                    **kwargs):
        content = self.load(uri)
        # the content needs to be re-grouped
        objects = []
        for k, v in content.items():
            v.update({'_oid': k})
            objects.append(v)
        objects = self.normalize(objects)
        if save:
            self.cube_save(objects, autosnap=autosnap)
Ejemplo n.º 11
0
 def __call__(cls, cube=None, name=None, backends=None, *args, **kwargs):
     name = name or cube
     if cube:
         cls = get_cube(cube=cube, name=name, init=False, backends=backends)
     _type = type.__call__(cls, name=name, *args, **kwargs)
     return _type
Ejemplo n.º 12
0
 def get_cube(self, cube, init=True, **kwargs):
     " wrapper for utils.get_cube(); try to load a cube, pyclient "
     config = copy(self.config)
     config.update(kwargs)
     return get_cube(cube=cube, init=init, config=config, path=self.config.cubes_path)
Ejemplo n.º 13
0
 def __new__(cls, *args, **kwargs):
     if 'cube' in kwargs and kwargs['cube']:
         cls = get_cube(cube=kwargs['cube'], init=False)
     else:
         cls = cls
     return object.__new__(cls)
Ejemplo n.º 14
0
#!/usr/bin/env python
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
# Author: "Chris Ward <*****@*****.**>

from __future__ import unicode_literals

import os

from metrique.utils import get_cube
csvdata_rows = get_cube('csvdata_rows')

cwd = os.path.dirname(os.path.abspath(__file__))
here = '/'.join(cwd.split('/')[0:-2])
DEFAULT_URI = os.path.join(here, 'us-idx-eod.csv')
DEFAULT_ID = lambda o: o['symbol']


class Local(csvdata_rows):
    """
    Test Cube; csv based
    """
    name = 'tests_csvdata'

    def get_objects(self, uri=DEFAULT_URI, _oid=DEFAULT_ID, **kwargs):
        return super(Local, self).get_objects(uri=uri, _oid=_oid, **kwargs)
Ejemplo n.º 15
0
#!/usr/bin/env pyehon
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
# Author: "Chris Ward <*****@*****.**>

'''
metriquec.cubes.sqldata.teiid
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This module contains the cube methods for extracting
data from SQL TEIID data sources.
'''
import logging

from metrique.utils import get_cube
sqldata_generic = get_cube('sqldata_generic')

from metriquec.sql.teiid import TEIID

logger = logging.getLogger(__name__)


class Teiid(sqldata_generic):
    '''
    Driver which adds support for TEIID based sql cubes.

    :param sql_host: teiid hostname
    :param sql_port: teiid port
    :param sql_vdb: teiid virtual database name
    :param sql_username: teiid username
    :param sql_password: teiid password
    '''