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 *
21 from pykickstart
.constants
import *
22 from pykickstart
.errors
import *
23 from pykickstart
.options
import *
28 _
= lambda x
: gettext
.ldgettext("pykickstart", x
)
30 class FC6_RepoData(BaseData
):
31 removedKeywords
= BaseData
.removedKeywords
32 removedAttrs
= BaseData
.removedAttrs
34 def __init__(self
, *args
, **kwargs
):
35 BaseData
.__init
__(self
, *args
, **kwargs
)
36 self
.baseurl
= kwargs
.get("baseurl", "")
37 self
.mirrorlist
= kwargs
.get("mirrorlist", None)
38 self
.name
= kwargs
.get("name", "")
41 return self
.name
== y
.name
43 def _getArgsAsStr(self
):
47 retval
+= "--baseurl=%s" % self
.baseurl
49 retval
+= "--mirrorlist=%s" % self
.mirrorlist
54 retval
= BaseData
.__str
__(self
)
55 retval
+= "repo --name=%s %s\n" % (self
.name
, self
._getArgsAsStr
())
58 class F8_RepoData(FC6_RepoData
):
59 removedKeywords
= FC6_RepoData
.removedKeywords
60 removedAttrs
= FC6_RepoData
.removedAttrs
62 def __init__(self
, *args
, **kwargs
):
63 FC6_RepoData
.__init
__(self
, *args
, **kwargs
)
64 self
.cost
= kwargs
.get("cost", None)
65 self
.includepkgs
= kwargs
.get("includepkgs", [])
66 self
.excludepkgs
= kwargs
.get("excludepkgs", [])
68 def _getArgsAsStr(self
):
69 retval
= FC6_RepoData
._getArgsAsStr
(self
)
72 retval
+= " --cost=%s" % self
.cost
74 retval
+= " --includepkgs=\"%s\"" % string
.join(self
.includepkgs
, ",")
76 retval
+= " --excludepkgs=\"%s\"" % string
.join(self
.excludepkgs
, ",")
80 class F11_RepoData(F8_RepoData
):
81 removedKeywords
= F8_RepoData
.removedKeywords
82 removedAttrs
= F8_RepoData
.removedAttrs
84 def __init__(self
, *args
, **kwargs
):
85 F8_RepoData
.__init
__(self
, *args
, **kwargs
)
86 self
.ignoregroups
= kwargs
.get("ignoregroups", None)
88 def _getArgsAsStr(self
):
89 retval
= F8_RepoData
._getArgsAsStr
(self
)
92 retval
+= " --ignoregroups=true"
95 class FC6_Repo(KickstartCommand
):
96 removedKeywords
= KickstartCommand
.removedKeywords
97 removedAttrs
= KickstartCommand
.removedAttrs
99 def __init__(self
, writePriority
=0, *args
, **kwargs
):
100 KickstartCommand
.__init
__(self
, writePriority
, *args
, **kwargs
)
101 self
.op
= self
._getParser
()
103 self
.repoList
= kwargs
.get("repoList", [])
107 for repo
in self
.repoList
:
108 retval
+= repo
.__str
__()
112 def _getParser(self
):
113 op
= KSOptionParser()
114 op
.add_option("--name", dest
="name", required
=1)
115 op
.add_option("--baseurl")
116 op
.add_option("--mirrorlist")
119 def parse(self
, args
):
120 (opts
, extra
) = self
.op
.parse_args(args
=args
, lineno
=self
.lineno
)
123 mapping
= {"command": "repo", "options": extra
}
124 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Unexpected arguments to %(command)s command: %(options)s") % mapping
)
126 # This is lame, but I can't think of a better way to make sure only
127 # one of these two is specified.
128 if opts
.baseurl
and opts
.mirrorlist
:
129 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Only one of --baseurl and --mirrorlist may be specified for repo command."))
131 if not opts
.baseurl
and not opts
.mirrorlist
:
132 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("One of --baseurl or --mirrorlist must be specified for repo command."))
134 rd
= self
.handler
.RepoData()
135 self
._setToObj
(self
.op
, opts
, rd
)
137 # Check for duplicates in the data list.
138 if rd
in self
.dataList():
139 raise KickstartValueError(_("A repo with the name %s has already been defined.") % rd
.name
)
146 class F8_Repo(FC6_Repo
):
147 removedKeywords
= FC6_Repo
.removedKeywords
148 removedAttrs
= FC6_Repo
.removedAttrs
152 for repo
in self
.repoList
:
153 retval
+= repo
.__str
__()
157 def _getParser(self
):
158 def list_cb (option
, opt_str
, value
, parser
):
159 for d
in value
.split(','):
160 parser
.values
.ensure_value(option
.dest
, []).append(d
)
162 op
= FC6_Repo
._getParser
(self
)
163 op
.add_option("--cost", action
="store", type="int")
164 op
.add_option("--excludepkgs", action
="callback", callback
=list_cb
,
165 nargs
=1, type="string")
166 op
.add_option("--includepkgs", action
="callback", callback
=list_cb
,
167 nargs
=1, type="string")
170 def methodToRepo(self
):
171 if not self
.handler
.method
.url
:
172 raise KickstartError
, formatErrorMsg(self
.handler
.method
.lineno
, msg
=_("Method must be a url to be added to the repo list."))
173 reponame
= "ks-method-url"
174 repourl
= self
.handler
.method
.url
175 rd
= self
.handler
.RepoData(name
=reponame
, baseurl
=repourl
)
178 class F11_Repo(F8_Repo
):
179 removedKeywords
= F8_Repo
.removedKeywords
180 removedAttrs
= F8_Repo
.removedAttrs
182 def _getParser(self
):
183 op
= F8_Repo
._getParser
(self
)
184 op
.add_option("--ignoregroups", action
="store", type="ksboolean")