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
fd345f6f
Commit
fd345f6f
authored
Sep 10, 2010
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Class with startup modes
parent
8d7f618d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
53 deletions
+104
-53
main.py
main.py
+3
-53
startup.py
settingsd/startup.py
+101
-0
No files found.
main.py
View file @
fd345f6f
...
...
@@ -6,10 +6,8 @@ import syslog
import
getopt
from
settingsd
import
const
from
settingsd
import
config
from
settingsd
import
logger
from
settingsd
import
validators
from
settingsd
import
application
from
settingsd
import
startup
#from settingsd import daemon # TODO
...
...
@@ -80,54 +78,6 @@ if __name__ == "__main__" :
#####
if
not
daemon_mode_flag
:
app
=
application
.
Application
()
try
:
app
.
loadApplicationConfigs
()
except
:
logger
.
error
(
"Initialization error"
)
logger
.
attachException
()
sys
.
exit
(
1
)
if
bus_type
!=
None
:
config
.
setValue
(
config
.
APPLICATION_SECTION
,
"bus_type"
,
bus_type
)
if
log_level
!=
None
:
config
.
setValue
(
config
.
APPLICATION_SECTION
,
"log_level"
,
log_level
)
if
use_syslog_flag
:
syslog
.
openlog
(
config
.
APPLICATION_SECTION
,
syslog
.
LOG_PID
,
syslog
.
LOG_USER
)
config
.
setValue
(
config
.
RUNTIME_SECTION
,
"use_syslog"
,
True
)
try
:
app
.
loadModules
()
app
.
loadServicesConfigs
()
app
.
initBus
()
app
.
initServices
()
logger
.
info
(
"Initialized"
)
except
:
logger
.
error
(
"Initialization error"
)
logger
.
attachException
()
sys
.
exit
(
1
)
try
:
app
.
runLoop
()
except
(
SystemExit
,
KeyboardInterrupt
)
:
try
:
app
.
closeServices
()
except
:
logger
.
error
(
"Critical error on services closing, abort all processes and go boom"
)
app
.
quitLoop
()
logger
.
info
(
"Closed"
)
except
:
logger
.
error
(
"Runtime error, trying to close services"
)
logger
.
attachException
()
try
:
app
.
closeServices
()
except
:
logger
.
error
(
"Critical error on services closing, abort all processes and go boom"
)
app
.
quitLoop
()
logger
.
info
(
"Closed"
)
sys
.
exit
(
1
)
else
:
print
"TODO"
startup_proc
=
startup
.
Startup
(
log_level
,
use_syslog_flag
,
bus_type
,
daemon_mode_flag
)
startup_proc
.
run
()
settingsd/startup.py
0 → 100644
View file @
fd345f6f
# -*- coding: utf-8 -*-
import
sys
import
signal
import
syslog
import
const
import
config
import
logger
import
application
#import daemon # TODO
##### Public classes #####
class
Startup
(
object
)
:
def
__init__
(
self
,
log_level
,
use_syslog_flag
,
bus_type
,
daemon_mode_flag
)
:
object
.
__init__
(
self
)
#####
self
.
_log_level
=
log_level
self
.
_use_syslog_flag
=
use_syslog_flag
self
.
_bus_type
=
bus_type
self
.
_daemon_mode_flag
=
daemon_mode_flag
#####
self
.
_app
=
application
.
Application
()
### Public ###
def
run
(
self
)
:
self
.
prepare
()
if
self
.
_daemon_mode_flag
:
self
.
runDaemon
()
else
:
self
.
runInteractive
()
### Private ###
def
prepare
(
self
)
:
if
self
.
_use_syslog_flag
==
None
:
if
self
.
_daemon_mode_flag
:
syslog
.
openlog
(
const
.
MY_NAME
,
syslog
.
LOG_PID
,
syslog
.
LOG_DAEMON
)
config
.
setValue
(
config
.
RUNTIME_SECTION
,
"use_syslog"
,
True
)
else
:
syslog
.
openlog
(
const
.
MY_NAME
,
syslog
.
LOG_PID
,
(
syslog
.
LOG_DAEMON
if
self
.
_daemon_mode_flag
else
syslog
.
LOG_USER
))
config
.
setValue
(
config
.
RUNTIME_SECTION
,
"use_syslog"
,
True
)
try
:
self
.
_app
.
loadApplicationConfigs
()
except
:
logger
.
error
(
"Initialization error"
)
logger
.
attachException
()
sys
.
exit
(
1
)
if
self
.
_bus_type
!=
None
:
config
.
setValue
(
config
.
APPLICATION_SECTION
,
"bus_type"
,
self
.
_bus_type
)
if
self
.
_log_level
!=
None
:
config
.
setValue
(
config
.
APPLICATION_SECTION
,
"log_level"
,
self
.
_log_level
)
###
def
runInteractive
(
self
)
:
try
:
self
.
_app
.
loadModules
()
self
.
_app
.
loadServicesConfigs
()
self
.
_app
.
initBus
()
self
.
_app
.
initServices
()
logger
.
info
(
"Initialized"
)
except
:
logger
.
error
(
"Initialization error"
)
logger
.
attachException
()
sys
.
exit
(
1
)
try
:
self
.
_app
.
runLoop
()
except
(
SystemExit
,
KeyboardInterrupt
)
:
try
:
self
.
_app
.
closeServices
()
except
:
logger
.
error
(
"Critical error on services closing, abort all processes and go boom"
)
self
.
_app
.
quitLoop
()
logger
.
info
(
"Closed"
)
except
:
logger
.
error
(
"Runtime error, trying to close services"
)
logger
.
attachException
()
try
:
self
.
_app
.
closeServices
()
except
:
logger
.
error
(
"Critical error on services closing, abort all processes and go boom"
)
self
.
_app
.
quitLoop
()
logger
.
error
(
"Closed"
)
sys
.
exit
(
1
)
def
runDaemon
(
self
)
:
print
"TODO"
# TODO
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