>From 77addeff8a9fb59c7ba96a463c2a3e6f66690b7f Mon Sep 17 00:00:00 2001
From: Colin Walters <walters@verbum.org>
Date: Tue, 11 Mar 2014 09:33:36 -0400
Subject: [PATCH] ostreesetup: New command

This tells the installer to handle an OSTree repository.
---
 pykickstart/commands/__init__.py    |  3 +-
 pykickstart/commands/ostreesetup.py | 75 +++++++++++++++++++++++++++++++++++++
 pykickstart/handlers/control.py     |  2 +
 tests/commands/ostreesetup.py       | 38 +++++++++++++++++++
 4 files changed, 117 insertions(+), 1 deletion(-)
 create mode 100644 pykickstart/commands/ostreesetup.py
 create mode 100644 tests/commands/ostreesetup.py

diff --git a/pykickstart/commands/__init__.py b/pykickstart/commands/__init__.py
index c5145ba..ed4d649 100644
--- a/pykickstart/commands/__init__.py
+++ b/pykickstart/commands/__init__.py
@@ -21,6 +21,7 @@ import authconfig, autopart, autostep, bootloader, btrfs, clearpart, cdrom, devi
 import deviceprobe, displaymode, dmraid, driverdisk, eula, fcoe, firewall, firstboot
 import group, harddrive, ignoredisk, interactive, iscsi, iscsiname, key, keyboard, lang
 import langsupport, lilocheck, liveimg, logging, logvol, mediacheck, method, monitor
-import mouse, multipath, network, nfs, partition, raid, realm, reboot, repo, rescue
+import mouse, multipath, network, nfs, ostreesetup
+import partition, raid, realm, reboot, repo, rescue
 import rootpw, selinux, services, skipx, sshpw, timezone, updates, upgrade, url, user
 import unsupported_hardware, vnc, volgroup, xconfig, zerombr, zfcp
diff --git a/pykickstart/commands/ostreesetup.py b/pykickstart/commands/ostreesetup.py
new file mode 100644
index 0000000..f9f4426
--- /dev/null
+++ b/pykickstart/commands/ostreesetup.py
@@ -0,0 +1,75 @@
+#
+# Copyright (C) 2014  Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# the GNU General Public License v.2, or (at your option) any later version.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY expressed or implied, including the implied warranties of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+# Public License for more details.  You should have received a copy of the
+# GNU General Public License along with this program; if not, write to the
+# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
+# source code or documentation are not subject to the GNU General Public
+# License and may only be used or replicated with the express permission of
+# Red Hat, Inc.
+#
+
+from pykickstart.base import KickstartCommand
+from pykickstart.options import KSOptionParser
+
+import gettext
+_ = lambda x: gettext.ldgettext("pykickstart", x)
+
+class F20_OSTreeSetup(KickstartCommand):
+    removedKeywords = KickstartCommand.removedKeywords
+    removedAttrs = KickstartCommand.removedAttrs
+
+    def __init__(self, *args, **kwargs):
+        KickstartCommand.__init__(self, *args, **kwargs)
+        self.op = self._getParser()
+        self.osname = kwargs.get('osname', None)
+        self.remote = kwargs.get("remote", self.osname)
+        self.url = kwargs.get('url', None)
+        self.ref = kwargs.get('ref', None)
+        self.noGpg = kwargs.get('noGpg', False)
+
+    def __str__(self):
+        retval = KickstartCommand.__str__(self)
+
+        if self.osname:
+            retval += "# OSTree setup\n"
+            retval += "ostreesetup %s\n" % self._getArgsAsStr()
+
+        return retval
+
+    def _getArgsAsStr(self):
+        retcmd = []
+        if self.osname:
+            retcmd.append('--osname="%s"' % self.osname)
+        if self.remote:
+            retcmd.append('--remote="%s"' % self.remote)
+        if self.url:
+            retcmd.append('--url="%s"' % self.url)
+        if self.ref:
+            retcmd.append('--ref="%s"' % self.ref)
+        if self.noGpg:
+            retcmd.append('--nogpg')
+        return ' '.join(retcmd)
+
+    def _getParser(self):
+        op = KSOptionParser()
+        op.add_option("--osname", dest="osname", required=1)
+        op.add_option("--remote", dest="remote")
+        op.add_option("--url", dest="url", required=1)
+        op.add_option("--ref", dest="ref", required=1)
+        op.add_option("--nogpg", action="store_true")
+        return op
+
+    def parse(self, args):
+        (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
+        self._setToSelf(self.op, opts)
+        if self.remote is None:
+            self.remote = self.osname
+        return self
diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py
index 6e654a5..90547c7 100644
--- a/pykickstart/handlers/control.py
+++ b/pykickstart/handlers/control.py
@@ -1060,6 +1060,7 @@ commandMap = {
         "multipath": multipath.FC6_MultiPath,
         "network": network.F20_Network,
         "nfs": nfs.FC6_NFS,
+        "ostreesetup": ostreesetup.F20_OSTreeSetup,
         "part": partition.F20_Partition,
         "partition": partition.F20_Partition,
         "poweroff": reboot.F18_Reboot,
@@ -1349,6 +1350,7 @@ commandMap = {
         "multipath": multipath.FC6_MultiPath,
         "network": network.F20_Network,
         "nfs": nfs.FC6_NFS,
+        "ostreesetup": ostreesetup.F20_OSTreeSetup,
         "part": partition.F20_Partition,
         "partition": partition.F20_Partition,
         "poweroff": reboot.F18_Reboot,
diff --git a/tests/commands/ostreesetup.py b/tests/commands/ostreesetup.py
new file mode 100644
index 0000000..30241de
--- /dev/null
+++ b/tests/commands/ostreesetup.py
@@ -0,0 +1,38 @@
+#
+# Colin Walters <walters@redhat.com>
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This copyrighted material is made available to anyone wishing to use, modify,
+# copy, or redistribute it subject to the terms and conditions of the GNU
+# General Public License v.2.  This program is distributed in the hope that it
+# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
+# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  Any Red Hat
+# trademarks that are incorporated in the source code or documentation are not
+# subject to the GNU General Public License and may only be used or replicated
+# with the express permission of Red Hat, Inc.
+#
+
+import unittest
+from tests.baseclass import *
+
+class F20_TestCase(CommandTest):
+    def runTest(self):
+        # pass
+        self.assert_parse("ostreesetup --osname=fedora-atomic --url=http://example.com/repo --ref=fedora-atomic/sometest/base/core")
+        cmdstr = "ostreesetup --osname=\"fedora-atomic\" --remote=\"fedora-atomic\" --url=\"http://example.com/repo\" --ref=\"fedora-atomic/sometest/base/core\""
+        self.assert_parse(cmdstr, cmdstr + '\n')
+
+        # fail - we have required arguments
+        self.assert_parse_error("ostreesetup", KickstartValueError)
+        self.assert_parse_error("ostreesetup --os=fedora-atomic", KickstartValueError)
+        self.assert_parse_error("ostreesetup --os=fedora-atomic --url=http://example.com/repo", KickstartValueError)
+        self.assert_parse_error("ostreesetup --bacon=tasty")
+
+if __name__ == "__main__":
+    unittest.main()
-- 
1.8.3.1

