Add new RHEL7 logvol objects to master
[pykickstart.git] / pykickstart / commands / user.py
blobf9a4275983d25344121db603fa1bb7b2b3d456b7
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
23 import gettext
24 import warnings
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)
41 def __eq__(self, y):
42 if not y:
43 return False
45 return self.name == y.name
47 def __ne__(self, y):
48 return not self == y
50 def __str__(self):
51 retval = BaseData.__str__(self)
53 if self.uid != "":
54 retval += "user"
55 retval += self._getArgsAsStr() + "\n"
57 return retval
59 def _getArgsAsStr(self):
60 retval = ""
62 if len(self.groups) > 0:
63 retval += " --groups=%s" % ",".join(self.groups)
64 if self.homedir:
65 retval += " --homedir=%s" % self.homedir
66 if self.name:
67 retval += " --name=%s" % self.name
68 if self.password:
69 retval += " --password=%s" % self.password
70 if self.isCrypted:
71 retval += " --iscrypted"
72 if self.shell:
73 retval += " --shell=%s" % self.shell
74 if self.uid:
75 retval += " --uid=%s" % self.uid
77 return retval
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)
90 if self.lock:
91 retval += " --lock"
93 return retval
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)
106 if self.gecos:
107 retval += " --gecos=\"%s\"" % (self.gecos,)
109 return retval
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)
122 if self.gid:
123 retval += " --gid=%d" % (self.gid,)
125 return retval
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", [])
138 def __str__(self):
139 retval = ""
140 for user in self.userList:
141 retval += user.__str__()
143 return retval
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",
155 default=False)
156 op.add_option("--name", required=1)
157 op.add_option("--password")
158 op.add_option("--shell")
159 op.add_option("--uid", type="int")
160 return op
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)
172 return ud
174 def dataList(self):
175 return self.userList
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")
185 return op
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")
194 return op
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")
203 return op