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 *
26 from rhpl
.translate
import _
27 import rhpl
.translate
as translate
29 translate
.textdomain("pykickstart")
31 class FC6_RepoData(BaseData
):
32 def __init__(self
, baseurl
="", mirrorlist
="", name
=""):
33 BaseData
.__init
__(self
)
34 self
.baseurl
= baseurl
35 self
.mirrorlist
= mirrorlist
40 urlopt
= "--baseurl=%s" % self
.baseurl
42 urlopt
= "--mirrorlist=%s" % self
.mirrorlist
44 return "repo --name=%s %s\n" % (self
.name
, urlopt
)
46 class F8_RepoData(FC6_RepoData
):
47 def __init__(self
, baseurl
="", mirrorlist
="", name
="", priority
=None,
48 includepkgs
=[], excludepkgs
=[]):
49 FC6_RepoData
.__init
__(self
, baseurl
=baseurl
, mirrorlist
=mirrorlist
,
51 self
.priority
= priority
52 self
.includepkgs
= includepkgs
53 self
.excludepkgs
= excludepkgs
56 str = FC6_RepoData
.__str
__(self
).rstrip()
59 str += " --priority=%s" % self
.priority
61 str += " --includepkgs=\"%s\"" % string
.join(self
.includepkgs
, ",")
63 str += " --excludepkgs=\"%s\"" % string
.join(self
.excludepkgs
, ",")
67 class FC6_Repo(KickstartCommand
):
68 def __init__(self
, writePriority
=0, repoList
=None):
69 KickstartCommand
.__init
__(self
, writePriority
)
74 self
.repoList
= repoList
78 for repo
in self
.repoList
:
79 retval
+= repo
.__str
__()
83 def parse(self
, args
):
84 op
= KSOptionParser(lineno
=self
.lineno
)
85 op
.add_option("--name", dest
="name", required
=1)
86 op
.add_option("--baseurl")
87 op
.add_option("--mirrorlist")
89 (opts
, extra
) = op
.parse_args(args
=args
)
91 # This is lame, but I can't think of a better way to make sure only
92 # one of these two is specified.
93 if opts
.baseurl
and opts
.mirrorlist
:
94 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Only one of --baseurl and --mirrorlist may be specified for repo command."))
96 if not opts
.baseurl
and not opts
.mirrorlist
:
97 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("One of --baseurl or --mirrorlist must be specified for repo command."))
100 self
._setToObj
(op
, opts
, rd
)
103 def add(self
, newObj
):
104 self
.repoList
.append(newObj
)
106 class F8_Repo(FC6_Repo
):
107 def __init__(self
, writePriority
=0, repoList
=None):
108 FC6_Repo
.__init
__(self
, writePriority
, repoList
)
112 for repo
in self
.repoList
:
113 retval
+= repo
.__str
__()
117 def parse(self
, args
):
118 def list_cb (option
, opt_str
, value
, parser
):
119 for d
in value
.split(','):
120 parser
.values
.ensure_value(option
.dest
, []).append(d
)
122 op
= KSOptionParser(lineno
=self
.lineno
)
123 op
.add_option("--name", dest
="name", required
=1)
124 op
.add_option("--baseurl")
125 op
.add_option("--mirrorlist")
126 op
.add_option("--priority", action
="store", type="int")
127 op
.add_option("--excludepkgs", action
="callback", callback
=list_cb
,
128 nargs
=1, type="string")
129 op
.add_option("--includepkgs", action
="callback", callback
=list_cb
,
130 nargs
=1, type="string")
132 (opts
, extra
) = op
.parse_args(args
=args
)
134 # This is lame, but I can't think of a better way to make sure only
135 # one of these two is specified.
136 if opts
.baseurl
and opts
.mirrorlist
:
137 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("Only one of --baseurl and --mirrorlist may be specified for repo command."))
139 if not opts
.baseurl
and not opts
.mirrorlist
:
140 raise KickstartValueError
, formatErrorMsg(self
.lineno
, msg
=_("One of --baseurl or --mirrorlist must be specified for repo command."))
143 self
._setToObj
(op
, opts
, rd
)