Skip to content

Commit

Permalink
Namespace refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Apr 5, 2018
1 parent 7749d20 commit dc9691a
Show file tree
Hide file tree
Showing 26 changed files with 68 additions and 35 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ in progress
- [io] Add comments to MqttInfluxGrafanaService regarding ingress data enrichment
- [package] Improve list of suggested packages to ease installing on more modern Debian distributions
- [doc] Add documentation about Nginx reverse proxy setup
- [dev] Switch development environment from Docker to native
- [env] Switch development environment from Docker to native
- [io] Make MQTT client identifier even more unique by adding process id
- [feed] Improve ``luftdaten-to-mqtt`` of [:ref:`vendor-luftdaten.info`]

Expand All @@ -33,6 +33,7 @@ in progress
- [core] Improve component loading robustness
- [grafana] Refactoring. Robustness. Run GrafanaManager as service. Add worker service for taming dashboard refresh intervals.
- [command] Add ``kotori-selftest`` program, still in its infancy
- [code] Namespace refactoring


.. _kotori-0.20.1:
Expand Down
8 changes: 4 additions & 4 deletions kotori/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# -*- coding: utf-8 -*-
# (c) 2014-2016 Andreas Motl, Elmyra UG <andreas.motl@elmyra.de>
# (c) 2014-2017 Andreas Motl, <andreas@getkotori.org>
import sys
from bunch import Bunch
from docopt import docopt
from pkgutil import extend_path
from twisted.internet import reactor
from twisted.logger import Logger, LogLevel
from kotori.util import setup_logging
from kotori.core import APP_NAME, KotoriBootloader
from kotori.logger import startLogging
from kotori.configuration import get_configuration, get_configuration_file, apply_default_settings
from kotori.frontend.server import boot_frontend
from kotori.util.common import setup_logging
from kotori.util.logger import startLogging
from kotori.util.configuration import get_configuration, get_configuration_file, apply_default_settings

__path__ = extend_path(__path__, __name__)

Expand Down
8 changes: 4 additions & 4 deletions kotori/core.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
# (c) 2014-2016 Andreas Motl, Elmyra UG <andreas.motl@elmyra.de>
# (c) 2014-2018 Andreas Motl, <andreas@getkotori.org>
from pkg_resources import EntryPoint
from pyramid.settings import asbool
from twisted.logger import Logger, LogLevel
from kotori.logger import changeLogLevel
from kotori.configuration import read_list
from kotori.util.configuration import read_list
from kotori.util.errors import last_error_and_traceback
from kotori.util.logger import changeLogLevel
from kotori.version import __VERSION__
from kotori.errors import last_error_and_traceback

log = Logger()
APP_NAME = u'Kotori version ' + __VERSION__
Expand Down
4 changes: 2 additions & 2 deletions kotori/daq/application/composite.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
# (c) 2016 Andreas Motl, Elmyra UG <andreas.motl@elmyra.de>
# (c) 2016 Andreas Motl, <andreas@getkotori.org>
from bunch import Bunch
from twisted.logger import Logger
from kotori import KotoriBootloader
from kotori.configuration import read_list
from kotori.daq.services import RootService
from kotori.util.configuration import read_list

log = Logger()

Expand Down
2 changes: 1 addition & 1 deletion kotori/daq/intercom/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from twisted.logger import Logger
from kotori.daq.intercom.pyclibrary_ext.c_parser import CParserEnhanced
from kotori.daq.intercom.pyclibrary_ext.backend_ctypes import monkeypatch_pyclibrary_ctypes_struct
from kotori.util import slm
from kotori.util.common import slm

logger = Logger()

Expand Down
2 changes: 1 addition & 1 deletion kotori/daq/intercom/wamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from twisted.logger import Logger, LogLevel
from twisted.internet import reactor
from autobahn.twisted.wamp import ApplicationRunner, ApplicationSession
from kotori.logger import startLogging
from kotori.util.logger import startLogging

log = Logger()

Expand Down
4 changes: 2 additions & 2 deletions kotori/daq/services/mig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from twisted.application.service import MultiService, Service
from twisted.python.failure import Failure
from twisted.python.threadpool import ThreadPool
from kotori.configuration import read_list
from kotori.daq.services.schema import MessageType, TopicMatchers
from kotori.daq.services import MultiServiceMixin
from kotori.daq.intercom.mqtt import MqttAdapter
from kotori.daq.storage.influx import InfluxDBAdapter
from kotori.io.protocol.util import convert_floats
from kotori.thimble import Thimble
from kotori.util.configuration import read_list
from kotori.util.thimble import Thimble

