Rename command objects by inserting an underscore between the version part
[pykickstart.git] / pykickstart / commands / user.py
blobc83e386228df1133fdaeb8903fc4f8e33acdb92d
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 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 import string
15 from pykickstart.base import *
16 from pykickstart.constants import *
17 from pykickstart.errors import *
18 from pykickstart.options import *
20 from rhpl.translate import _
21 import rhpl.translate as translate
23 translate.textdomain("pykickstart")
25 class FC6_UserData(BaseData):
26 def __init__(self, groups=None, homedir="", isCrypted=False, name="",
27 password="", shell="", uid=None):
28 BaseData.__init__(self)
30 if groups == None:
31 groups = []
33 self.groups = groups
34 self.homedir = homedir
35 self.isCrypted = isCrypted
36 self.name = name
37 self.password = password
38 self.shell = shell
39 self.uid = uid
41 def __str__(self):
42 retval = "user"
44 if len(self.groups) > 0:
45 retval += " --groups=%s" % string.join(self.groups, ",")
46 if self.homedir:
47 retval += " --homedir=%s" % self.homedir
48 if self.name:
49 retval += " --name=%s" % self.name
50 if self.password:
51 retval += " --password=%s" % self.password
52 if self.isCrypted:
53 retval += " --isCrypted"
54 if self.shell:
55 retval += " --shell=%s" % self.shell
56 if self.uid:
57 retval += " --uid=%s" % self.uid
59 return retval + "\n"
61 class FC6_User(KickstartCommand):
62 def __init__(self, writePriority=0, userList=None):
63 KickstartCommand.__init__(self, writePriority)
65 if userList == None:
66 userList = []
68 self.userList = userList
70 def __str__(self):
71 retval = ""
72 for user in self.userList:
73 retval += user.__str__()
75 return retval
77 def parse(self, args):
78 def groups_cb (option, opt_str, value, parser):
79 for d in value.split(','):
80 parser.values.ensure_value(option.dest, []).append(d)
82 op = KSOptionParser(lineno=self.lineno)
83 op.add_option("--groups", dest="groups", action="callback",
84 callback=groups_cb, nargs=1, type="string")
85 op.add_option("--homedir")
86 op.add_option("--iscrypted", dest="isCrypted", action="store_true",
87 default=False)
88 op.add_option("--name", required=1)
89 op.add_option("--password")
90 op.add_option("--shell")
91 op.add_option("--uid", type="int")
93 ud = FC6_UserData()
94 (opts, extra) = op.parse_args(args=args)
95 self._setToObj(op, opts, ud)
96 self.add(ud)
98 def add(self, newObj):
99 self.userList.append(newObj)