Преглед изворни кода

optimized config/logging.yaml and worked on controller/command configuration files

digital пре 8 година
родитељ
комит
8ebdf38095
5 измењених фајлова са 99 додато и 84 уклоњено
  1. 2 0
      config/commands.yaml
  2. 24 65
      config/logging.yaml
  3. 13 17
      lib/beewatch/config/__init__.py
  4. 1 2
      lib/beewatch/server/__init__.py
  5. 59 0
      test_config.py

+ 2 - 0
config/commands.yaml

@@ -1,5 +1,7 @@
+
 controllers:
     engines_ctrl:
         target: digilib.pin.EnginesController
+        left: 17,
 commands:
     turn: engines_ctrl.turn

+ 24 - 65
config/logging.yaml

@@ -3,72 +3,57 @@ disable_existing_loggers: False
 formatters:
     formatter_console:
         style: "{"
-        format: "({filename}:{lineno}) {name} {levelname} - {message}"
+        format: "({filename}:{lineno:<3}) {name} {levelname} - {message}"
         # datefmt: "%Y-%m-%d %H:%M:%S"
     formatter_file:
         style: "{"
         format: "{asctime} ({filename}:{lineno}) {name} {levelname} - {message}"
         datefmt: "%Y-%m-%d %H:%M:%S"
 handlers:
-    handler_console:
+    chandler:
         class: logging.StreamHandler
         level: DEBUG
         formatter: formatter_console
         stream: ext://sys.stdout
-    fh_chat:
-        class: logging.FileHandler
-        level: DEBUG
-        formatter: formatter_file
-        filename: logs/chat.log
-    fh_network:
-        class: logging.FileHandler
-        level: DEBUG
-        formatter: formatter_file
-        filename: logs/network.log
-    fh_log:
+    fh_server_chat:
         class: logging.FileHandler
         level: DEBUG
         formatter: formatter_file
-        filename: logs/client.log
-    fh_lib:
-        class: logging.FileHandler
-        level: DEBUG
-        formatter: formatter_file
-        filename: logs/client.log
-    fh_client:
+        filename: logs/chat_server.log
+    fh_chat:
         class: logging.FileHandler
         level: DEBUG
         formatter: formatter_file
-        filename: logs/client.log
-        #
+        filename: logs/chat_client.log
 loggers:
     __main__:
         level: DEBUG
-        handlers: [handler_console]
+        handlers: [chandler]
+        propagate: no
     beewatch:
         level: DEBUG
-        handlers: [handler_console]
+        handlers: [chandler]
+        propagate: no
     digilib:
         level: DEBUG
-        handlers: [handler_console]
-    digilib.gui:
-        level: DEBUG
-        handlers: [handler_console]
+        handlers: [chandler]
+        propagate: no
     digilib.network:
-        level: DEBUG
-        handlers: [handler_console]
+        handlers: [chandler]
         propagate: no
-    digilib.network.chat:
-        level: INFO
-        handlers: [handler_console]
+    digilib.network.server.chat:
+        handlers: [chandler]
         propagate: no
-    digilib.network.client:
-        level: DEBUG
-        handlers: [handler_console]
+        # handlers: [chandler,fh_client_chat]
+    digilib.network.client.chat:
+        handlers: [chandler]
         propagate: no
-    root:
-        level: DEBUG
-        handlers: [handler_console]
+        # handlers: [chandler,fh_client_chat]
+
+
+
+
+
 
 
 
@@ -76,32 +61,6 @@ loggers:
 
 
 
-# [loggers]
-# keys=BeeGui
-#
-# [handlers]
-# keys=bg_console_handler
-#
-# [formatters]
-# keys=bg_simple_formatter
-#
-# [logger_BeeGui]
-# level=DEBUG
-# handlers=bg_console_handler
-# qualname=__digilib.gui__
-# propagate=1
-#
-# [handler_bg_console_handler]
-# class=StreamHandler
-# level=DEBUG
-# formatter=bg_simple_formatter
-# args=(sys.stdout,)
-#
-# [formatter_bg_simple_formatter]
-# style=$
-# format=(${name}:${lineno}): ${module}-${levelname} **:${message}
-# #format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
-# datefmt=
 
 
 

+ 13 - 17
lib/beewatch/config/__init__.py

@@ -28,35 +28,31 @@ class Configure(object):
         self.configure(config)
         self.config = {}
     def configure(self,config):
-        config_keys = ["controllers","commands"]
-        for name,properties in config.pop("controllers"):
+        for name,properties in config.pop("controllers").items():
+            print(name)
             target = properties.pop("target")
             if not callable(target):
                 target = self.str_to_callable(target)
-            self.retconf["controllers"][name] = target(**ctrl)
-        for name,function in config.pop("commands"):
+                print(target)
+            self.retconf["controllers"][name] = target(**properties)
+        for name,function in config.pop("commands").items():
             if not callable(function):
                 function = self.str_to_callable()
             self.retconf[commands][name] = function
     def str_to_callable(self,dotted_str):
         parts = dotted_str.split(".")
         next_to_import = parts.pop(0)
-        converted = None
+        converted = __import__(next_to_import)
+        # converted = None
+        # next_to_import = parts.pop(0)
         for p in parts:
-            if not hasattr(imported,p):
-                __import__(next_to_import)
-            converted = getattr(converted,p)
             next_to_import += "." + p
+            if not hasattr(converted,p):
+                print("importing " + next_to_import)
+                converted = __import__(next_to_import)
+            converted = getattr(converted,p)
+        print("converted",converted)
         return converted
-    for n in name:
-        used = used + '.' + n
-        try:
-            found = getattr(found, n)
-        except AttributeError:
-            __import__(used)
-            found = getattr(found, n)
-    return found
-
 
 
 

+ 1 - 2
lib/beewatch/server/__init__.py

@@ -52,7 +52,6 @@ class BeeWatchServer(digilib.network.Server):
 class ConnHandlerBeeWatch(digilib.network.ConnHandlerBase):
     def __init__(self, socket, addr, server):
         super(ConnHandlerBeeWatch, self).__init__(socket, addr, server)
-        lchat.info('hey')
         self.engine_controller = digilib.pin.EnginesController(
             left=[4,17],
             right=[27,22],
@@ -82,7 +81,7 @@ class ConnHandlerBeeWatch(digilib.network.ConnHandlerBase):
         self.send("this is the server speaking, hello new client!")
     def handle(self, data_decoded):
         data_decoded=data_decoded.strip()
-        lchat.info("Client:"+data_decoded)
+        # lchat.info("Client:"+data_decoded)
         if data_decoded.find(" ") != -1:
             cmd = data_decoded.split()[0]
             args = data_decoded.split()[1:]

+ 59 - 0
test_config.py

@@ -0,0 +1,59 @@
+#!/usr/bin/env python3.5
+# Copyright 2017 Digital
+#
+# This file is part of BeeWatch.
+#
+# BeeWatch is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# BeeWatch is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with BeeWatch.  If not, see <http://www.gnu.org/licenses/>.
+
+from pprint import pprint
+import yaml
+import beewatch.config
+
+with open("config/commands.yaml") as f:
+    data = f.read()
+config = yaml.safe_load(data)
+pprint(beewatch.config.Configure(config))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#