log = Logger()

Expand Down
2 changes: 1 addition & 1 deletion kotori/firmware/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from git import RemoteProgress
from plumbum import local
from plumbum.cmd import pwd, make, grep, ls
from kotori.errors import last_error_and_traceback
from kotori.util.errors import last_error_and_traceback

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion kotori/firmware/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from twisted.web import http, server
from twisted.logger import Logger
from twisted.application.service import MultiService
from kotori.configuration import read_list
from kotori.util.configuration import read_list
from kotori.daq.services import RootService, MultiServiceMixin
from kotori.io.protocol.forwarder import ForwarderAddress
from kotori.io.protocol.http import HttpServerService
Expand Down
2 changes: 1 addition & 1 deletion kotori/io/protocol/forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from bunch import Bunch, bunchify
from twisted.logger import Logger
from twisted.application.service import MultiService
from kotori.configuration import read_list
from kotori.util.configuration import read_list
from kotori.core import KotoriBootloader
from kotori.daq.services import RootService, MultiServiceMixin
from kotori.io.protocol.http import HttpServerService
Expand Down
2 changes: 1 addition & 1 deletion kotori/io/protocol/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from kotori.io.export.tabular import UniversalTabularExporter
from kotori.io.export.plot import UniversalPlotter
from kotori.io.protocol.util import convert_floats, slugify_datettime, flatten_request_args, handleFailure
from kotori.errors import last_error_and_traceback
from kotori.util.errors import last_error_and_traceback

log = Logger()

Expand Down
2 changes: 1 addition & 1 deletion kotori/io/protocol/influx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pyinfluxql.functions import Mean
from twisted.logger import Logger
from kotori.io.protocol.util import is_number
from kotori.util import tdelta
from kotori.util.common import tdelta

log = Logger()

Expand Down
4 changes: 2 additions & 2 deletions kotori/io/protocol/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from twisted.web import http, server
from twisted.logger import Logger, LogLevel
from twisted.application.service import MultiService
from kotori.configuration import read_list
from kotori.util.configuration import read_list
from kotori.daq.services import MultiServiceMixin
from kotori.daq.intercom.mqtt import MqttAdapter
from kotori.io.protocol.http import HttpDataFrameResponse
from kotori.io.protocol.util import handleFailure
from kotori.errors import last_error_and_traceback
from kotori.util.errors import last_error_and_traceback

log = Logger()

Expand Down
Empty file added kotori/util/__init__.py
Empty file.
31 changes: 30 additions & 1 deletion kotori/util.py → kotori/util/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# (c) 2014-2016 Andreas Motl <andreas.motl@elmyra.de>
# (c) 2014-2018 Andreas Motl <andreas@getkotori.org>
import re
import os
import sys
Expand All @@ -11,12 +11,16 @@
from appdirs import user_data_dir
from datetime import timedelta

from bunch import Bunch

logger = logging.getLogger()


def slm(message):
"""sanitize log message"""
return unicode(message).replace('{', '{{').replace('}', '}}')


