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
ca308c0d
Commit
ca308c0d
authored
Sep 10, 2010
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
0f0c92ba
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
21 deletions
+36
-21
main.py
main.py
+6
-4
application.py
settingsd/application.py
+5
-5
config.py
settingsd/config.py
+13
-3
const.py
settingsd/const.py
+0
-1
logger.py
settingsd/logger.py
+2
-2
service.py
settingsd/service.py
+10
-6
No files found.
main.py
View file @
ca308c0d
...
...
@@ -87,15 +87,16 @@ if __name__ == "__main__" :
app
.
loadApplicationConfigs
()
except
:
logger
.
error
(
"Initialization error"
)
logger
.
attachException
()
sys
.
exit
(
1
)
if
bus_type
!=
None
:
config
.
setValue
(
con
st
.
MY_NAME
,
"bus_type"
,
bus_type
)
config
.
setValue
(
con
fig
.
APPLICATION_SECTION
,
"bus_type"
,
bus_type
)
if
log_level
!=
None
:
config
.
setValue
(
con
st
.
MY_NAME
,
"log_level"
,
log_level
)
config
.
setValue
(
con
fig
.
APPLICATION_SECTION
,
"log_level"
,
log_level
)
if
use_syslog_flag
:
syslog
.
openlog
(
con
st
.
MY_NAME
,
syslog
.
LOG_PID
,
syslog
.
LOG_USER
)
config
.
setValue
(
con
st
.
RUNTIME_NAME
,
"use_syslog"
,
True
)
syslog
.
openlog
(
con
fig
.
APPLICATION_SECTION
,
syslog
.
LOG_PID
,
syslog
.
LOG_USER
)
config
.
setValue
(
con
fig
.
RUNTIME_SECTION
,
"use_syslog"
,
True
)
try
:
app
.
loadModules
()
...
...
@@ -105,6 +106,7 @@ if __name__ == "__main__" :
logger
.
info
(
"Initialized"
)
except
:
logger
.
error
(
"Initialization error"
)
logger
.
attachException
()
sys
.
exit
(
1
)
try
:
...
...
settingsd/application.py
View file @
ca308c0d
...
...
@@ -61,7 +61,7 @@ class Application(object) :
sys
.
path
.
remove
(
const
.
ACTIONS_DIR
)
def
loadApplicationConfigs
(
self
)
:
config
.
loadConfigs
(
only_sections_list
=
(
con
st
.
MY_NAME
,))
config
.
loadConfigs
(
only_sections_list
=
(
con
fig
.
APPLICATION_SECTION
,))
def
loadServicesConfigs
(
self
)
:
for
service_name
in
self
.
_services_dict
.
keys
()
:
...
...
@@ -75,14 +75,14 @@ class Application(object) :
logger
.
error
(
"Error on set options tuple
%
s"
%
(
str
(
service_options_list_item
)))
logger
.
attachException
()
config
.
loadConfigs
(
exclude_sections_list
=
(
con
st
.
MY_NAME
,))
config
.
loadConfigs
(
exclude_sections_list
=
(
con
fig
.
APPLICATION_SECTION
,))
def
initBus
(
self
)
:
bus_type
=
config
.
value
(
con
st
.
MY_NAME
,
"bus_type"
)
service_name
=
config
.
value
(
con
st
.
MY_NAME
,
"service_name"
)
bus_type
=
config
.
value
(
con
fig
.
APPLICATION_SECTION
,
"bus_type"
)
service_name
=
config
.
value
(
con
fig
.
APPLICATION_SECTION
,
"service_name"
)
try
:
config
.
setValue
(
con
st
.
RUNTIME_NAME
,
"bus_name"
,
dbus
.
service
.
BusName
(
service_name
,
config
.
setValue
(
con
fig
.
RUNTIME_SECTION
,
"bus_name"
,
dbus
.
service
.
BusName
(
service_name
,
(
dbus
.
SystemBus
()
if
bus_type
==
const
.
BUS_TYPE_SYSTEM
else
dbus
.
SessionBus
()
)))
except
:
logger
.
error
(
"Could not connect to D-Bus
\"
%
s
\"
"
%
(
bus_type
))
...
...
settingsd/config.py
View file @
ca308c0d
...
...
@@ -9,15 +9,25 @@ import config
import
validators
##### Public constants #####
APPLICATION_SECTION
=
const
.
MY_NAME
RUNTIME_SECTION
=
"runtime"
ALL_SECTIONS_LIST
=
(
APPLICATION_SECTION
,
RUNTIME_SECTION
)
##### Private objects #####
ConfigDictObject
=
{
const
.
MY_NAME
:
{
APPLICATION_SECTION
:
{
"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
)
))
},
const
.
RUNTIME_NAME
:
{
RUNTIME_SECTION
:
{
"bus_name"
:
(
None
,
None
),
"use_syslog"
:
(
False
,
None
)
}
...
...
@@ -51,7 +61,7 @@ def validator(section, option) :
def
loadConfigs
(
only_sections_list
=
(),
exclude_sections_list
=
())
:
only_sections_list
=
list
(
only_sections_list
)
exclude_sections_list
=
list
(
exclude_sections_list
)
exclude_sections_list
.
append
(
const
.
RUNTIME_NAME
)
exclude_sections_list
.
append
(
RUNTIME_SECTION
)
for
config_files_list_item
in
os
.
listdir
(
const
.
CONFIGS_DIR
)
:
if
not
config_files_list_item
.
endswith
(
const
.
CONFIG_FILE_POSTFIX
)
:
...
...
settingsd/const.py
View file @
ca308c0d
...
...
@@ -3,7 +3,6 @@
##### Public constants #####
MY_NAME
=
"settingsd"
RUNTIME_NAME
=
"runtime"
VERSION
=
"0.1"
...
...
settingsd/logger.py
View file @
ca308c0d
...
...
@@ -61,12 +61,12 @@ def log(message_type, message) :
if
not
message_type
in
ALL_MESSAGES_LIST
:
raise
UnknownMessageType
(
"Message type
\"
%
d
\"
not in list
%
s"
%
(
message_type
,
ALL_MESSAGES_LIST
))
if
message_type
[
2
]
<=
config
.
value
(
con
st
.
MY_NAME
,
"log_level"
)
:
if
message_type
[
2
]
<=
config
.
value
(
con
fig
.
APPLICATION_SECTION
,
"log_level"
)
:
message_type_texts_list
=
(
"Error"
,
"Warning"
,
"Notice"
,
"Info"
,
"Details"
,
"Debug"
)
message
=
"[
%
s ]:
%
s"
%
(
message_type_texts_list
[
message_type
[
0
]],
message
)
print
>>
sys
.
stderr
,
const
.
MY_NAME
,
message
if
config
.
value
(
con
st
.
RUNTIME_NAME
,
"use_syslog"
)
:
if
config
.
value
(
con
fig
.
RUNTIME_SECTION
,
"use_syslog"
)
:
syslog
.
syslog
(
message_type
[
1
],
message
)
settingsd/service.py
View file @
ca308c0d
...
...
@@ -52,7 +52,7 @@ class Service(ServiceInterface, ServiceRequisitesInterface) :
#####
class
CustomObject
(
dbus
.
service
.
Object
)
:
def
__init__
(
self
,
object_path
)
:
dbus
.
service
.
Object
.
__init__
(
self
,
config
.
value
(
con
st
.
RUNTIME_NAME
,
"bus_name"
),
object_path
)
dbus
.
service
.
Object
.
__init__
(
self
,
config
.
value
(
con
fig
.
RUNTIME_SECTION
,
"bus_name"
),
object_path
)
self
.
_object_path
=
object_path
...
...
@@ -71,18 +71,20 @@ class CustomObject(dbus.service.Object) :
class
FunctionObject
(
CustomObject
)
:
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
(
config
.
APPLICATION_SECTION
,
"service_path"
),
"functions"
,
object_path
))
class
ActionObject
(
CustomObject
)
:
def
__init__
(
self
,
object_path
)
:
CustomObject
.
__init__
(
self
,
dbus_tools
.
joinPath
(
config
.
value
(
const
.
MY_NAME
,
"service_path"
),
"actions"
,
object_path
))
CustomObject
.
__init__
(
self
,
dbus_tools
.
joinPath
(
config
.
value
(
config
.
APPLICATION_SECTION
,
"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
)
if
config
.
value
(
con
st
.
MY_NAME
,
"log_level"
)
==
const
.
LOG_LEVEL_DEBUG
:
if
config
.
value
(
con
fig
.
APPLICATION_SECTION
,
"log_level"
)
==
const
.
LOG_LEVEL_DEBUG
:
logger
.
debug
(
"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
...
...
@@ -102,11 +104,13 @@ def customMethod(interface_name) :
def
functionMethod
(
interface_name
)
:
def
decorator
(
function
)
:
return
customMethod
(
dbus_tools
.
joinMethod
(
config
.
value
(
const
.
MY_NAME
,
"service_name"
),
"functions"
,
interface_name
))(
function
)
return
customMethod
(
dbus_tools
.
joinMethod
(
config
.
value
(
config
.
APPLICATION_SECTION
,
"service_name"
),
"functions"
,
interface_name
))(
function
)
return
decorator
def
actionsMethod
(
interface_name
)
:
def
decorator
(
function
)
:
return
customMethod
(
dbus_tools
.
joinMethod
(
config
.
value
(
const
.
MY_NAME
,
"service_name"
),
"actions"
,
interface_name
))(
function
)
return
customMethod
(
dbus_tools
.
joinMethod
(
config
.
value
(
config
.
APPLICATION_SECTION
,
"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