-
Notifications
You must be signed in to change notification settings - Fork 117
/
url.py
224 lines (168 loc) · 7.11 KB
/
url.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#
# Chris Lumens <clumens@redhat.com>
#
# Copyright 2007, 2009, 2013 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use, modify,
# copy, or redistribute it subject to the terms and conditions of the GNU
# General Public License v.2. This program is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
# trademarks that are incorporated in the source code or documentation are not
# subject to the GNU General Public License and may only be used or replicated
# with the express permission of Red Hat, Inc.
#
from pykickstart.base import KickstartCommand
from pykickstart.errors import KickstartValueError, formatErrorMsg
from pykickstart.options import KSOptionParser
from pykickstart.i18n import _
class FC3_Url(KickstartCommand):
removedKeywords = KickstartCommand.removedKeywords
removedAttrs = KickstartCommand.removedAttrs
def __init__(self, writePriority=0, *args, **kwargs):
KickstartCommand.__init__(self, writePriority, *args, **kwargs)
self.url = kwargs.get("url", None)
self.op = self._getParser()
def __eq__(self, other):
if not other:
return False
return self.url == other.url
def __ne__(self, other):
return not self == other
def __str__(self):
retval = KickstartCommand.__str__(self)
if self.seen:
retval += "# Use network installation\nurl --url=\"%s\"\n" % self.url
return retval
def _getParser(self):
op = KSOptionParser()
op.add_option("--url", dest="url", required=1)
return op
def parse(self, args):
(opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno)
self.set_to_self(self.op, opts)
return self
class F13_Url(FC3_Url):
removedKeywords = FC3_Url.removedKeywords
removedAttrs = FC3_Url.removedAttrs
def __init__(self, *args, **kwargs):
FC3_Url.__init__(self, *args, **kwargs)
self.proxy = kwargs.get("proxy", "")
def __eq__(self, other):
if not FC3_Url.__eq__(self, other):
return False
return self.proxy == other.proxy
def __str__(self):
retval = FC3_Url.__str__(self)
if self.seen and self.proxy:
retval = retval.strip()
retval += " --proxy=\"%s\"\n" % self.proxy
return retval
def _getParser(self):
op = FC3_Url._getParser(self)
op.add_option("--proxy")
return op
class F14_Url(F13_Url):
removedKeywords = F13_Url.removedKeywords
removedAttrs = F13_Url.removedAttrs
def __init__(self, *args, **kwargs):
F13_Url.__init__(self, *args, **kwargs)
self.noverifyssl = kwargs.get("noverifyssl", False)
def __eq__(self, other):
if not F13_Url.__eq__(self, other):
return False
return self.noverifyssl == other.noverifyssl
def __str__(self):
retval = F13_Url.__str__(self)
if self.seen and self.noverifyssl:
retval = retval.strip()
retval += " --noverifyssl\n"
return retval
def _getParser(self):
op = F13_Url._getParser(self)
op.add_option("--noverifyssl", action="store_true", default=False)
return op
RHEL6_Url = F14_Url
class F18_Url(F14_Url):
removedKeywords = F14_Url.removedKeywords
removedAttrs = F14_Url.removedAttrs
def __init__(self, *args, **kwargs):
F14_Url.__init__(self, *args, **kwargs)
self.mirrorlist = kwargs.get("mirrorlist", None)
self.exclusive_required_options = [("mirrorlist", "--mirrorlist"),
("url", "--url")]
def __eq__(self, other):
if not F14_Url.__eq__(self, other):
return False
return self.mirrorlist == other.mirrorlist
def __str__(self):
retval = KickstartCommand.__str__(self)
if not self.seen:
return retval
retval += "# Use network installation\n"
if self.url:
retval += "url --url=\"%s\"" % self.url
elif self.mirrorlist:
retval += "url --mirrorlist=\"%s\"" % self.mirrorlist
if self.proxy:
retval += " --proxy=\"%s\"" % self.proxy
if self.noverifyssl:
retval += " --noverifyssl"
return retval + "\n"
def _getParser(self):
op = F14_Url._getParser(self)
# This overrides the option set in the superclass's _getParser
# method. --url is no longer required because you could do
# --mirrorlist instead.
op.add_option("--url", dest="url")
op.add_option("--mirrorlist", dest="mirrorlist")
return op
def parse(self, args):
retval = F14_Url.parse(self, args)
(opts, _extra) = self.op.parse_args(args=args, lineno=self.lineno)
# Check that just one of exclusive required options is specified
used_options = [opt for attr, opt in self.exclusive_required_options
if getattr(opts, attr, None)]
if len(used_options) == 0:
mapping = {"options_list": ", ".join((opt for attr, opt in self.exclusive_required_options))}
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of -%(options_list)s options must be specified for url command.") % mapping))
if len(used_options) > 1:
mapping = {"options_list": ", ".join((opt for opt in used_options))}
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of %(options_list)s options may be specified for url command.") % mapping))
return retval
class F27_Url(F18_Url):
removedKeywords = F18_Url.removedKeywords
removedAttrs = F18_Url.removedAttrs
def __init__(self, *args, **kwargs):
F18_Url.__init__(self, *args, **kwargs)
self.metalink = kwargs.get("metalink", None)
self.exclusive_required_options.append(("metalink", "--metalink"))
def __eq__(self, other):
if not F18_Url.__eq__(self, other):
return False
return self.metalink == other.metalink
def __str__(self):
retval = KickstartCommand.__str__(self)
if not self.seen:
return retval
retval += "# Use network installation\n"
if self.url:
retval += "url --url=\"%s\"" % self.url
elif self.mirrorlist:
retval += "url --mirrorlist=\"%s\"" % self.mirrorlist
elif self.metalink:
retval += "url --metalink=\"%s\"" % self.metalink
if self.proxy:
retval += " --proxy=\"%s\"" % self.proxy
if self.noverifyssl:
retval += " --noverifyssl"
return retval + "\n"
def _getParser(self):
op = F18_Url._getParser(self)
op.add_option("--metalink", dest="metalink")
return op