Rename command objects by inserting an underscore between the version part
[pykickstart.git] / pykickstart / commands / repo.py
blob966759423204343c8595d711f06834c27469e3ce
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 from pykickstart.base import *
14 from pykickstart.constants import *
15 from pykickstart.errors import *
16 from pykickstart.options import *
18 from rhpl.translate import _
19 import rhpl.translate as translate
21 translate.textdomain("pykickstart")
23 class FC6_RepoData(BaseData):
24 def __init__(self, baseurl="", mirrorlist="", name=""):
25 BaseData.__init__(self)
26 self.baseurl = baseurl
27 self.mirrorlist = mirrorlist
28 self.name = name
30 def __str__(self):
31 if self.baseurl:
32 urlopt = "--baseurl=%s" % self.baseurl
33 elif self.mirrorlist:
34 urlopt = "--mirrorlist=%s" % self.mirrorlist
36 return "repo --name=%s %s\n" % (self.name, urlopt)
38 class FC6_Repo(KickstartCommand):
39 def __init__(self, writePriority=0, repoList=None):
40 KickstartCommand.__init__(self, writePriority)
42 if repoList == None:
43 repoList = []
45 self.repoList = repoList
47 def __str__(self):
48 retval = ""
49 for repo in self.repoList:
50 retval += repo.__str__()
52 return retval
54 def parse(self, args):
55 op = KSOptionParser(lineno=self.lineno)
56 op.add_option("--name", dest="name", required=1)
57 op.add_option("--baseurl")
58 op.add_option("--mirrorlist")
60 (opts, extra) = op.parse_args(args=args)
62 # This is lame, but I can't think of a better way to make sure only
63 # one of these two is specified.
64 if opts.baseurl and opts.mirrorlist:
65 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Only one of --baseurl and --mirrorlist may be specified for repo command."))
67 if not opts.baseurl and not opts.mirrorlist:
68 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("One of --baseurl or --mirrorlist must be specified for repo command."))
70 rd = FC6_RepoData()
71 self._setToObj(op, opts, rd)
72 self.add(rd)
74 def add(self, newObj):
75 self.repoList.append(newObj)