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
cf1eb01e
Commit
cf1eb01e
authored
Sep 07, 2010
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved requisites to service class, refactoring
parent
b6d81a29
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
59 deletions
+49
-59
main.conf
configs/main.conf
+1
-1
hello.py
functions/hello.py
+5
-9
application.py
settingsd/application.py
+14
-19
config.py
settingsd/config.py
+4
-4
const.py
settingsd/const.py
+7
-6
logger.py
settingsd/logger.py
+1
-1
service.py
settingsd/service.py
+17
-19
No files found.
configs/main.conf
View file @
cf1eb01e
[
se
rvice
]
[
se
ttingsd
]
bus_type
=
session
log_level
=
2
...
...
functions/hello.py
View file @
cf1eb01e
...
...
@@ -22,7 +22,10 @@ class Hello(settingsd.service.FunctionObject) :
settingsd
.
shared
.
Functions
.
Hello
.
removeFromConnection
()
settingsd
.
shared
.
Functions
.
removeSharedObject
(
"Hello"
)
class
Requisites
(
settingsd
.
service
.
Requisites
)
:
class
Service
(
settingsd
.
service
.
Service
)
:
def
initService
(
self
)
:
self
.
Functions
.
addSharedObject
(
"Hello"
,
Hello
(
self
.
serviceName
()))
@classmethod
def
serviceName
(
self
)
:
return
"hello"
...
...
@@ -30,13 +33,6 @@ class Requisites(settingsd.service.Requisites) :
@classmethod
def
options
(
self
)
:
return
[
(
"hello"
,
"hello_string"
,
"Hello, World!"
,
str
)
(
self
.
serviceName
()
,
"hello_string"
,
"Hello, World!"
,
str
)
]
class
Service
(
settingsd
.
service
.
Service
)
:
def
init
(
self
)
:
self
.
Functions
.
addSharedObject
(
"Hello"
,
Hello
(
"hello"
))
def
close
(
self
)
:
pass
settingsd/application.py
View file @
cf1eb01e
...
...
@@ -48,7 +48,6 @@ class Application(object) :
self
.
closeServices
()
self
.
_main_loop
.
quit
()
def
loadModules
(
self
)
:
sys
.
path
.
append
(
const
.
FUNCTIONS_DIR
)
sys
.
path
.
append
(
const
.
ACTIONS_DIR
)
...
...
@@ -56,21 +55,17 @@ class Application(object) :
for
modules_path_list_item
in
(
const
.
FUNCTIONS_DIR
,
const
.
ACTIONS_DIR
)
:
for
module_name
in
[
item
[:
-
3
]
for
item
in
os
.
listdir
(
modules_path_list_item
)
if
item
.
endswith
(
".py"
)
]
:
self
.
_modules_list
.
append
(
__import__
(
module_name
,
globals
(),
locals
(),
[
""
]))
if
self
.
_modules_list
[
-
1
]
.
Requisites
.
serviceName
()
!=
None
:
self
.
_services_dict
[
self
.
_modules_list
[
-
1
]
.
Requisites
.
serviceName
()]
=
{
"requisites"
:
self
.
_modules_list
[
-
1
]
.
Requisites
,
"service"
:
self
.
_modules_list
[
-
1
]
.
Service
,
"instance"
:
None
}
else
:
print
>>
sys
.
stderr
,
"Anonymous modules does not acceped"
self
.
_services_dict
[
self
.
_modules_list
[
-
1
]
.
Service
.
serviceName
()]
=
{
"service_class"
:
self
.
_modules_list
[
-
1
]
.
Service
,
"service"
:
None
}
sys
.
path
.
remove
(
const
.
FUNCTIONS_DIR
)
sys
.
path
.
remove
(
const
.
ACTIONS_DIR
)
def
loadConfigs
(
self
)
:
for
service_name
in
self
.
_services_dict
.
keys
()
:
service_options_list
=
list
(
self
.
_services_dict
[
service_name
][
"
requisite
s"
]
.
options
())
service_options_list
=
list
(
self
.
_services_dict
[
service_name
][
"
service_clas
s"
]
.
options
())
service_options_list
.
append
((
service_name
,
"enabled"
,
"no"
,
validators
.
validBool
))
for
service_options_list_item
in
service_options_list
:
...
...
@@ -79,23 +74,23 @@ class Application(object) :
config
.
loadConfig
()
def
initBus
(
self
)
:
if
config
.
value
(
"service"
,
"bus_type"
)
==
const
.
SERVICE_
BUS_TYPE_SYSTEM
:
if
config
.
value
(
const
.
MY_NAME
,
"bus_type"
)
==
const
.
BUS_TYPE_SYSTEM
:
bus
=
dbus
.
SystemBus
()
else
:
bus
=
dbus
.
SessionBus
()
self
.
_bus_name
=
dbus
.
service
.
BusName
(
config
.
value
(
"service"
,
"
name"
),
bus
=
bus
)
config
.
setValue
(
"runtime"
,
"bus_name"
,
self
.
_bus_name
)
self
.
_bus_name
=
dbus
.
service
.
BusName
(
config
.
value
(
const
.
MY_NAME
,
"service_
name"
),
bus
=
bus
)
config
.
setValue
(
const
.
RUNTIME_NAME
,
"bus_name"
,
self
.
_bus_name
)
def
initServices
(
self
)
:
for
service_name
in
self
.
_services_dict
.
keys
()
:
if
config
.
value
(
service_name
,
"enabled"
)
:
self
.
_services_dict
[
service_name
][
"
instance"
]
=
self
.
_services_dict
[
service_name
][
"service
"
]()
self
.
_services_dict
[
service_name
][
"
instance"
]
.
init
()
self
.
_services_dict
[
service_name
][
"
service"
]
=
self
.
_services_dict
[
service_name
][
"service_class
"
]()
self
.
_services_dict
[
service_name
][
"
service"
]
.
initService
()
def
closeServices
(
self
)
:
for
service_name
in
self
.
_services_dict
.
keys
()
:
if
self
.
_services_dict
[
service_name
][
"
instan
ce"
]
!=
None
:
self
.
_services_dict
[
service_name
][
"
instance"
]
.
clos
e
()
del
self
.
_services_dict
[
service_name
][
"
instan
ce"
]
self
.
_services_dict
[
service_name
][
"
instan
ce"
]
=
None
if
self
.
_services_dict
[
service_name
][
"
servi
ce"
]
!=
None
:
self
.
_services_dict
[
service_name
][
"
service"
]
.
closeServic
e
()
del
self
.
_services_dict
[
service_name
][
"
servi
ce"
]
self
.
_services_dict
[
service_name
][
"
servi
ce"
]
=
None
settingsd/config.py
View file @
cf1eb01e
...
...
@@ -11,10 +11,10 @@ import validators
#####
ConfigDictObject
=
{
"service"
:
{
"name"
:
(
const
.
DEFAULT_SERVICE_NAME
,
str
),
"path"
:
(
const
.
DEFAULT_SERVICE_PATH
,
str
),
"bus_type"
:
(
const
.
DEFAULT_
SERVICE_BUS_TYPE
,
(
lambda
arg
:
validators
.
validRange
(
arg
,
const
.
ALL_SERVICE
_BUS_TYPES_LIST
)
)),
const
.
MY_NAME
:
{
"
service_
name"
:
(
const
.
DEFAULT_SERVICE_NAME
,
str
),
"
service_
path"
:
(
const
.
DEFAULT_SERVICE_PATH
,
str
),
"bus_type"
:
(
const
.
DEFAULT_
BUS_TYPE
,
(
lambda
arg
:
validators
.
validRange
(
arg
,
const
.
ALL
_BUS_TYPES_LIST
)
)),
"log_level"
:
(
const
.
DEFAULT_LOG_LEVEL
,
(
lambda
arg
:
validators
.
validRange
(
int
(
arg
),
const
.
ALL_LOG_LEVELS_LIST
)
))
}
}
...
...
settingsd/const.py
View file @
cf1eb01e
...
...
@@ -2,6 +2,7 @@
MY_NAME
=
"settingsd"
RUNTIME_NAME
=
"runtime"
FUNCTIONS_DIR
=
"functions"
ACTIONS_DIR
=
"actions"
...
...
@@ -9,11 +10,11 @@ CONFIGS_DIR = "configs"
CONFIG_FILE_POSTFIX
=
".conf"
SERVICE_
BUS_TYPE_SYSTEM
=
"system"
SERVICE_
BUS_TYPE_SESSION
=
"session"
ALL_
SERVICE_
BUS_TYPES_LIST
=
(
SERVICE_
BUS_TYPE_SYSTEM
,
SERVICE_
BUS_TYPE_SESSION
BUS_TYPE_SYSTEM
=
"system"
BUS_TYPE_SESSION
=
"session"
ALL_BUS_TYPES_LIST
=
(
BUS_TYPE_SYSTEM
,
BUS_TYPE_SESSION
)
LOG_LEVEL_INFO
=
0
...
...
@@ -28,6 +29,6 @@ ALL_LOG_LEVELS_LIST = (
DEFAULT_SERVICE_NAME
=
"org.etersoft.
%
s"
%
(
MY_NAME
)
DEFAULT_SERVICE_PATH
=
"/org/etersoft/
%
s"
%
(
MY_NAME
)
DEFAULT_
SERVICE_BUS_TYPE
=
SERVICE_
BUS_TYPE_SYSTEM
DEFAULT_
BUS_TYPE
=
BUS_TYPE_SYSTEM
DEFAULT_LOG_LEVEL
=
LOG_LEVEL_INFO
settingsd/logger.py
View file @
cf1eb01e
...
...
@@ -37,7 +37,7 @@ def message(message_type, message) :
else
:
raise
UnknownMessageType
(
"Message type
\"
%
d
\"
not in list
%
s"
%
(
message_type
,
ALL_MESSAGES_LIST
))
if
log_level
<=
config
.
value
(
"service"
,
"log_level"
)
:
if
log_level
<=
config
.
value
(
const
.
MY_NAME
,
"log_level"
)
:
text_log_levels_list
=
(
"
%
s [ Info ]:"
%
(
const
.
MY_NAME
),
"
%
s [ Details ]:"
%
(
const
.
MY_NAME
),
...
...
settingsd/service.py
View file @
cf1eb01e
...
...
@@ -13,17 +13,6 @@ import logger
#####
class
Requisites
(
object
)
:
@classmethod
def
serviceName
(
self
)
:
return
None
@classmethod
def
options
(
self
)
:
return
[]
#####
class
Service
(
object
)
:
__metaclass__
=
abc
.
ABCMeta
...
...
@@ -31,17 +20,26 @@ class Service(object) :
Actions
=
shared
.
Actions
@abc.abstractmethod
def
init
(
self
)
:
def
init
Service
(
self
)
:
pass
def
close
(
self
)
:
def
close
Service
(
self
)
:
pass
@classmethod
@abc.abstractmethod
def
serviceName
(
self
)
:
pass
@classmethod
def
options
(
self
)
:
return
[]
#####
class
CustomObject
(
dbus
.
service
.
Object
)
:
def
__init__
(
self
,
object_path
)
:
dbus
.
service
.
Object
.
__init__
(
self
,
config
.
value
(
"runtime"
,
"bus_name"
),
object_path
)
dbus
.
service
.
Object
.
__init__
(
self
,
config
.
value
(
const
.
RUNTIME_NAME
,
"bus_name"
),
object_path
)
self
.
_object_path
=
object_path
...
...
@@ -56,18 +54,18 @@ class CustomObject(dbus.service.Object) :
class
FunctionObject
(
CustomObject
)
:
def
__init__
(
self
,
object_path
)
:
CustomObject
.
__init__
(
self
,
dbus_tools
.
joinPath
(
config
.
value
(
"service"
,
"
path"
),
"functions"
,
object_path
))
CustomObject
.
__init__
(
self
,
dbus_tools
.
joinPath
(
config
.
value
(
const
.
MY_NAME
,
"service_
path"
),
"functions"
,
object_path
))
class
ActionObject
(
CustomObject
)
:
def
__init__
(
self
,
object_path
)
:
CustomObject
.
__init__
(
self
,
dbus_tools
.
joinPath
(
config
.
value
(
"service"
,
"
path"
),
"actions"
,
object_path
))
CustomObject
.
__init__
(
self
,
dbus_tools
.
joinPath
(
config
.
value
(
const
.
MY_NAME
,
"service_
path"
),
"actions"
,
object_path
))
######
def
tracer
(
function
)
:
def
wrapper
(
self
,
*
args_list
,
**
kwargs_dict
)
:
return_value
=
function
(
self
,
*
args_list
,
**
kwargs_dict
)
if
config
.
value
(
"service"
,
"log_level"
)
==
const
.
LOG_LEVEL_DEBUG
:
if
config
.
value
(
const
.
MY_NAME
,
"log_level"
)
==
const
.
LOG_LEVEL_DEBUG
:
logger
.
message
(
logger
.
DEBUG_MESSAGE
,
"Called
\"
%
s::
%
s
\"
with args (
%
s,
%
s) -->
%
s"
%
(
self
.
__class__
.
__name__
,
function
.
__name__
,
str
(
args_list
),
str
(
kwargs_dict
),
str
(
return_value
)
))
return
return_value
...
...
@@ -84,11 +82,11 @@ def customMethod(interface_name) :
def
functionMethod
(
interface_name
)
:
def
decorator
(
function
)
:
return
customMethod
(
dbus_tools
.
joinMethod
(
config
.
value
(
"service"
,
"
name"
),
"functions"
,
interface_name
))(
function
)
return
customMethod
(
dbus_tools
.
joinMethod
(
config
.
value
(
const
.
MY_NAME
,
"service_
name"
),
"functions"
,
interface_name
))(
function
)
return
decorator
def
actionsMethod
(
interface_name
)
:
def
decorator
(
function
)
:
return
customMethod
(
dbus_tools
.
joinMethod
(
config
.
value
(
"service"
,
"
name"
),
"actions"
,
interface_name
))(
function
)
return
customMethod
(
dbus_tools
.
joinMethod
(
config
.
value
(
const
.
MY_NAME
,
"service_
name"
),
"actions"
,
interface_name
))(
function
)
return
decorator
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