class Singleton(object):
"""
Singleton class by Duncan Booth.
Expand Down Expand Up @@ -104,6 +108,7 @@ def __str__(self):
def get_hostname():
return socket.gethostname()


def setup_logging(level=logging.INFO):
log_format = '%(asctime)-15s [%(name)-25s] %(levelname)-7s: %(message)s'
logging.basicConfig(
Expand All @@ -125,3 +130,27 @@ def tdelta(input):
kwargs[k] = int(v)
return timedelta(**kwargs)


class SmartBunch(Bunch):

def dump(self):
return self.toJSON()

def pretty(self):
return self.toJSON(indent=4)

def prettify(self):
return self.pretty()

@classmethod
def bunchify(cls, x):
"""
Recursively transforms a dictionary into a SmartBunch via copy.
Generic "bunchify", also works with descendants of Bunch.
"""
if isinstance(x, dict):
return cls( (k, cls.bunchify(v)) for k,v in x.iteritems() )
elif isinstance(x, (list, tuple)):
return type(x)( cls.bunchify(v) for v in x )
else:
return x
2 changes: 1 addition & 1 deletion kotori/configuration.py → kotori/util/configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# (c) 2014-2016 Andreas Motl, Elmyra UG <andreas.motl@elmyra.de>
# (c) 2014-2017 Andreas Motl, <andreas@getkotori.org>
import os
import logging
from glob import glob
Expand Down
2 changes: 1 addition & 1 deletion kotori/errors.py → kotori/util/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# (c) 2014,2015 Andreas Motl, Elmyra UG <andreas.motl@elmyra.de>
# (c) 2014-2015 Andreas Motl, <andreas@getkotori.org>
import sys
import traceback
from StringIO import StringIO
Expand Down
5 changes: 3 additions & 2 deletions kotori/logger.py → kotori/util/logger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# (c) 2015 Andreas Motl, Elmyra UG <andreas.motl@elmyra.de>
# (c) 2015 Andreas Motl, <andreas@getkotori.org>
from __future__ import absolute_import

from twisted.logger import (
from twisted.logger import (
LogLevel, globalLogBeginner,
FileLogObserver, FilteringLogObserver, LogLevelFilterPredicate,
formatTime, timeFormatRFC3339, formatEvent)
Expand Down
2 changes: 2 additions & 0 deletions kotori/thimble.py → kotori/util/thimble.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
"""Implementation of a Twisted-friendly thread pool wrapper."""
from __future__ import absolute_import
from functools import partial
from twisted.internet.threads import deferToThreadPool
from twisted.internet.defer import fail
Expand Down
2 changes: 1 addition & 1 deletion kotori/vendor/hydro2motion/web/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from twisted.web.resource import Resource
from twisted.web.server import Site
from twisted.web.static import File
from kotori.util import NodeId, get_hostname
from kotori.util.common import NodeId, get_hostname

log = Logger()

Expand Down
2 changes: 1 addition & 1 deletion kotori/vendor/ilaundry/master/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from autobahn.twisted.websocket import WampWebSocketServerProtocol, WampWebSocketServerFactory
from twisted.python import log
from twisted.internet import reactor
from kotori.util import ConfigStoreJson
from kotori.util.common import ConfigStoreJson


client = None
Expand Down
2 changes: 1 addition & 1 deletion kotori/vendor/ilaundry/node/nodeservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from twisted.python import log
from twisted.internet import reactor
from autobahn.twisted.websocket import connectWS, WampWebSocketClientProtocol, WampWebSocketClientFactory
from kotori.util import NodeId, get_hostname
from kotori.util.common import NodeId, get_hostname
from kotori.io.node.util import tts_say

node_manager = None
Expand Down
2 changes: 1 addition & 1 deletion kotori/vendor/lst/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pkg_resources import resource_filename
from twisted.logger import Logger
from twisted.internet import reactor
from kotori.configuration import read_list
from kotori.util.configuration import read_list
from kotori.daq.intercom.c import LibraryAdapter, StructRegistryByID
from kotori.daq.intercom.wamp import WampApplication, WampSession
from kotori.daq.intercom.udp import UdpBusForwarder
Expand Down
2 changes: 1 addition & 1 deletion kotori/vendor/lst/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from urlparse import urlparse
from tabulate import tabulate
from collections import OrderedDict
from kotori.configuration import read_list
from kotori.util.configuration import read_list

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion kotori/vendor/lst/h2m/playground.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pprint import pprint
from binascii import unhexlify, hexlify
from tabulate import tabulate
from kotori.util import setup_logging
from kotori.util.common import setup_logging
from kotori.vendor.lst.h2m.util import setup_h2m_structs
from kotori.daq.intercom.c import LibraryAdapter, StructRegistry, StructRegistryByID

Expand Down
4 changes: 2 additions & 2 deletions kotori/vendor/lst/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from bunch import Bunch
from docopt import docopt
from kotori.version import __VERSION__
from kotori.util import setup_logging
from kotori.configuration import get_configuration, get_configuration_file
from kotori.util.common import setup_logging
from kotori.util.configuration import get_configuration, get_configuration_file
from kotori.vendor.lst.application import setup_binary_message_adapter
from kotori.vendor.lst.commands import lst_channels, lst_message, sanitize_channel_label, compute_channel_label

Expand Down

0 comments on commit dc9691a

Please sign in to comment.