Commit 3944bff0 authored by Devaev Maxim's avatar Devaev Maxim

Fixed regexp for ntp servers, code for checks /etc/ntp.conf

parent f3ea0489
# -*- coding: utf-8 -*-
import os
import re
from settingsd import config
......@@ -23,10 +24,13 @@ class NtpConfig(service.FunctionObject) :
@service.functionMethod(NTP_METHODS_NAMESPACE, in_signature="as")
def setServers(self, servers_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"\nserver[\s\t]+[^\n]+", "", ntp_config_file_data)
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)
......@@ -40,6 +44,7 @@ class NtpConfig(service.FunctionObject) :
@service.functionMethod(NTP_METHODS_NAMESPACE, out_signature="as")
def servers(self) :
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")
try :
......@@ -53,6 +58,7 @@ class NtpConfig(service.FunctionObject) :
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
return []
###
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment