We need to store data about EULA agreement during the installation and first boot and we should allow users to accept the license agreement in kickstart.
Related: rhbz#1000409
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com --- pykickstart/commands/__init__.py | 2 +- pykickstart/commands/eula.py | 72 ++++++++++++++++++++++++++++++++++++++++ pykickstart/handlers/control.py | 2 ++ tests/commands/eula.py | 42 +++++++++++++++++++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 pykickstart/commands/eula.py create mode 100644 tests/commands/eula.py
diff --git a/pykickstart/commands/__init__.py b/pykickstart/commands/__init__.py index 43bbe0c..c5145ba 100644 --- a/pykickstart/commands/__init__.py +++ b/pykickstart/commands/__init__.py @@ -18,7 +18,7 @@ # with the express permission of Red Hat, Inc. # import authconfig, autopart, autostep, bootloader, btrfs, clearpart, cdrom, device -import deviceprobe, displaymode, dmraid, driverdisk, fcoe, firewall, firstboot +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 diff --git a/pykickstart/commands/eula.py b/pykickstart/commands/eula.py new file mode 100644 index 0000000..9283c6b --- /dev/null +++ b/pykickstart/commands/eula.py @@ -0,0 +1,72 @@ +# +# Copyright (C) 2013 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. +# +# Red Hat Author(s): Vratislav Podzimek vpodzime@redhat.com +# + +from pykickstart.base import * +from pykickstart.errors import * +from pykickstart.options import * + +import gettext +_ = lambda x: gettext.ldgettext("pykickstart", x) + +class F20_Eula(KickstartCommand): + """The 'eula' kickstart command""" + + def __init__(self, *args, **kwargs): + KickstartCommand.__init__(self, *args, **kwargs) + self.op = self._getParser() + self.agreed = kwargs.get("agreed", False) + + def __str__(self): + retval = KickstartCommand.__str__(self) + + if self.agreed: + retval += "# License agreement\n" + retval += "eula %s\n" % self._getArgsAsStr() + + return retval + + def _getArgsAsStr(self): + if self.agreed: + return "--agreed" + else: + return "" + + def _getParser(self): + op = KSOptionParser() + # allow both 'agreed' and 'agree' to be used + op.add_option("--agreed", dest="agreed", action="store_true", default=False) + op.add_option("--agree", dest="agreed", action="store_true", default=False) + op.add_option("--accepted", dest="agreed", action="store_true", default=False) + op.add_option("--accept", dest="agreed", 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) + + if len(extra) != 0: + raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Kickstart command %s does not take any arguments") % "eula")) + + if not self.agreed: + raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Kickstart command eula expects the --agreed option"))) + + return self + diff --git a/pykickstart/handlers/control.py b/pykickstart/handlers/control.py index 29d0584..83dece0 100644 --- a/pykickstart/handlers/control.py +++ b/pykickstart/handlers/control.py @@ -1038,6 +1038,7 @@ commandMap = { "deviceprobe": deviceprobe.FC3_DeviceProbe, "dmraid": dmraid.FC6_DmRaid, "driverdisk": driverdisk.F14_DriverDisk, + "eula": eula.F20_Eula, "fcoe": fcoe.F13_Fcoe, "firewall": firewall.F14_Firewall, "firstboot": firstboot.FC3_Firstboot, @@ -1326,6 +1327,7 @@ commandMap = { "deviceprobe": deviceprobe.FC3_DeviceProbe, "dmraid": dmraid.FC6_DmRaid, "driverdisk": driverdisk.F14_DriverDisk, + "eula": eula.F20_Eula, "fcoe": fcoe.F13_Fcoe, "firewall": firewall.F14_Firewall, "firstboot": firstboot.FC3_Firstboot, diff --git a/tests/commands/eula.py b/tests/commands/eula.py new file mode 100644 index 0000000..a35d990 --- /dev/null +++ b/tests/commands/eula.py @@ -0,0 +1,42 @@ +# +# Copyright (C) 2013 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. +# +# Red Hat Author(s): Vratislav Podzimek vpodzime@redhat.com +# + +import unittest +from tests.baseclass import * + +from pykickstart.errors import * +from pykickstart.commands.eula import * + +class F20_TestCase(CommandTest): + command = "eula" + + def runTest(self): + # pass + self.assert_parse("eula --agreed", "eula --agreed\n") + self.assert_parse("eula --agree", "eula --agreed\n") + self.assert_parse("eula --accepted", "eula --agreed\n") + self.assert_parse("eula --accept", "eula --agreed\n") + + # fail + self.assert_parse_error("eula", KickstartValueError) + self.assert_parse_error("eula arg1", KickstartValueError) + +if __name__ == "__main__": + unittest.main()