Error out if the same partition/repo/network is defined twice (#512956).
[pykickstart.git] / pykickstart / commands / group.py
blob5aa813d199b69d9e096394458f3f891b8c5d6bdf
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2009 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 *
25 import gettext
26 _ = lambda x: gettext.ldgettext("pykickstart", x)
28 class F12_GroupData(BaseData):
29 removedKeywords = BaseData.removedKeywords
30 removedAttrs = BaseData.removedAttrs
32 def __init__(self, *args, **kwargs):
33 BaseData.__init__(self, *args, **kwargs)
34 self.name = kwargs.get("name", "")
35 self.gid = kwargs.get("gid", None)
37 def __eq__(self, y):
38 return self.name == y.name
40 def __str__(self):
41 retval = BaseData.__str__(self)
42 retval += "group"
44 if self.name:
45 retval += " --name=%s" % self.name
46 if self.gid:
47 retval += " --gid=%s" % self.gid
49 return retval + "\n"
51 class F12_Group(KickstartCommand):
52 removedKeywords = KickstartCommand.removedKeywords
53 removedAttrs = KickstartCommand.removedAttrs
55 def __init__(self, writePriority=0, *args, **kwargs):
56 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
57 self.op = self._getParser()
59 self.groupList = kwargs.get("groupList", [])
61 def __str__(self):
62 retval = ""
63 for user in self.groupList:
64 retval += user.__str__()
66 return retval
68 def _getParser(self):
69 op = KSOptionParser()
70 op.add_option("--name", required=1)
71 op.add_option("--gid", type="int")
72 return op
74 def parse(self, args):
75 gd = self.handler.GroupData()
76 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
77 self._setToObj(self.op, opts, gd)
79 # Check for duplicates in the data list.
80 if gd in self.dataList():
81 raise KickstartValueError(_("A group with the name %s has already been defined.") % gd.name)
83 return gd
85 def dataList(self):
86 return self.groupList