Add new RHEL7 logvol objects to master
[pykickstart.git] / pykickstart / commands / repo.py
blob3ee114c5fe597b826a2ec94fab4e3dc181a8ab25
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2007, 2008, 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 BaseData, KickstartCommand
21 from pykickstart.errors import KickstartError, KickstartValueError, formatErrorMsg
22 from pykickstart.options import KSOptionParser
24 import gettext
25 import warnings
26 _ = lambda x: gettext.ldgettext("pykickstart", x)
28 class FC6_RepoData(BaseData):
29 removedKeywords = BaseData.removedKeywords
30 removedAttrs = BaseData.removedAttrs
32 def __init__(self, *args, **kwargs):
33 BaseData.__init__(self, *args, **kwargs)
34 self.baseurl = kwargs.get("baseurl", "")
35 self.mirrorlist = kwargs.get("mirrorlist", None)
36 self.name = kwargs.get("name", "")
38 def __eq__(self, y):
39 if not y:
40 return False
42 return self.name == y.name
44 def __ne__(self, y):
45 return not self == y
47 def _getArgsAsStr(self):
48 retval = ""
50 if self.baseurl:
51 retval += "--baseurl=%s" % self.baseurl
52 elif self.mirrorlist:
53 retval += "--mirrorlist=%s" % self.mirrorlist
55 return retval
57 def __str__(self):
58 retval = BaseData.__str__(self)
59 retval += "repo --name=\"%s\" %s\n" % (self.name, self._getArgsAsStr())
60 return retval
62 class F8_RepoData(FC6_RepoData):
63 removedKeywords = FC6_RepoData.removedKeywords
64 removedAttrs = FC6_RepoData.removedAttrs
66 def __init__(self, *args, **kwargs):
67 FC6_RepoData.__init__(self, *args, **kwargs)
68 self.cost = kwargs.get("cost", None)
69 self.includepkgs = kwargs.get("includepkgs", [])
70 self.excludepkgs = kwargs.get("excludepkgs", [])
72 def _getArgsAsStr(self):
73 retval = FC6_RepoData._getArgsAsStr(self)
75 if self.cost:
76 retval += " --cost=%s" % self.cost
77 if self.includepkgs:
78 retval += " --includepkgs=\"%s\"" % ",".join(self.includepkgs)
79 if self.excludepkgs:
80 retval += " --excludepkgs=\"%s\"" % ",".join(self.excludepkgs)
82 return retval
84 class F11_RepoData(F8_RepoData):
85 removedKeywords = F8_RepoData.removedKeywords
86 removedAttrs = F8_RepoData.removedAttrs
88 def __init__(self, *args, **kwargs):
89 F8_RepoData.__init__(self, *args, **kwargs)
90 self.ignoregroups = kwargs.get("ignoregroups", None)
92 def _getArgsAsStr(self):
93 retval = F8_RepoData._getArgsAsStr(self)
95 if self.ignoregroups:
96 retval += " --ignoregroups=true"
97 return retval
99 class F13_RepoData(F11_RepoData):
100 removedKeywords = F11_RepoData.removedKeywords
101 removedAttrs = F11_RepoData.removedAttrs
103 def __init__(self, *args, **kwargs):
104 F11_RepoData.__init__(self, *args, **kwargs)
105 self.proxy = kwargs.get("proxy", "")
107 def _getArgsAsStr(self):
108 retval = F11_RepoData._getArgsAsStr(self)
110 if self.proxy:
111 retval += " --proxy=\"%s\"" % self.proxy
113 return retval
115 class F14_RepoData(F13_RepoData):
116 removedKeywords = F13_RepoData.removedKeywords
117 removedAttrs = F13_RepoData.removedAttrs
119 def __init__(self, *args, **kwargs):
120 F13_RepoData.__init__(self, *args, **kwargs)
121 self.noverifyssl = kwargs.get("noverifyssl", False)
123 def _getArgsAsStr(self):
124 retval = F13_RepoData._getArgsAsStr(self)
126 if self.noverifyssl:
127 retval += " --noverifyssl"
129 return retval
131 RHEL6_RepoData = F14_RepoData
133 F15_RepoData = F14_RepoData
135 class F21_RepoData(F14_RepoData):
136 removedKeywords = F14_RepoData.removedKeywords
137 removedAttrs = F14_RepoData.removedAttrs
139 def __init__(self, *args, **kwargs):
140 F14_RepoData.__init__(self, *args, **kwargs)
141 self.install = kwargs.get("install", False)
143 def _getArgsAsStr(self):
144 retval = F14_RepoData._getArgsAsStr(self)
146 if self.install:
147 retval += " --install"
149 return retval
151 RHEL7_RepoData = F21_RepoData
153 class FC6_Repo(KickstartCommand):
154 removedKeywords = KickstartCommand.removedKeywords
155 removedAttrs = KickstartCommand.removedAttrs
157 urlRequired = True
159 def __init__(self, writePriority=0, *args, **kwargs):
160 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
161 self.op = self._getParser()
163 self.repoList = kwargs.get("repoList", [])
165 def __str__(self):
166 retval = ""
167 for repo in self.repoList:
168 retval += repo.__str__()
170 return retval
172 def _getParser(self):
173 op = KSOptionParser()
174 op.add_option("--name", dest="name", required=1)
175 op.add_option("--baseurl")
176 op.add_option("--mirrorlist")
177 return op
179 def parse(self, args):
180 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
182 if len(extra) != 0:
183 mapping = {"command": "repo", "options": extra}
184 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %(command)s command: %(options)s") % mapping))
186 # This is lame, but I can't think of a better way to make sure only
187 # one of these two is specified.
188 if opts.baseurl and opts.mirrorlist:
189 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of --baseurl and --mirrorlist may be specified for repo command.")))
191 if self.urlRequired and not opts.baseurl and not opts.mirrorlist:
192 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of --baseurl or --mirrorlist must be specified for repo command.")))
194 rd = self.handler.RepoData()
195 self._setToObj(self.op, opts, rd)
196 rd.lineno = self.lineno
198 # Check for duplicates in the data list.
199 if rd in self.dataList():
200 warnings.warn(_("A repo with the name %s has already been defined.") % rd.name)
202 return rd
204 def dataList(self):
205 return self.repoList
207 class F8_Repo(FC6_Repo):
208 removedKeywords = FC6_Repo.removedKeywords
209 removedAttrs = FC6_Repo.removedAttrs
211 def __str__(self):
212 retval = ""
213 for repo in self.repoList:
214 retval += repo.__str__()
216 return retval
218 def _getParser(self):
219 def list_cb (option, opt_str, value, parser):
220 for d in value.split(','):
221 parser.values.ensure_value(option.dest, []).append(d)
223 op = FC6_Repo._getParser(self)
224 op.add_option("--cost", action="store", type="int")
225 op.add_option("--excludepkgs", action="callback", callback=list_cb,
226 nargs=1, type="string")
227 op.add_option("--includepkgs", action="callback", callback=list_cb,
228 nargs=1, type="string")
229 return op
231 def methodToRepo(self):
232 if not self.handler.method.url:
233 raise KickstartError(formatErrorMsg(self.handler.method.lineno, msg=_("Method must be a url to be added to the repo list.")))
234 reponame = "ks-method-url"
235 repourl = self.handler.method.url
236 rd = self.handler.RepoData(name=reponame, baseurl=repourl)
237 return rd
239 class F11_Repo(F8_Repo):
240 removedKeywords = F8_Repo.removedKeywords
241 removedAttrs = F8_Repo.removedAttrs
243 def _getParser(self):
244 op = F8_Repo._getParser(self)
245 op.add_option("--ignoregroups", action="store", type="ksboolean")
246 return op
248 class F13_Repo(F11_Repo):
249 removedKeywords = F11_Repo.removedKeywords
250 removedAttrs = F11_Repo.removedAttrs
252 def _getParser(self):
253 op = F11_Repo._getParser(self)
254 op.add_option("--proxy")
255 return op
257 class F14_Repo(F13_Repo):
258 removedKeywords = F13_Repo.removedKeywords
259 removedAttrs = F13_Repo.removedAttrs
261 def _getParser(self):
262 op = F13_Repo._getParser(self)
263 op.add_option("--noverifyssl", action="store_true", default=False)
264 return op
266 RHEL6_Repo = F14_Repo
268 class F15_Repo(F14_Repo):
269 removedKeywords = F14_Repo.removedKeywords
270 removedAttrs = F14_Repo.removedAttrs
272 urlRequired = False
274 class F21_Repo(F15_Repo):
275 removedKeywords = F15_Repo.removedKeywords
276 removedAttrs = F15_Repo.removedAttrs
278 def _getParser(self):
279 op = F15_Repo._getParser(self)
280 op.add_option("--install", action="store_true", default=False)
281 return op
283 RHEL7_Repo = F21_Repo