Source

washell / wa / engines / coremetrics.py

Full commit
# -*- coding: utf-8 -*-
#
# Copyright 2012 Antonio Alvarado Hernández
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""
TODO
"""

from __future__ import print_function

import json


class ParsingError(Exception):
    """TODO"""


class CmEngine(object):
    """TODO"""

    def __init__(self, config):
        self._config = config

class CmSource(object):
    """TODO"""

    def __init__(self, config):
        pass

class CmReader(object):
    """TODO"""

    def __init__(self, stream):
        self._stream = stream

    def __enter__(self):
        print("Entering...")
        if not isinstance(self._stream, file):
            # TODO: Something usefull here!
            raise Exception("Oops")
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        print("Exiting!!!")
        if not self._stream.closed:
            self._stream.close()
        return

class DataParser(object):
    """TODO"""
    def __init__(self):
        pass

    def parse(self, stream):
        """TODO"""
        try:
            decoded = json.load(stream)
            data = DataFeed(decoded)
            feed = PanelFeed()

            return data

        except Exception as e:
            raise ParsingError()

class PanelHead(object):
    """TODO"""

class PanelBody(object):
    """TODO"""

class PanelFeed(object):
    """TODO"""
    def __init__(self):
        self._head = PanelHead()
        self._body = PanelBody()

    @property
    def head(self):
        """Returns a reference to the internal body object."""
        return self._head

    @property
    def body(self):
        """Returns a reference to the internal body object."""
        return self._body

class PanelParser(object):
    """TODO"""
    def __init__(self):
        pass

    def parse(self, stream):
        """Parses raw data retrieved from given stream object."""
        return ParseFeed()

class DataFeed(object):
    """TODO"""

    def __init__(self, decoded):
        self._decoded = decoded
        self._header = None
        self._data = None

    def __str__(self):
        return str(self._decoded.keys())

def parse_json_resource(resource):
    """TODO"""
    try:
        with open(resource) as stream:
            parser = DataParser()
            feed = parser.parse(stream)
            print(str(feed))

    except Exception as e:
        print("Oops: %s" % str(e))

# EOF