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
a0ec3f64
Commit
a0ec3f64
authored
Oct 14, 2010
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Power management and runlevels
parent
5a21c9d8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
0 deletions
+124
-0
main.conf
configs/main.conf
+3
-0
fmod_machine.py
functions/fmod_machine.py
+121
-0
No files found.
configs/main.conf
View file @
a0ec3f64
...
...
@@ -9,6 +9,9 @@ enabled = yes
[
system_services
]
enabled
=
yes
[
machine
]
enabled
=
yes
[
common_info
]
enabled
=
yes
functions/fmod_machine.py
0 → 100644
View file @
a0ec3f64
# -*- coding: utf-8 -*-
import
subprocess
from
settingsd
import
config
from
settingsd
import
service
from
settingsd
import
shared
from
settingsd
import
logger
from
settingsd
import
validators
##### Private constants #####
SERVICE_NAME
=
"machine"
POWER_METHODS_NAMESPACE
=
"power"
RUNLEVELS_METHODS_NAMESPACE
=
"runlevels"
RUNLEVELS
=
"0123456"
SHUTDOWN_OPTION_HALT
=
"-h"
SHUTDOWN_OPTION_REBOOT
=
"-r"
##### Exceptions #####
class
SubprocessFailure
(
Exception
)
:
pass
##### Private classes #####
class
Machine
(
service
.
FunctionObject
)
:
### DBus methods ###
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
shutdown
(
self
)
:
proc_args
=
"
%
s
%
s now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_prog_path"
),
SHUTDOWN_OPTION_HALT
)
return
self
.
execProcess
(
proc_args
)[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
reboot
(
self
)
:
proc_args
=
"
%
s
%
s now"
%
(
config
.
value
(
SERVICE_NAME
,
"shutdown_prog_path"
),
SHUTDOWN_OPTION_REBOOT
)
return
self
.
execProcess
(
proc_args
)[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
suspend
(
self
)
:
return
self
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_suspend_prog_path"
))[
2
]
@service.functionMethod
(
POWER_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
hibernate
(
self
)
:
return
self
.
execProcess
(
config
.
value
(
SERVICE_NAME
,
"pm_hibernate_prog_path"
))[
2
]
###
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
in_signature
=
"i"
,
out_signature
=
"i"
)
def
switchTo
(
self
,
level
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"telinit_prog_path"
),
validators
.
validRange
(
str
(
level
),
RUNLEVELS
))
return
self
.
execProcess
(
proc_args
)[
2
]
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
currentLevel
(
self
)
:
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_prog_path"
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
self
.
execProcess
(
proc_args
)
level_pairs_list
=
proc_stdout
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
:
raise
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
int
(
level_pairs_list
[
1
])
@service.functionMethod
(
RUNLEVELS_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
previousLevel
(
self
)
:
proc_args
=
config
.
value
(
SERVICE_NAME
,
"runlevel_prog_path"
)
(
proc_stdout
,
proc_stderr
,
proc_returncode
)
=
self
.
execProcess
(
proc_args
)
level_pairs_list
=
proc_stdout
.
strip
()
.
split
(
" "
)
if
len
(
level_pairs_list
)
!=
2
or
not
level_pairs_list
[
1
]
in
RUNLEVELS
+
"N"
:
raise
SubprocessFailure
(
"Error while execute
\"
%
s
\"\n
Stdout:
%
s
\n
Stderr:
%
s
\n
Return code:
%
d"
%
(
proc_args
,
proc_stdout
.
strip
(),
proc_stderr
.
strip
(),
proc_returncode
))
return
(
int
(
level_pairs_list
[
0
])
if
level_pairs_list
[
0
]
in
RUNLEVELS
else
-
1
)
### Private ###
def
execProcess
(
self
,
proc_args
)
:
logger
.
debug
(
"{mod}: Executing child process
\"
%
s
\"
"
%
(
proc_args
))
proc
=
subprocess
.
Popen
(
proc_args
,
shell
=
True
,
bufsize
=
1024
,
close_fds
=
True
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
{
"LC_ALL"
:
"C"
})
(
proc_stdout
,
proc_stderr
)
=
proc
.
communicate
()
logger
.
debug
(
"{mod}: Child process
\"
%
s
\"
finished, return_code=
%
d"
%
(
proc_args
,
proc
.
returncode
))
return
(
proc_stdout
,
proc_stderr
,
proc
.
returncode
)
##### Public classes #####
class
Service
(
service
.
Service
)
:
### Public ###
def
initService
(
self
)
:
shared
.
Functions
.
addSharedObject
(
SERVICE_NAME
,
Machine
(
SERVICE_NAME
,
self
))
###
@classmethod
def
serviceName
(
self
)
:
return
SERVICE_NAME
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"shutdown_prog_path"
,
"/sbin/shutdown"
,
str
),
(
SERVICE_NAME
,
"pm_suspend_prog_path"
,
"/usr/sbin/pm-suspend"
,
str
),
(
SERVICE_NAME
,
"pm_hibernate_prog_path"
,
"/usr/sbin/pm-hibernate"
,
str
),
(
SERVICE_NAME
,
"telinit_prog_path"
,
"/sbin/telinit"
,
str
),
(
SERVICE_NAME
,
"runlevel_prog_path"
,
"/sbin/runlevel"
,
str
)
]
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