Commit 7b173447 authored by Devaev Maxim's avatar Devaev Maxim

Refactoring

parent cf1eb01e
......@@ -31,7 +31,7 @@ class Service(settingsd.service.Service) :
return "hello"
@classmethod
def options(self) :
def optionsList(self) :
return [
(self.serviceName(), "hello_string", "Hello, World!", str)
]
......
......@@ -14,7 +14,7 @@ import validators
import logger
#####
##### Public classes #####
class Application(object) :
def __init__(self) :
object.__init__(self)
......@@ -26,6 +26,9 @@ class Application(object) :
self._main_loop = gobject.MainLoop()
### Public ###
def exec_(self) :
self.init()
logger.message(const.LOG_LEVEL_INFO, "Initialized")
......@@ -35,6 +38,9 @@ class Application(object) :
self.close()
logger.message(const.LOG_LEVEL_INFO, "Closed")
### Private ###
def init(self) :
self.loadModules()
self.loadConfigs()
......@@ -65,7 +71,7 @@ class Application(object) :
def loadConfigs(self) :
for service_name in self._services_dict.keys() :
service_options_list = list(self._services_dict[service_name]["service_class"].options())
service_options_list = list(self._services_dict[service_name]["service_class"].optionsList())
service_options_list.append((service_name, "enabled", "no", validators.validBool))
for service_options_list_item in service_options_list :
......
......@@ -9,7 +9,7 @@ import config
import validators
#####
##### Private objects #####
ConfigDictObject = {
const.MY_NAME : {
"service_name" : (const.DEFAULT_SERVICE_NAME, str),
......@@ -20,7 +20,7 @@ ConfigDictObject = {
}
##### Public #####
##### Public methods #####
def setValue(section, option, value, validator = None) :
global ConfigDictObject
......
# -*- coding: utf-8 -*-
##### Public constants #####
MY_NAME = "settingsd"
RUNTIME_NAME = "runtime"
......
# -*- coding: utf-8 -*-
##### Public #####
##### Public methods #####
def joinPath(first, *others_list) :
return joinItems("/", first, *others_list)
......@@ -9,7 +9,7 @@ def joinMethod(first, *others_list) :
return joinItems(".", first, *others_list)
##### Private #####
##### Private methods #####
def joinItems(separator, first, *others_list) :
for others_list_item in others_list :
if len(first) == 0 :
......
......@@ -7,7 +7,7 @@ import const
import config
#####
##### Public constants #####
ERROR_MESSAGE = 0
INFO_MESSAGE = 1
VERBOSE_MESSAGE = 2
......@@ -21,12 +21,12 @@ ALL_MESSAGES_LIST = (
)
#####
##### Exceptions #####
class UnknownMessageType(Exception) :
pass
#####
##### Public methods #####
def message(message_type, message) :
if message_type in (ERROR_MESSAGE, INFO_MESSAGE) :
log_level = const.LOG_LEVEL_INFO
......
# -*- coding: utf-8 -*-
import dbus
import dbus.service
import dbus.glib
......@@ -12,12 +13,12 @@ import dbus_tools
import logger
#####
class Service(object) :
##### Private classes #####
class ServiceInterface(object) :
__metaclass__ = abc.ABCMeta
Functions = shared.Functions
Actions = shared.Actions
### Public ###
@abc.abstractmethod
def initService(self) :
......@@ -26,16 +27,28 @@ class Service(object) :
def closeService(self) :
pass
class ServiceRequisitesInterface(object) :
__metaclass__ = abc.ABCMeta
### Public ###
@classmethod
@abc.abstractmethod
def serviceName(self) :
pass
@classmethod
def options(self) :
def optionsList(self) :
return []
##### Public classes #####
class Service(ServiceInterface, ServiceRequisitesInterface) :
Functions = shared.Functions
Actions = shared.Actions
#####
class CustomObject(dbus.service.Object) :
def __init__(self, object_path) :
......@@ -43,6 +56,9 @@ class CustomObject(dbus.service.Object) :
self._object_path = object_path
### Public ###
def objectPath(self) :
self._object_path
......@@ -52,6 +68,7 @@ class CustomObject(dbus.service.Object) :
def removeFromConnection(self, conneciton = None, path = None) :
self.remove_from_connection(conneciton, path)
class FunctionObject(CustomObject) :
def __init__(self, object_path) :
CustomObject.__init__(self, dbus_tools.joinPath(config.value(const.MY_NAME, "service_path"), "functions", object_path))
......@@ -61,7 +78,7 @@ class ActionObject(CustomObject) :
CustomObject.__init__(self, dbus_tools.joinPath(config.value(const.MY_NAME, "service_path"), "actions", object_path))
######
##### Private decorators #####
def tracer(function) :
def wrapper(self, *args_list, **kwargs_dict) :
return_value = function(self, *args_list, **kwargs_dict)
......@@ -75,6 +92,8 @@ def tracer(function) :
return wrapper
##### Public decorators #####
def customMethod(interface_name) :
def decorator(function) :
return tracer(dbus.service.method(interface_name)(function))
......
# -*- coding: utf-8 -*-
#####
##### Exceptions #####
class SharedConflict(Exception) :
pass
......@@ -9,11 +9,14 @@ class SharedNotExist(Exception) :
pass
#####
##### Private meta #####
class SharedMeta(type) :
def __init__(cls, name, bases_list, attrs_dict) :
cls._shared_objects_dict = {}
### Public ###
def addSharedObject(cls, shared_object_name, shared_object) :
if cls._shared_objects_dict.has_key(shared_object_name) :
raise SharedConflict("Shared \"%s\" is already exists in collection \"%s\"" % (shared_object_name, cls.__name__))
......@@ -37,6 +40,8 @@ class SharedMeta(type) :
def sharedObjectsList(cls) :
return cls._shared_objects_dict
##### Public classes #####
class Functions(object) :
__metaclass__ = SharedMeta
......
# -*- coding: utf-8 -*-
#####
##### Exceptions #####
class ValidatorError(Exception) :
pass
##### Public #####
##### Public methods #####
def validBool(arg) :
arg = str(arg).lower()
true_args_list = ("1", "true", "yes")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment