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 imgcreate
.pykickstart
.base
import *
21 from imgcreate
.pykickstart
.constants
import *
22 from imgcreate
.pykickstart
.errors
import *
23 from imgcreate
.pykickstart
.options
import *
28 _
= lambda x
: gettext
.ldgettext("pykickstart", x
)
30 class FC6_RepoData(BaseData
):
31 def __init__(self
, baseurl
="", mirrorlist
=None, name
=""):
32 BaseData
.__init
__(self
)
33 self
.baseurl
= baseurl
34 self
.mirrorlist
= mirrorlist
37 def _getArgsAsStr(self
):
41 retval
+= "--baseurl=%s" % self
.baseurl
43 retval
+= "--mirrorlist=%s" % self
.mirrorlist
48 return "repo --name=%s %s\n" % (self
.name
, self
._getArgsAsStr
())
50 class F8_RepoData(FC6_RepoData
):
51 def __init__(self
, baseurl
="", mirrorlist
=None, name
="", cost
=None,
52 includepkgs
=[], excludepkgs
=[]):
53 FC6_RepoData
.__init
__(self
, baseurl
=baseurl
, mirrorlist
=mirrorlist
,
56 self
.includepkgs
= includepkgs
57 self
.excludepkgs
= excludepkgs
59 def _getArgsAsStr(self
):
60 retval
= FC6_RepoData
._getArgsAsStr
(self
)
63 retval
+= " --cost=%s" % self
.cost
65 retval
+= " --includepkgs=\"%s\"" % string
.join(self
.includepkgs
, ",")
67 retval
+= " --excludepkgs=\"%s\"" % string
.join(self
.excludepkgs
, ",")
71 class FC6_Repo(KickstartCommand
):
72 def __init__(self
, writePriority
=0, repoList
=None):
73 KickstartCommand
.__init
__(self
, writePriority
)
74 self
.op
= self
._getParser
()
79 self
.repoList
= repoList
83 for repo
in self
.repoList
:
84 retval
+= repo
.__str
__()
89 op
= KSOptionParser(lineno
=self
.lineno
)
90 op
.add_option("--name", dest
="name", required
=1)
91 op
.add_option("--baseurl")
92 op
.add_option("--mirrorlist")
95 def parse(self
, args
):
96 (opts
, extra
) = self
.op
.parse_args(args
=args
)
98 # This is lame, but I can't think of a better way to make sure only
99 # one of these two is specified.
100 if opts
.baseurl
and opts
.mirrorlist
:
101 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Only one of --baseurl and --mirrorlist may be specified for repo command."))
103 if not opts
.baseurl
and not opts
.mirrorlist
:
104 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("One of --baseurl or --mirrorlist must be specified for repo command."))
106 rd
= self
.handler
.RepoData()
107 self
._setToObj
(self
.op
, opts
, rd
)
110 def add(self
, newObj
):
111 self
.repoList
.append(newObj
)
113 class F8_Repo(FC6_Repo
):
114 def __init__(self
, writePriority
=0, repoList
=None):
115 FC6_Repo
.__init
__(self
, writePriority
, repoList
)
119 for repo
in self
.repoList
:
120 retval
+= repo
.__str
__()
124 def _getParser(self
):
125 def list_cb (option
, opt_str
, value
, parser
):
126 for d
in value
.split(','):
127 parser
.values
.ensure_value(option
.dest
, []).append(d
)
129 op
= FC6_Repo
._getParser
(self
)
130 op
.add_option("--cost", action
="store", type="int")
131 op
.add_option("--excludepkgs", action
="callback", callback
=list_cb
,
132 nargs
=1, type="string")
133 op
.add_option("--includepkgs", action
="callback", callback
=list_cb
,
134 nargs
=1, type="string")
137 def methodToRepo(self
):
138 if not self
.handler
.method
.url
:
139 raise KickstartError
, formatErrorMsg(self
.handler
.method
.lineno
, msg
=_("Method must be a url to be added to the repo list."))
140 reponame
= "ks-method-url"
141 repourl
= self
.handler
.method
.url
142 rd
= self
.handler
.RepoData(name
=reponame
, baseurl
=repourl
)