diff options
Diffstat (limited to 'scripts/lib/mic/3rdparty/pykickstart/commands/repo.py')
| -rw-r--r-- | scripts/lib/mic/3rdparty/pykickstart/commands/repo.py | 249 |
1 files changed, 249 insertions, 0 deletions
diff --git a/scripts/lib/mic/3rdparty/pykickstart/commands/repo.py b/scripts/lib/mic/3rdparty/pykickstart/commands/repo.py new file mode 100644 index 0000000000..543ef947c1 --- /dev/null +++ b/scripts/lib/mic/3rdparty/pykickstart/commands/repo.py | |||
| @@ -0,0 +1,249 @@ | |||
| 1 | # | ||
| 2 | # Chris Lumens <clumens@redhat.com> | ||
| 3 | # | ||
| 4 | # Copyright 2007, 2008, 2009 Red Hat, Inc. | ||
| 5 | # | ||
| 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. | ||
| 12 | # | ||
| 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. | ||
| 19 | # | ||
| 20 | from pykickstart.base import * | ||
| 21 | from pykickstart.constants import * | ||
| 22 | from pykickstart.errors import * | ||
| 23 | from pykickstart.options import * | ||
| 24 | |||
| 25 | import gettext | ||
| 26 | import warnings | ||
| 27 | _ = lambda x: gettext.ldgettext("pykickstart", x) | ||
| 28 | |||
| 29 | class FC6_RepoData(BaseData): | ||
| 30 | removedKeywords = BaseData.removedKeywords | ||
| 31 | removedAttrs = BaseData.removedAttrs | ||
| 32 | |||
| 33 | def __init__(self, *args, **kwargs): | ||
| 34 | BaseData.__init__(self, *args, **kwargs) | ||
| 35 | self.baseurl = kwargs.get("baseurl", "") | ||
| 36 | self.mirrorlist = kwargs.get("mirrorlist", None) | ||
| 37 | self.name = kwargs.get("name", "") | ||
| 38 | |||
| 39 | def __eq__(self, y): | ||
| 40 | return self.name == y.name | ||
| 41 | |||
| 42 | def _getArgsAsStr(self): | ||
| 43 | retval = "" | ||
| 44 | |||
| 45 | if self.baseurl: | ||
| 46 | retval += "--baseurl=%s" % self.baseurl | ||
| 47 | elif self.mirrorlist: | ||
| 48 | retval += "--mirrorlist=%s" % self.mirrorlist | ||
| 49 | |||
| 50 | return retval | ||
| 51 | |||
| 52 | def __str__(self): | ||
| 53 | retval = BaseData.__str__(self) | ||
| 54 | retval += "repo --name=\"%s\" %s\n" % (self.name, self._getArgsAsStr()) | ||
| 55 | return retval | ||
| 56 | |||
| 57 | class F8_RepoData(FC6_RepoData): | ||
| 58 | removedKeywords = FC6_RepoData.removedKeywords | ||
| 59 | removedAttrs = FC6_RepoData.removedAttrs | ||
| 60 | |||
| 61 | def __init__(self, *args, **kwargs): | ||
| 62 | FC6_RepoData.__init__(self, *args, **kwargs) | ||
| 63 | self.cost = kwargs.get("cost", None) | ||
| 64 | self.includepkgs = kwargs.get("includepkgs", []) | ||
| 65 | self.excludepkgs = kwargs.get("excludepkgs", []) | ||
| 66 | |||
| 67 | def _getArgsAsStr(self): | ||
| 68 | retval = FC6_RepoData._getArgsAsStr(self) | ||
| 69 | |||
| 70 | if self.cost: | ||
| 71 | retval += " --cost=%s" % self.cost | ||
| 72 | if self.includepkgs: | ||
| 73 | retval += " --includepkgs=\"%s\"" % ",".join(self.includepkgs) | ||
| 74 | if self.excludepkgs: | ||
| 75 | retval += " --excludepkgs=\"%s\"" % ",".join(self.excludepkgs) | ||
| 76 | |||
| 77 | return retval | ||
| 78 | |||
| 79 | class F11_RepoData(F8_RepoData): | ||
| 80 | removedKeywords = F8_RepoData.removedKeywords | ||
| 81 | removedAttrs = F8_RepoData.removedAttrs | ||
| 82 | |||
| 83 | def __init__(self, *args, **kwargs): | ||
| 84 | F8_RepoData.__init__(self, *args, **kwargs) | ||
| 85 | self.ignoregroups = kwargs.get("ignoregroups", None) | ||
| 86 | |||
| 87 | def _getArgsAsStr(self): | ||
| 88 | retval = F8_RepoData._getArgsAsStr(self) | ||
| 89 | |||
| 90 | if self.ignoregroups: | ||
| 91 | retval += " --ignoregroups=true" | ||
| 92 | return retval | ||
| 93 | |||
| 94 | class F13_RepoData(F11_RepoData): | ||
| 95 | removedKeywords = F11_RepoData.removedKeywords | ||
| 96 | removedAttrs = F11_RepoData.removedAttrs | ||
| 97 | |||
| 98 | def __init__(self, *args, **kwargs): | ||
| 99 | F11_RepoData.__init__(self, *args, **kwargs) | ||
| 100 | self.proxy = kwargs.get("proxy", "") | ||
| 101 | |||
| 102 | def _getArgsAsStr(self): | ||
| 103 | retval = F11_RepoData._getArgsAsStr(self) | ||
| 104 | |||
| 105 | if self.proxy: | ||
| 106 | retval += " --proxy=\"%s\"" % self.proxy | ||
| 107 | |||
| 108 | return retval | ||
| 109 | |||
| 110 | class F14_RepoData(F13_RepoData): | ||
| 111 | removedKeywords = F13_RepoData.removedKeywords | ||
| 112 | removedAttrs = F13_RepoData.removedAttrs | ||
| 113 | |||
| 114 | def __init__(self, *args, **kwargs): | ||
| 115 | F13_RepoData.__init__(self, *args, **kwargs) | ||
| 116 | self.noverifyssl = kwargs.get("noverifyssl", False) | ||
| 117 | |||
| 118 | def _getArgsAsStr(self): | ||
| 119 | retval = F13_RepoData._getArgsAsStr(self) | ||
| 120 | |||
| 121 | if self.noverifyssl: | ||
| 122 | retval += " --noverifyssl" | ||
| 123 | |||
| 124 | return retval | ||
| 125 | |||
| 126 | RHEL6_RepoData = F14_RepoData | ||
| 127 | |||
| 128 | F15_RepoData = F14_RepoData | ||
| 129 | |||
| 130 | class FC6_Repo(KickstartCommand): | ||
| 131 | removedKeywords = KickstartCommand.removedKeywords | ||
| 132 | removedAttrs = KickstartCommand.removedAttrs | ||
| 133 | |||
| 134 | urlRequired = True | ||
| 135 | |||
| 136 | def __init__(self, writePriority=0, *args, **kwargs): | ||
| 137 | KickstartCommand.__init__(self, writePriority, *args, **kwargs) | ||
| 138 | self.op = self._getParser() | ||
| 139 | |||
| 140 | self.repoList = kwargs.get("repoList", []) | ||
| 141 | |||
| 142 | def __str__(self): | ||
| 143 | retval = "" | ||
| 144 | for repo in self.repoList: | ||
| 145 | retval += repo.__str__() | ||
| 146 | |||
| 147 | return retval | ||
| 148 | |||
| 149 | def _getParser(self): | ||
| 150 | op = KSOptionParser() | ||
| 151 | op.add_option("--name", dest="name", required=1) | ||
| 152 | op.add_option("--baseurl") | ||
| 153 | op.add_option("--mirrorlist") | ||
| 154 | return op | ||
| 155 | |||
| 156 | def parse(self, args): | ||
| 157 | (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) | ||
| 158 | |||
| 159 | if len(extra) != 0: | ||
| 160 | mapping = {"command": "repo", "options": extra} | ||
| 161 | raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %(command)s command: %(options)s") % mapping) | ||
| 162 | |||
| 163 | # This is lame, but I can't think of a better way to make sure only | ||
| 164 | # one of these two is specified. | ||
| 165 | if opts.baseurl and opts.mirrorlist: | ||
| 166 | raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("Only one of --baseurl and --mirrorlist may be specified for repo command.")) | ||
| 167 | |||
| 168 | if self.urlRequired and not opts.baseurl and not opts.mirrorlist: | ||
| 169 | raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("One of --baseurl or --mirrorlist must be specified for repo command.")) | ||
| 170 | |||
| 171 | rd = self.handler.RepoData() | ||
| 172 | self._setToObj(self.op, opts, rd) | ||
| 173 | rd.lineno = self.lineno | ||
| 174 | |||
| 175 | # Check for duplicates in the data list. | ||
| 176 | if rd in self.dataList(): | ||
| 177 | warnings.warn(_("A repo with the name %s has already been defined.") % rd.name) | ||
| 178 | |||
| 179 | return rd | ||
| 180 | |||
| 181 | def dataList(self): | ||
| 182 | return self.repoList | ||
| 183 | |||
| 184 | class F8_Repo(FC6_Repo): | ||
| 185 | removedKeywords = FC6_Repo.removedKeywords | ||
| 186 | removedAttrs = FC6_Repo.removedAttrs | ||
| 187 | |||
| 188 | def __str__(self): | ||
| 189 | retval = "" | ||
| 190 | for repo in self.repoList: | ||
| 191 | retval += repo.__str__() | ||
| 192 | |||
| 193 | return retval | ||
| 194 | |||
| 195 | def _getParser(self): | ||
| 196 | def list_cb (option, opt_str, value, parser): | ||
| 197 | for d in value.split(','): | ||
| 198 | parser.values.ensure_value(option.dest, []).append(d) | ||
| 199 | |||
| 200 | op = FC6_Repo._getParser(self) | ||
| 201 | op.add_option("--cost", action="store", type="int") | ||
| 202 | op.add_option("--excludepkgs", action="callback", callback=list_cb, | ||
| 203 | nargs=1, type="string") | ||
| 204 | op.add_option("--includepkgs", action="callback", callback=list_cb, | ||
| 205 | nargs=1, type="string") | ||
| 206 | return op | ||
| 207 | |||
| 208 | def methodToRepo(self): | ||
| 209 | if not self.handler.method.url: | ||
| 210 | raise KickstartError, formatErrorMsg(self.handler.method.lineno, msg=_("Method must be a url to be added to the repo list.")) | ||
| 211 | reponame = "ks-method-url" | ||
| 212 | repourl = self.handler.method.url | ||
| 213 | rd = self.handler.RepoData(name=reponame, baseurl=repourl) | ||
| 214 | return rd | ||
| 215 | |||
| 216 | class F11_Repo(F8_Repo): | ||
| 217 | removedKeywords = F8_Repo.removedKeywords | ||
| 218 | removedAttrs = F8_Repo.removedAttrs | ||
| 219 | |||
| 220 | def _getParser(self): | ||
| 221 | op = F8_Repo._getParser(self) | ||
| 222 | op.add_option("--ignoregroups", action="store", type="ksboolean") | ||
| 223 | return op | ||
| 224 | |||
| 225 | class F13_Repo(F11_Repo): | ||
| 226 | removedKeywords = F11_Repo.removedKeywords | ||
| 227 | removedAttrs = F11_Repo.removedAttrs | ||
| 228 | |||
| 229 | def _getParser(self): | ||
| 230 | op = F11_Repo._getParser(self) | ||
| 231 | op.add_option("--proxy") | ||
| 232 | return op | ||
| 233 | |||
| 234 | class F14_Repo(F13_Repo): | ||
| 235 | removedKeywords = F13_Repo.removedKeywords | ||
| 236 | removedAttrs = F13_Repo.removedAttrs | ||
| 237 | |||
| 238 | def _getParser(self): | ||
| 239 | op = F13_Repo._getParser(self) | ||
| 240 | op.add_option("--noverifyssl", action="store_true", default=False) | ||
| 241 | return op | ||
| 242 | |||
| 243 | RHEL6_Repo = F14_Repo | ||
| 244 | |||
| 245 | class F15_Repo(F14_Repo): | ||
| 246 | removedKeywords = F14_Repo.removedKeywords | ||
| 247 | removedAttrs = F14_Repo.removedAttrs | ||
| 248 | |||
| 249 | urlRequired = False | ||
