FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

 
 
LinkBack Thread Tools
 
Old 05-18-2012, 03:18 PM
Vratislav Podzimek
 
Default NTP switch functionality (DatetimeSpoke)

When the NTP switch is turned ON/OFF we want to start/stop the chronyd.service
and make the date/time setting widgets (in)active.
---
pyanaconda/iutil.py | 25 +++++++++++++
pyanaconda/ui/gui/spokes/datetime_spoke.py | 53 ++++++++++++++++++++++++++-
pyanaconda/ui/gui/spokes/datetime_spoke.ui | 1 +
3 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py
index e7a4574..d4c5857 100644
--- a/pyanaconda/iutil.py
+++ b/pyanaconda/iutil.py
@@ -1015,3 +1015,28 @@ def lsmod():
with open("/proc/modules") as f:
lines = f.readlines()
return [l.split()[0] for l in lines]
+
+def _run_systemctl(command, service):
+ """
+ Runs 'systemctl command service.service'
+
+ @return: exit status of the systemctl
+
+ """
+
+ service_name = service + ".service"
+ ret = execWithRedirect("systemctl", [command, service_name], stdin=None,
+ stdout="/dev/null")
+
+ return ret
+
+def start_service(service):
+ return _run_systemctl("start", service)
+
+def stop_service(service):
+ return _run_systemctl("stop", service)
+
+def service_running(service):
+ ret = _run_systemctl("status", service)
+
+ return ret == 0
diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py b/pyanaconda/ui/gui/spokes/datetime_spoke.py
index 3e03cd2..d320508 100644
--- a/pyanaconda/ui/gui/spokes/datetime_spoke.py
+++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py
@@ -23,13 +23,13 @@ import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
N_ = lambda x: x

-from gi.repository import AnacondaWidgets, GLib
+from gi.repository import AnacondaWidgets, GLib, Gtk

from pyanaconda.ui.gui import UIObject
from pyanaconda.ui.gui.spokes import NormalSpoke
from pyanaconda.ui.gui.categories.localization import LocalizationCategory

-from pyanaconda import localization
+from pyanaconda import localization, iutil, network
import datetime, os

__all__ = ["DatetimeSpoke"]
@@ -143,6 +143,17 @@ class DatetimeSpoke(NormalSpoke):

self._update_datetime()

+ has_active_network = network.hasActiveNetDev()
+ if not has_active_network:
+ self._show_no_network_warning()
+ else:
+ self.window.clear_info()
+
+ ntp_working = iutil.service_running("chronyd") and has_active_network
+
+ self._networkTimeSwitch = self.builder.get_object("networkTimeSwitch")
+ self._networkTimeSwitch.set_active(ntp_working)
+
def add_to_store(self, store, item):
store.append([item])

@@ -469,3 +480,41 @@ class DatetimeSpoke(NormalSpoke):

self._hoursLabel.set_text("%0.2d" % new_hours)

+ def _set_date_time_setting_sensitive(self, sensitive):
+ #contains all date/time setting widgets
+ footer_alignment = self.builder.get_object("footerAlignment")
+ footer_alignment.set_sensitive(sensitive)
+
+ def _show_no_network_warning(self):
+ self.window.set_info(Gtk.MessageType.WARNING,
+ _("You need to set up network first if you "
+ "want to use NTP"))
+
+ def on_ntp_switched(self, switch, *args):
+ #turned ON
+ if switch.get_active():
+ if not network.hasActiveNetDev():
+ self._show_no_network_warning()
+ switch.set_active(False)
+ return
+ else:
+ self.window.clear_info()
+
+ ret = iutil.start_service("chronyd")
+ self._set_date_time_setting_sensitive(False)
+
+ #if starting chronyd failed and chronyd is not running,
+ #set switch back to OFF
+ if (ret != 0) and not iutil.service_running("chronyd"):
+ switch.set_active(False)
+
+ #turned OFF
+ else:
+ self._set_date_time_setting_sensitive(True)
+ ret = iutil.stop_service("chronyd")
+
+ #if stopping chronyd failed and chronyd is running,
+ #set switch back to ON
+ if (ret != 0) and iutil.service_running("chronyd"):
+ switch.set_active(True)
+
diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.ui b/pyanaconda/ui/gui/spokes/datetime_spoke.ui
index 5247301..f705d2b 100644
--- a/pyanaconda/ui/gui/spokes/datetime_spoke.ui
+++ b/pyanaconda/ui/gui/spokes/datetime_spoke.ui
@@ -159,6 +159,7 @@
<property name="halign">end</property>
<property name="valign">start</property>
<property name="use_action_appearance">False</property>
+ <signal name="notify::active" handler="on_ntp_switched" swapped="no"/>
</object>
</child>
</object>
--
1.7.4.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 03:01 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org