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
3237b4e7
Commit
3237b4e7
authored
Dec 07, 2010
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New parsers for ntp_config
parent
d381ba9d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
15 deletions
+36
-15
fmod_ntp_config.py
plugins/functions/fmod_ntp_config.py
+36
-15
No files found.
plugins/functions/fmod_ntp_config.py
View file @
3237b4e7
...
...
@@ -24,26 +24,50 @@ class NtpConfig(service.FunctionObject) :
@service.functionMethod
(
NTP_METHODS_NAMESPACE
,
in_signature
=
"as"
)
def
setServers
(
self
,
servers_list
)
:
self
.
setConfigValue
(
"server"
,
servers_list
)
@service.functionMethod
(
NTP_METHODS_NAMESPACE
,
out_signature
=
"as"
)
def
servers
(
self
)
:
return
self
.
configValue
(
"server"
)
###
@service.functionMethod
(
NTP_METHODS_NAMESPACE
)
def
request
(
self
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"ntpdate_prog_path"
),
" "
.
join
(
self
.
servers
()))
tools
.
execProcess
(
proc_args
)
### Private ###
def
setConfigValue
(
self
,
variable_name
,
values_list
,
replace_flag
=
True
)
:
if
not
type
(
values_list
)
.
__name__
in
(
"list"
,
"tuple"
)
:
values_list
=
[
values_list
]
if
not
os
.
access
(
config
.
value
(
SERVICE_NAME
,
"ntp_config_file_path"
),
os
.
F_OK
)
:
open
(
config
.
value
(
SERVICE_NAME
,
"ntp_config_file_path"
),
"w"
)
.
close
()
ntp_config_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"ntp_config_file_path"
),
"r+"
)
ntp_config_file_data
=
ntp_config_file
.
read
()
ntp_config_file_data
=
re
.
sub
(
r"(\n|\A)server[\s\t]+[^\n]+"
,
""
,
ntp_config_file_data
)
for
servers_list_item
in
servers_list
:
ntp_config_file_data
+=
"server
%
s
\n
"
%
(
servers_list_item
)
variable_regexp
=
re
.
compile
(
r"(((\n|\A)
%
s[\s\t]+[^\n]*)+)"
%
(
variable_name
))
variable
=
"
\n
"
.
join
([
"
%
s
%
s"
%
(
variable_name
,
values_list_item
)
for
values_list_item
in
values_list
])
if
variable_regexp
.
search
(
ntp_config_file_data
)
:
if
len
(
variable
)
!=
0
:
variable
=
(
"
\n
"
if
replace_flag
else
"
\\
1
\n
"
)
+
variable
ntp_config_file_data
=
variable_regexp
.
sub
(
variable
,
ntp_config_file_data
)
elif
len
(
variable
)
!=
0
:
ntp_config_file_data
+=
(
"
\n
"
if
ntp_config_file_data
[
-
1
]
!=
"
\n
"
else
""
)
+
variable
+
"
\n
"
ntp_config_file
.
seek
(
0
)
ntp_config_file
.
truncate
()
ntp_config_file
.
write
(
ntp_config_file_data
)
try
:
ntp_config_file
.
close
()
ntp_config_file
_data
.
close
()
except
:
pass
@service.functionMethod
(
NTP_METHODS_NAMESPACE
,
out_signature
=
"as"
)
def
servers
(
self
)
:
def
configValue
(
self
,
variable_name
)
:
if
os
.
access
(
config
.
value
(
SERVICE_NAME
,
"ntp_config_file_path"
),
os
.
F_OK
)
:
ntp_config_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"ntp_config_file_path"
),
"r"
)
ntp_config_file_list
=
ntp_config_file
.
read
()
.
split
(
"
\n
"
)
...
...
@@ -51,21 +75,18 @@ class NtpConfig(service.FunctionObject) :
ntp_config_file
.
close
()
except
:
pass
servers_list
=
[]
variable_regexp
=
re
.
compile
(
r"^
%
s[\s\t]+([^\n]*)"
%
(
variable_name
))
variables_list
=
[]
for
ntp_config_file_list_item
in
ntp_config_file_list
:
if
len
(
ntp_config_file_list_item
)
==
0
:
continue
if
re
.
match
(
r"^server[\s\t]+"
,
ntp_config_file_list_item
)
!=
None
:
servers_list
.
append
(
re
.
split
(
r"[\s\t]+"
,
ntp_config_file_list_item
)[
1
])
return
servers_list
variable_match
=
variable_regexp
.
match
(
ntp_config_file_list_item
)
if
variable_match
!=
None
:
variables_list
.
append
(
variable_match
.
group
(
1
))
return
variables_list
return
[]
###
@service.functionMethod
(
NTP_METHODS_NAMESPACE
)
def
request
(
self
)
:
proc_args
=
"
%
s
%
s"
%
(
config
.
value
(
SERVICE_NAME
,
"ntpdate_prog_path"
),
" "
.
join
(
self
.
servers
()))
tools
.
execProcess
(
proc_args
)
##### Public classes #####
...
...
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