Add support for the --lock and --plaintext options for rootpw and user
[pykickstart.git] / pykickstart / commands / rootpw.py
blob09fdefc99ae2d71fccae2b9a26ae73f46bd61cfc
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007 Red Hat, Inc.
6 # This software may be freely redistributed under the terms of the GNU
7 # general public license.
9 # You should have received a copy of the GNU General Public License
10 # along with this program; if not, write to the Free Software
11 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13 from pykickstart.base import *
14 from pykickstart.errors import *
15 from pykickstart.options import *
17 from rhpl.translate import _
18 import rhpl.translate as translate
20 translate.textdomain("pykickstart")
22 class FC3_RootPw(KickstartCommand):
23 def __init__(self, writePriority=0, isCrypted=False, password=""):
24 KickstartCommand.__init__(self, writePriority)
25 self.isCrypted = isCrypted
26 self.password = password
28 def __str__(self):
29 if self.password != "":
30 if self.isCrypted:
31 crypted = "--iscrypted"
32 else:
33 crypted = ""
35 return "# Root password\nrootpw %s %s\n" % (crypted, self.password)
36 else:
37 return ""
39 def parse(self, args):
40 op = KSOptionParser(lineno=self.lineno)
41 op.add_option("--iscrypted", dest="isCrypted", action="store_true",
42 default=False)
44 (opts, extra) = op.parse_args(args=args)
45 self._setToSelf(op, opts)
47 if len(extra) != 1:
48 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("A single argument is expected for the %s command") % "rootpw")
50 self.password = extra[0]
52 class F8_RootPw(FC3_RootPw):
53 def __init__(self, writePriority=0, isCrypted=False, password="",
54 lock=False):
55 FC3_RootPw.__init__(self, writePriority, isCrypted, password)
56 self.lock = lock
58 def __str__(self):
59 retval = FC3_RootPw.__str__(self)
61 if retval != "" and self.lock:
62 return retval.strip() + " --lock\n"
63 else:
64 return retval
66 def parse(self, args):
67 op = KSOptionParser(lineno=self.lineno)
68 op.add_option("--iscrypted", dest="isCrypted", action="store_true",
69 default=False)
70 op.add_option("--lock", dest="lock", action="store_true", default=False)
71 op.add_option("--plaintext", dest="isCrypted", action="store_false")
73 (opts, extra) = op.parse_args(args=args)
74 self._setToSelf(op, opts)
76 if len(extra) != 1:
77 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("A single argument is expected for the %s command") % "rootpw")
79 self.password = extra[0]