[pykickstart] [PATCH] Add --nontp option and a way to specify NTP servers to the timezone command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We need a place to store NTP servers specified in the UI and it has to be
in ksdata, so let's allow users to specify them in kickstarts as well.
Since NTP is the default behaviour in the UI installation I think it should
also be the default for the kickstart installation. Thus there should be
--nontp option rather then --ntp option.
---
 pykickstart/commands/timezone.py |   49 ++++++++++++++++++++++++++++++++++++++
 pykickstart/handlers/control.py  |    2 +-
 2 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/pykickstart/commands/timezone.py b/pykickstart/commands/timezone.py
index f5441de..0678a62 100644
--- a/pykickstart/commands/timezone.py
+++ b/pykickstart/commands/timezone.py
@@ -24,6 +24,8 @@ from pykickstart.options import *
 import gettext
 _ = lambda x: gettext.ldgettext("pykickstart", x)
 
+import re
+
 class FC3_Timezone(KickstartCommand):
     removedKeywords = KickstartCommand.removedKeywords
     removedAttrs = KickstartCommand.removedAttrs
@@ -84,3 +86,50 @@ class FC6_Timezone(FC3_Timezone):
         op = FC3_Timezone._getParser(self)
         op.add_option("--utc", "--isUtc", dest="isUtc", action="store_true", default=False)
         return op
+
+class F18_Timezone(FC6_Timezone):
+    def __init__(self, writePriority=0, *args, **kwargs):
+        FC6_Timezone.__init__(self, writePriority, *args, **kwargs)
+        self.op = self._getParser()
+        self.ntp = kwargs.get("ntp", False)
+        self.ntp_servers = kwargs.get("ntp_servers", set())
+
+    def __str__(self):
+        retval = FC6_Timezone.__str__(self)
+
+        if self.ntp:
+            retval += "--ntp"
+
+        return retval
+
+    def _getParser(self):
+        op = FC6_Timezone._getParser(self)
+        op.add_option("--nontp", dest="nontp", action="store_true", default=False)
+        return op
+
+    def parse(self, args):
+        (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
+        self._setToSelf(self.op, opts)
+
+        #we need to split args into timezone(s) and NTP servers
+
+        #examples: Europe/Prague, America/Argentina/Buenos_Aires
+        timezone_re = re.compile(r"^[A-Z][ a-z]*/[A-Z][_/A-Za-z]*$")
+
+        #example: ntp.cesnet.cz
+        ntpsrv_re = re.compile(r"^[-a-zA-Z0-9.]+$")
+
+        for arg in extra:
+            if timezone_re.match(arg):
+                #last timezone specified wins
+                self.timezone = arg
+
+            elif ntpsrv_re.match(arg):
+                self.ntp_servers.add(arg)
+
+        if not self.timezone:
+            err_msg = _("Kickstart command 'timezone' requires valid timezone"\
+                        " as an argument")
+            raise KickstartValueError(formatErrorMsg(self.lineno, msg=err_msg))
+
+        return self
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index 6fe7c10..9b39b10 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -933,7 +933,7 @@ commandMap = {
         "skipx": skipx.FC3_SkipX,
         "sshpw": sshpw.F13_SshPw,
         "text": displaymode.FC3_DisplayMode,
-        "timezone": timezone.FC6_Timezone,
+        "timezone": timezone.F18_Timezone,
         "updates": updates.F7_Updates,
         "upgrade": upgrade.F11_Upgrade,
         "url": method.F14_Method,
-- 
1.7.4.4

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


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux