Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
7b173447
Commit
7b173447
authored
Sep 07, 2010
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
cf1eb01e
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
51 additions
and
20 deletions
+51
-20
hello.py
functions/hello.py
+1
-1
application.py
settingsd/application.py
+8
-2
config.py
settingsd/config.py
+2
-2
const.py
settingsd/const.py
+1
-0
dbus_tools.py
settingsd/dbus_tools.py
+2
-2
logger.py
settingsd/logger.py
+3
-3
service.py
settingsd/service.py
+25
-6
shared.py
settingsd/shared.py
+7
-2
validators.py
settingsd/validators.py
+2
-2
No files found.
functions/hello.py
View file @
7b173447
...
@@ -31,7 +31,7 @@ class Service(settingsd.service.Service) :
...
@@ -31,7 +31,7 @@ class Service(settingsd.service.Service) :
return
"hello"
return
"hello"
@classmethod
@classmethod
def
options
(
self
)
:
def
options
List
(
self
)
:
return
[
return
[
(
self
.
serviceName
(),
"hello_string"
,
"Hello, World!"
,
str
)
(
self
.
serviceName
(),
"hello_string"
,
"Hello, World!"
,
str
)
]
]
...
...
settingsd/application.py
View file @
7b173447
...
@@ -14,7 +14,7 @@ import validators
...
@@ -14,7 +14,7 @@ import validators
import
logger
import
logger
#####
#####
Public classes #####
class
Application
(
object
)
:
class
Application
(
object
)
:
def
__init__
(
self
)
:
def
__init__
(
self
)
:
object
.
__init__
(
self
)
object
.
__init__
(
self
)
...
@@ -26,6 +26,9 @@ class Application(object) :
...
@@ -26,6 +26,9 @@ class Application(object) :
self
.
_main_loop
=
gobject
.
MainLoop
()
self
.
_main_loop
=
gobject
.
MainLoop
()
### Public ###
def
exec_
(
self
)
:
def
exec_
(
self
)
:
self
.
init
()
self
.
init
()
logger
.
message
(
const
.
LOG_LEVEL_INFO
,
"Initialized"
)
logger
.
message
(
const
.
LOG_LEVEL_INFO
,
"Initialized"
)
...
@@ -35,6 +38,9 @@ class Application(object) :
...
@@ -35,6 +38,9 @@ class Application(object) :
self
.
close
()
self
.
close
()
logger
.
message
(
const
.
LOG_LEVEL_INFO
,
"Closed"
)
logger
.
message
(
const
.
LOG_LEVEL_INFO
,
"Closed"
)
### Private ###
def
init
(
self
)
:
def
init
(
self
)
:
self
.
loadModules
()
self
.
loadModules
()
self
.
loadConfigs
()
self
.
loadConfigs
()
...
@@ -65,7 +71,7 @@ class Application(object) :
...
@@ -65,7 +71,7 @@ class Application(object) :
def
loadConfigs
(
self
)
:
def
loadConfigs
(
self
)
:
for
service_name
in
self
.
_services_dict
.
keys
()
:
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"
]
.
options
List
())
service_options_list
.
append
((
service_name
,
"enabled"
,
"no"
,
validators
.
validBool
))
service_options_list
.
append
((
service_name
,
"enabled"
,
"no"
,
validators
.
validBool
))
for
service_options_list_item
in
service_options_list
:
for
service_options_list_item
in
service_options_list
:
...
...
settingsd/config.py
View file @
7b173447
...
@@ -9,7 +9,7 @@ import config
...
@@ -9,7 +9,7 @@ import config
import
validators
import
validators
#####
#####
Private objects #####
ConfigDictObject
=
{
ConfigDictObject
=
{
const
.
MY_NAME
:
{
const
.
MY_NAME
:
{
"service_name"
:
(
const
.
DEFAULT_SERVICE_NAME
,
str
),
"service_name"
:
(
const
.
DEFAULT_SERVICE_NAME
,
str
),
...
@@ -20,7 +20,7 @@ ConfigDictObject = {
...
@@ -20,7 +20,7 @@ ConfigDictObject = {
}
}
##### Public #####
##### Public
methods
#####
def
setValue
(
section
,
option
,
value
,
validator
=
None
)
:
def
setValue
(
section
,
option
,
value
,
validator
=
None
)
:
global
ConfigDictObject
global
ConfigDictObject
...
...
settingsd/const.py
View file @
7b173447
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
##### Public constants #####
MY_NAME
=
"settingsd"
MY_NAME
=
"settingsd"
RUNTIME_NAME
=
"runtime"
RUNTIME_NAME
=
"runtime"
...
...
settingsd/dbus_tools.py
View file @
7b173447
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
##### Public #####
##### Public
methods
#####
def
joinPath
(
first
,
*
others_list
)
:
def
joinPath
(
first
,
*
others_list
)
:
return
joinItems
(
"/"
,
first
,
*
others_list
)
return
joinItems
(
"/"
,
first
,
*
others_list
)
...
@@ -9,7 +9,7 @@ def joinMethod(first, *others_list) :
...
@@ -9,7 +9,7 @@ def joinMethod(first, *others_list) :
return
joinItems
(
"."
,
first
,
*
others_list
)
return
joinItems
(
"."
,
first
,
*
others_list
)
##### Private #####
##### Private
methods
#####
def
joinItems
(
separator
,
first
,
*
others_list
)
:
def
joinItems
(
separator
,
first
,
*
others_list
)
:
for
others_list_item
in
others_list
:
for
others_list_item
in
others_list
:
if
len
(
first
)
==
0
:
if
len
(
first
)
==
0
:
...
...
settingsd/logger.py
View file @
7b173447
...
@@ -7,7 +7,7 @@ import const
...
@@ -7,7 +7,7 @@ import const
import
config
import
config
#####
#####
Public constants #####
ERROR_MESSAGE
=
0
ERROR_MESSAGE
=
0
INFO_MESSAGE
=
1
INFO_MESSAGE
=
1
VERBOSE_MESSAGE
=
2
VERBOSE_MESSAGE
=
2
...
@@ -21,12 +21,12 @@ ALL_MESSAGES_LIST = (
...
@@ -21,12 +21,12 @@ ALL_MESSAGES_LIST = (
)
)
#####
#####
Exceptions #####
class
UnknownMessageType
(
Exception
)
:
class
UnknownMessageType
(
Exception
)
:
pass
pass
#####
#####
Public methods #####
def
message
(
message_type
,
message
)
:
def
message
(
message_type
,
message
)
:
if
message_type
in
(
ERROR_MESSAGE
,
INFO_MESSAGE
)
:
if
message_type
in
(
ERROR_MESSAGE
,
INFO_MESSAGE
)
:
log_level
=
const
.
LOG_LEVEL_INFO
log_level
=
const
.
LOG_LEVEL_INFO
...
...
settingsd/service.py
View file @
7b173447
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
dbus
import
dbus
import
dbus.service
import
dbus.service
import
dbus.glib
import
dbus.glib
...
@@ -12,12 +13,12 @@ import dbus_tools
...
@@ -12,12 +13,12 @@ import dbus_tools
import
logger
import
logger
#####
#####
Private classes #####
class
Service
(
object
)
:
class
Service
Interface
(
object
)
:
__metaclass__
=
abc
.
ABCMeta
__metaclass__
=
abc
.
ABCMeta
Functions
=
shared
.
Functions
Actions
=
shared
.
Actions
### Public ###
@abc.abstractmethod
@abc.abstractmethod
def
initService
(
self
)
:
def
initService
(
self
)
:
...
@@ -26,16 +27,28 @@ class Service(object) :
...
@@ -26,16 +27,28 @@ class Service(object) :
def
closeService
(
self
)
:
def
closeService
(
self
)
:
pass
pass
class
ServiceRequisitesInterface
(
object
)
:
__metaclass__
=
abc
.
ABCMeta
### Public ###
@classmethod
@classmethod
@abc.abstractmethod
@abc.abstractmethod
def
serviceName
(
self
)
:
def
serviceName
(
self
)
:
pass
pass
@classmethod
@classmethod
def
options
(
self
)
:
def
options
List
(
self
)
:
return
[]
return
[]
##### Public classes #####
class
Service
(
ServiceInterface
,
ServiceRequisitesInterface
)
:
Functions
=
shared
.
Functions
Actions
=
shared
.
Actions
#####
#####
class
CustomObject
(
dbus
.
service
.
Object
)
:
class
CustomObject
(
dbus
.
service
.
Object
)
:
def
__init__
(
self
,
object_path
)
:
def
__init__
(
self
,
object_path
)
:
...
@@ -43,6 +56,9 @@ class CustomObject(dbus.service.Object) :
...
@@ -43,6 +56,9 @@ class CustomObject(dbus.service.Object) :
self
.
_object_path
=
object_path
self
.
_object_path
=
object_path
### Public ###
def
objectPath
(
self
)
:
def
objectPath
(
self
)
:
self
.
_object_path
self
.
_object_path
...
@@ -52,6 +68,7 @@ class CustomObject(dbus.service.Object) :
...
@@ -52,6 +68,7 @@ class CustomObject(dbus.service.Object) :
def
removeFromConnection
(
self
,
conneciton
=
None
,
path
=
None
)
:
def
removeFromConnection
(
self
,
conneciton
=
None
,
path
=
None
)
:
self
.
remove_from_connection
(
conneciton
,
path
)
self
.
remove_from_connection
(
conneciton
,
path
)
class
FunctionObject
(
CustomObject
)
:
class
FunctionObject
(
CustomObject
)
:
def
__init__
(
self
,
object_path
)
:
def
__init__
(
self
,
object_path
)
:
CustomObject
.
__init__
(
self
,
dbus_tools
.
joinPath
(
config
.
value
(
const
.
MY_NAME
,
"service_path"
),
"functions"
,
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) :
...
@@ -61,7 +78,7 @@ class ActionObject(CustomObject) :
CustomObject
.
__init__
(
self
,
dbus_tools
.
joinPath
(
config
.
value
(
const
.
MY_NAME
,
"service_path"
),
"actions"
,
object_path
))
CustomObject
.
__init__
(
self
,
dbus_tools
.
joinPath
(
config
.
value
(
const
.
MY_NAME
,
"service_path"
),
"actions"
,
object_path
))
######
#####
Private decorators ####
#
def
tracer
(
function
)
:
def
tracer
(
function
)
:
def
wrapper
(
self
,
*
args_list
,
**
kwargs_dict
)
:
def
wrapper
(
self
,
*
args_list
,
**
kwargs_dict
)
:
return_value
=
function
(
self
,
*
args_list
,
**
kwargs_dict
)
return_value
=
function
(
self
,
*
args_list
,
**
kwargs_dict
)
...
@@ -75,6 +92,8 @@ def tracer(function) :
...
@@ -75,6 +92,8 @@ def tracer(function) :
return
wrapper
return
wrapper
##### Public decorators #####
def
customMethod
(
interface_name
)
:
def
customMethod
(
interface_name
)
:
def
decorator
(
function
)
:
def
decorator
(
function
)
:
return
tracer
(
dbus
.
service
.
method
(
interface_name
)(
function
))
return
tracer
(
dbus
.
service
.
method
(
interface_name
)(
function
))
...
...
settingsd/shared.py
View file @
7b173447
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#####
#####
Exceptions #####
class
SharedConflict
(
Exception
)
:
class
SharedConflict
(
Exception
)
:
pass
pass
...
@@ -9,11 +9,14 @@ class SharedNotExist(Exception) :
...
@@ -9,11 +9,14 @@ class SharedNotExist(Exception) :
pass
pass
#####
#####
Private meta #####
class
SharedMeta
(
type
)
:
class
SharedMeta
(
type
)
:
def
__init__
(
cls
,
name
,
bases_list
,
attrs_dict
)
:
def
__init__
(
cls
,
name
,
bases_list
,
attrs_dict
)
:
cls
.
_shared_objects_dict
=
{}
cls
.
_shared_objects_dict
=
{}
### Public ###
def
addSharedObject
(
cls
,
shared_object_name
,
shared_object
)
:
def
addSharedObject
(
cls
,
shared_object_name
,
shared_object
)
:
if
cls
.
_shared_objects_dict
.
has_key
(
shared_object_name
)
:
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__
))
raise
SharedConflict
(
"Shared
\"
%
s
\"
is already exists in collection
\"
%
s
\"
"
%
(
shared_object_name
,
cls
.
__name__
))
...
@@ -37,6 +40,8 @@ class SharedMeta(type) :
...
@@ -37,6 +40,8 @@ class SharedMeta(type) :
def
sharedObjectsList
(
cls
)
:
def
sharedObjectsList
(
cls
)
:
return
cls
.
_shared_objects_dict
return
cls
.
_shared_objects_dict
##### Public classes #####
class
Functions
(
object
)
:
class
Functions
(
object
)
:
__metaclass__
=
SharedMeta
__metaclass__
=
SharedMeta
...
...
settingsd/validators.py
View file @
7b173447
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#####
#####
Exceptions #####
class
ValidatorError
(
Exception
)
:
class
ValidatorError
(
Exception
)
:
pass
pass
##### Public #####
##### Public
methods
#####
def
validBool
(
arg
)
:
def
validBool
(
arg
)
:
arg
=
str
(
arg
)
.
lower
()
arg
=
str
(
arg
)
.
lower
()
true_args_list
=
(
"1"
,
"true"
,
"yes"
)
true_args_list
=
(
"1"
,
"true"
,
"yes"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment