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 BaseData
, KickstartCommand
21 from pykickstart
.options
import KSOptionParser
25 _
= lambda x
: gettext
.ldgettext("pykickstart", x
)
27 class FC6_UserData(BaseData
):
28 removedKeywords
= BaseData
.removedKeywords
29 removedAttrs
= BaseData
.removedAttrs
31 def __init__(self
, *args
, **kwargs
):
32 BaseData
.__init
__(self
, *args
, **kwargs
)
33 self
.groups
= kwargs
.get("groups", [])
34 self
.homedir
= kwargs
.get("homedir", "")
35 self
.isCrypted
= kwargs
.get("isCrypted", False)
36 self
.name
= kwargs
.get("name", "")
37 self
.password
= kwargs
.get("password", "")
38 self
.shell
= kwargs
.get("shell", "")
39 self
.uid
= kwargs
.get("uid", None)
45 return self
.name
== y
.name
51 retval
= BaseData
.__str
__(self
)
55 retval
+= self
._getArgsAsStr
() + "\n"
59 def _getArgsAsStr(self
):
62 if len(self
.groups
) > 0:
63 retval
+= " --groups=%s" % ",".join(self
.groups
)
65 retval
+= " --homedir=%s" % self
.homedir
67 retval
+= " --name=%s" % self
.name
69 retval
+= " --password=%s" % self
.password
71 retval
+= " --iscrypted"
73 retval
+= " --shell=%s" % self
.shell
75 retval
+= " --uid=%s" % self
.uid
79 class F8_UserData(FC6_UserData
):
80 removedKeywords
= FC6_UserData
.removedKeywords
81 removedAttrs
= FC6_UserData
.removedAttrs
83 def __init__(self
, *args
, **kwargs
):
84 FC6_UserData
.__init
__(self
, *args
, **kwargs
)
85 self
.lock
= kwargs
.get("lock", False)
87 def _getArgsAsStr(self
):
88 retval
= FC6_UserData
._getArgsAsStr
(self
)
95 class F12_UserData(F8_UserData
):
96 removedKeywords
= F8_UserData
.removedKeywords
97 removedAttrs
= F8_UserData
.removedAttrs
99 def __init__(self
, *args
, **kwargs
):
100 F8_UserData
.__init
__(self
, *args
, **kwargs
)
101 self
.gecos
= kwargs
.get("gecos", "")
103 def _getArgsAsStr(self
):
104 retval
= F8_UserData
._getArgsAsStr
(self
)
107 retval
+= " --gecos=\"%s\"" % (self
.gecos
,)
111 class F19_UserData(F12_UserData
):
112 removedKeywords
= F12_UserData
.removedKeywords
113 removedAttrs
= F12_UserData
.removedAttrs
115 def __init__(self
, *args
, **kwargs
):
116 F12_UserData
.__init
__(self
, *args
, **kwargs
)
117 self
.gid
= kwargs
.get("gid", None)
119 def _getArgsAsStr(self
):
120 retval
= F12_UserData
._getArgsAsStr
(self
)
123 retval
+= " --gid=%d" % (self
.gid
,)
128 class FC6_User(KickstartCommand
):
129 removedKeywords
= KickstartCommand
.removedKeywords
130 removedAttrs
= KickstartCommand
.removedAttrs
132 def __init__(self
, writePriority
=0, *args
, **kwargs
):
133 KickstartCommand
.__init
__(self
, writePriority
, *args
, **kwargs
)
134 self
.op
= self
._getParser
()
136 self
.userList
= kwargs
.get("userList", [])
140 for user
in self
.userList
:
141 retval
+= user
.__str
__()
145 def _getParser(self
):
146 def groups_cb (option
, opt_str
, value
, parser
):
147 for d
in value
.split(','):
148 parser
.values
.ensure_value(option
.dest
, []).append(d
)
150 op
= KSOptionParser()
151 op
.add_option("--groups", dest
="groups", action
="callback",
152 callback
=groups_cb
, nargs
=1, type="string")
153 op
.add_option("--homedir")
154 op
.add_option("--iscrypted", dest
="isCrypted", action
="store_true",
156 op
.add_option("--name", required
=1)
157 op
.add_option("--password")
158 op
.add_option("--shell")
159 op
.add_option("--uid", type="int")
162 def parse(self
, args
):
163 ud
= self
.handler
.UserData()
164 (opts
, _extra
) = self
.op
.parse_args(args
=args
, lineno
=self
.lineno
)
165 self
._setToObj
(self
.op
, opts
, ud
)
166 ud
.lineno
= self
.lineno
168 # Check for duplicates in the data list.
169 if ud
in self
.dataList():
170 warnings
.warn(_("A user with the name %s has already been defined.") % ud
.name
)
177 class F8_User(FC6_User
):
178 removedKeywords
= FC6_User
.removedKeywords
179 removedAttrs
= FC6_User
.removedAttrs
181 def _getParser(self
):
182 op
= FC6_User
._getParser
(self
)
183 op
.add_option("--lock", action
="store_true", default
=False)
184 op
.add_option("--plaintext", dest
="isCrypted", action
="store_false")
187 class F12_User(F8_User
):
188 removedKeywords
= F8_User
.removedKeywords
189 removedAttrs
= F8_User
.removedAttrs
191 def _getParser(self
):
192 op
= F8_User
._getParser
(self
)
193 op
.add_option("--gecos", type="string")
196 class F19_User(F12_User
):
197 removedKeywords
= F12_User
.removedKeywords
198 removedAttrs
= F12_User
.removedAttrs
200 def _getParser(self
):
201 op
= F12_User
._getParser
(self
)
202 op
.add_option("--gid", type="int")