2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2007 Red Hat, Inc.
6 # This copyrighted material is made available to anyone wishing to use, modify,
7 # copy, or redistribute it subject to the terms and conditions of the GNU
8 # General Public License v.2. This program is distributed in the hope that it
9 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
10 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # this program; if not, write to the Free Software Foundation, Inc., 51
15 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
16 # trademarks that are incorporated in the source code or documentation are not
17 # subject to the GNU General Public License and may only be used or replicated
18 # with the express permission of Red Hat, Inc.
20 from pykickstart.base import *
21 from pykickstart.constants import *
22 from pykickstart.errors import *
23 from pykickstart.options import *
27 _ = lambda x: gettext.ldgettext("pykickstart", x)
29 class FC6_UserData(BaseData):
30 removedKeywords = BaseData.removedKeywords
31 removedAttrs = BaseData.removedAttrs
33 def __init__(self, *args, **kwargs):
34 BaseData.__init__(self, *args, **kwargs)
35 self.groups = kwargs.get("groups", [])
36 self.homedir = kwargs.get("homedir", "")
37 self.isCrypted = kwargs.get("isCrypted", False)
38 self.name = kwargs.get("name", "")
39 self.password = kwargs.get("password", "")
40 self.shell = kwargs.get("shell", "")
41 self.uid = kwargs.get("uid", None)
44 return self.name == y.name
47 retval = BaseData.__str__(self)
51 retval += self._getArgsAsStr() + "\n"
55 def _getArgsAsStr(self):
58 if len(self.groups) > 0:
59 retval += " --groups=%s" % ",".join(self.groups)
61 retval += " --homedir=%s" % self.homedir
63 retval += " --name=%s" % self.name
65 retval += " --password=%s" % self.password
67 retval += " --iscrypted"
69 retval += " --shell=%s" % self.shell
71 retval += " --uid=%s" % self.uid
75 class F8_UserData(FC6_UserData):
76 removedKeywords = FC6_UserData.removedKeywords
77 removedAttrs = FC6_UserData.removedAttrs
79 def __init__(self, *args, **kwargs):
80 FC6_UserData.__init__(self, *args, **kwargs)
81 self.lock = kwargs.get("lock", False)
83 def _getArgsAsStr(self):
84 retval = FC6_UserData._getArgsAsStr(self)
91 class F12_UserData(F8_UserData):
92 removedKeywords = F8_UserData.removedKeywords
93 removedAttrs = F8_UserData.removedAttrs
95 def __init__(self, *args, **kwargs):
96 F8_UserData.__init__(self, *args, **kwargs)
97 self.gecos = kwargs.get("gecos", "")
99 def _getArgsAsStr(self):
100 retval = F8_UserData._getArgsAsStr(self)
103 retval += " --gecos=\"%s\"" % (self.gecos,)
107 class FC6_User(KickstartCommand):
108 removedKeywords = KickstartCommand.removedKeywords
109 removedAttrs = KickstartCommand.removedAttrs
111 def __init__(self, writePriority=0, *args, **kwargs):
112 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
113 self.op = self._getParser()
115 self.userList = kwargs.get("userList", [])
119 for user in self.userList:
120 retval += user.__str__()
124 def _getParser(self):
125 def groups_cb (option, opt_str, value, parser):
126 for d in value.split(','):
127 parser.values.ensure_value(option.dest, []).append(d)
129 op = KSOptionParser()
130 op.add_option("--groups", dest="groups", action="callback",
131 callback=groups_cb, nargs=1, type="string")
132 op.add_option("--homedir")
133 op.add_option("--iscrypted", dest="isCrypted", action="store_true",
135 op.add_option("--name", required=1)
136 op.add_option("--password")
137 op.add_option("--shell")
138 op.add_option("--uid", type="int")
141 def parse(self, args):
142 ud = self.handler.UserData()
143 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
144 self._setToObj(self.op, opts, ud)
145 ud.lineno = self.lineno
147 # Check for duplicates in the data list.
148 if ud in self.dataList():
149 warnings.warn(_("A user with the name %s has already been defined.") % ud.name)
156 class F8_User(FC6_User):
157 removedKeywords = FC6_User.removedKeywords
158 removedAttrs = FC6_User.removedAttrs
160 def _getParser(self):
161 op = FC6_User._getParser(self)
162 op.add_option("--lock", action="store_true", default=False)
163 op.add_option("--plaintext", dest="isCrypted", action="store_false")
166 class F12_User(F8_User):
167 removedKeywords = F8_User.removedKeywords
168 removedAttrs = F8_User.removedAttrs
170 def _getParser(self):
171 op = F8_User._getParser(self)
172 op.add_option("--gecos", type="string")