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
f3ea0489
Commit
f3ea0489
authored
Nov 24, 2010
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added module for date/time configuration
parent
0df0b6eb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
141 additions
and
0 deletions
+141
-0
main.conf
configs/settingsd/main.conf
+3
-0
fmod_date_time.py
plugins/functions/fmod_date_time.py
+138
-0
No files found.
configs/settingsd/main.conf
View file @
f3ea0489
...
@@ -24,3 +24,6 @@ enabled = yes
...
@@ -24,3 +24,6 @@ enabled = yes
[
ntp_config
]
[
ntp_config
]
enabled
=
yes
enabled
=
yes
[
date_time
]
enabled
=
yes
plugins/functions/fmod_date_time.py
0 → 100644
View file @
f3ea0489
# -*- coding: utf-8 -*-
import
os
import
time
import
re
import
hashlib
from
settingsd
import
config
from
settingsd
import
service
from
settingsd
import
shared
from
settingsd
import
tools
##### Private constants #####
SERVICE_NAME
=
"date_time"
SYSTEM_CLOCK_METHODS_NAMESPACE
=
"time.systemClock"
HARDWARE_CLOCK_METHODS_NAMESPACE
=
"time.hardwareClock"
ZONE_METHODS_NAMESPACE
=
"time.zone"
##### Exceptions #####
class
InvalidTimeZone
(
Exception
)
:
pass
##### Private classes #####
class
DateTime
(
service
.
FunctionObject
)
:
### DBus methods ###
@service.functionMethod
(
SYSTEM_CLOCK_METHODS_NAMESPACE
,
in_signature
=
"iiiiii"
,
out_signature
=
"i"
)
def
setUtcTime
(
self
,
month
,
monthday
,
hour
,
minute
,
year
,
second
)
:
proc_args
=
"
%
s -u
%02
d
%02
d
%02
d
%02
d
%04
d.
%02
d"
%
(
config
.
value
(
SERVICE_NAME
,
"date_prog_path"
),
month
,
monthday
,
hour
,
minute
,
year
,
second
)
return
tools
.
execProcess
(
proc_args
)[
2
]
@service.functionMethod
(
SYSTEM_CLOCK_METHODS_NAMESPACE
,
out_signature
=
"iiiiii"
)
def
utcTime
(
self
)
:
gm_time
=
time
.
gmtime
()
return
(
gm_time
.
tm_mon
,
gm_time
.
tm_mday
,
gm_time
.
tm_hour
,
gm_time
.
tm_min
,
gm_time
.
tm_year
,
gm_time
.
tm_sec
)
###
@service.functionMethod
(
ZONE_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
setTimeZone
(
self
,
zone
)
:
if
not
os
.
access
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir_path"
),
zone
),
os
.
F_OK
)
:
raise
InvalidTimeZone
(
"Unknown time zone
\"
%
s
\"
"
%
(
zone
))
os
.
remove
(
config
.
value
(
SERVICE_NAME
,
"localtime_file_path"
))
os
.
symlink
(
os
.
path
.
join
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir_path"
),
zone
),
config
.
value
(
SERVICE_NAME
,
"localtime_file_path"
))
if
not
os
.
access
(
config
.
value
(
SERVICE_NAME
,
"clock_config_path"
),
os
.
F_OK
)
:
open
(
config
.
value
(
SERVICE_NAME
,
"clock_config_path"
),
"w"
)
.
close
()
clock_config_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"clock_config_path"
),
"r+"
)
clock_config_file_data
=
clock_config_file
.
read
()
clock_config_file_data
=
re
.
sub
(
r"(\A|\n)ZONE=[\"\']?[a-zA-Z0-9/]*[\"\']?"
,
"
\n
ZONE=
\"
%
s
\"
"
%
(
zone
),
clock_config_file_data
)
clock_config_file
.
seek
(
0
)
clock_config_file
.
truncate
()
clock_config_file
.
write
(
clock_config_file_data
)
try
:
clock_config_file
.
close
()
except
:
pass
@service.functionMethod
(
ZONE_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
timeZone
(
self
)
:
if
os
.
access
(
config
.
value
(
SERVICE_NAME
,
"clock_config_path"
),
os
.
F_OK
)
:
clock_config_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"clock_config_path"
))
clock_config_file_data
=
clock_config_file
.
read
()
try
:
clock_config_file
.
close
()
except
:
pass
zone_match
=
re
.
search
(
r"(\A|\n)ZONE=[\"\']?([a-zA-Z0-9/]*)[\"\']?"
,
clock_config_file_data
)
if
zone_match
!=
None
:
return
os
.
path
.
normpath
(
zone_match
.
group
(
2
))
try
:
zoneinfo_dir_path
=
os
.
path
.
normpath
(
os
.
readlink
(
config
.
value
(
SERVICE_NAME
,
"localtime_file_path"
)))
except
:
zoneinfo_cache_dict
=
{}
for
(
root_dir_path
,
dirs_list
,
files_list
)
in
os
.
walk
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir_path"
))
:
for
files_list_item
in
files_list
:
zone_file_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
root_dir_path
,
files_list_item
))
zone_file
=
open
(
zone_file_path
)
zoneinfo_cache_dict
[
hashlib
.
sha1
(
zone_file
.
read
())
.
hexdigest
()]
=
zone_file_path
try
:
zone_file
.
close
()
except
:
pass
zone_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"localtime_file_path"
))
zone_file_hash
=
hashlib
.
sha1
(
zone_file
.
read
())
.
hexdigest
()
try
:
zone_file
.
close
()
except
:
pass
zoneinfo_dir_path
=
(
zoneinfo_cache_dict
[
zone_file_hash
]
if
zoneinfo_cache_dict
.
has_key
(
zone_file_hash
)
else
""
)
zoneinfo_dir_path_regexp_str
=
r"^
%
s/+(.*)"
%
(
config
.
value
(
SERVICE_NAME
,
"zoneinfo_dir_path"
))
return
os
.
path
.
normpath
(
re
.
sub
(
zoneinfo_dir_path_regexp_str
,
r"\1"
,
zoneinfo_dir_path
))
###
@service.functionMethod
(
HARDWARE_CLOCK_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
syncWithSystem
(
self
)
:
return
tools
.
execProcess
(
"
%
s --systohc"
%
(
config
.
value
(
SERVICE_NAME
,
"hwclock_prog_path"
)))[
0
]
##### Public classes #####
class
Service
(
service
.
Service
)
:
### Public ###
def
initService
(
self
)
:
shared
.
Functions
.
addSharedObject
(
SERVICE_NAME
,
DateTime
(
SERVICE_NAME
,
self
))
### Private ###
@classmethod
def
serviceName
(
self
)
:
return
SERVICE_NAME
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"date_prog_path"
,
"/bin/date"
,
str
),
(
SERVICE_NAME
,
"hwclock_prog_path"
,
"/usr/sbin/hwclock"
,
str
),
(
SERVICE_NAME
,
"localtime_file_path"
,
"/etc/localtime"
,
str
),
(
SERVICE_NAME
,
"zoneinfo_dir_path"
,
"/usr/share/zoneinfo"
,
str
),
(
SERVICE_NAME
,
"clock_config_path"
,
"/etc/sysconfig/clock"
,
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