Rename command objects by inserting an underscore between the version part
[pykickstart.git] / pykickstart / commands / method.py
blob0f130dc2d97c15c87d15d91a976209ba68c9af06
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2007 Red Hat, Inc.
6 # This software may be freely redistributed under the terms of the GNU
7 # general public license.
9 # You should have received a copy of the GNU General Public License
10 # along with this program; if not, write to the Free Software
11 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13 from pykickstart.base import *
14 from pykickstart.errors import *
15 from pykickstart.options import *
17 from rhpl.translate import _
18 import rhpl.translate as translate
20 translate.textdomain("pykickstart")
22 class FC3_Method(KickstartCommand):
23 def __init__(self, writePriority=0, method=""):
24 KickstartCommand.__init__(self, writePriority)
25 self.method = method
27 def __str__(self):
28 if self.method == "cdrom":
29 return "# Use CDROM installation media\ncdrom\n"
30 elif self.method == "harddrive":
31 msg = "# Use hard drive installation media\nharddrive --dir=%s" % self.dir
33 if hasattr(self, "biospart"):
34 return msg + " --biospart=%s\n" % getattr(self, "biospart")
35 else:
36 return msg + " --partition=%s\n" % getattr(self, "partition")
37 elif self.method == "nfs":
38 return "# Use NFS installation media\nnfs --server=%s --dir=%s\n" % (self.server, self.dir)
39 elif self.method == "url":
40 return "# Use network installation\nurl --url=%s\n" % self.url
41 else:
42 return ""
44 def parse(self, args):
45 op = KSOptionParser(lineno=self.lineno)
47 self.method = self.currentCmd
49 if self.currentCmd == "cdrom":
50 return
51 elif self.currentCmd == "harddrive":
52 op.add_option("--biospart", dest="biospart")
53 op.add_option("--partition", dest="partition")
54 op.add_option("--dir", dest="dir", required=1)
55 elif self.currentCmd == "nfs":
56 op.add_option("--server", dest="server", required=1)
57 op.add_option("--dir", dest="dir", required=1)
58 elif self.currentCmd == "url":
59 op.add_option("--url", dest="url", required=1)
61 (opts, extra) = op.parse_args(args=args)
63 if self.currentCmd == "harddrive":
64 if (getattr(opts, "biospart") == None and getattr(opts, "partition") == None) or \
65 (getattr(opts, "biospart") != None and getattr(opts, "partition") != None):
67 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("One of biospart or partition options must be specified."))
69 self._setToSelf(op, opts)
71 class FC6_Method(FC3_Method):
72 def __init__(self, writePriority=0, method=""):
73 FC3_Method.__init__(self, writePriority, method)
75 def __str__(self):
76 if self.method == "cdrom":
77 return "# Use CDROM installation media\ncdrom\n"
78 elif self.method == "harddrive":
79 msg = "# Use hard drive installation media\nharddrive --dir=%s" % self.dir
81 if hasattr(self, "biospart"):
82 return msg + " --biospart=%s\n" % getattr(self, "biospart")
83 else:
84 return msg + " --partition=%s\n" % getattr(self, "partition")
85 elif self.method == "nfs":
86 retval = "# Use NFS installation media\nnfs --server=%s --dir=%s" % (self.server, self.dir)
87 if hasattr(self, "opts"):
88 retval += " --opts=\"%s\"" % self.opts
90 return retval + "\n"
91 elif self.method == "url":
92 return "# Use network installation\nurl --url=%s\n" % self.url
93 else:
94 return ""
96 def parse(self, args):
97 op = KSOptionParser(lineno=self.lineno)
99 self.method = self.currentCmd
101 if self.currentCmd == "cdrom":
102 return
103 elif self.currentCmd == "harddrive":
104 op.add_option("--biospart", dest="biospart")
105 op.add_option("--partition", dest="partition")
106 op.add_option("--dir", dest="dir", required=1)
107 elif self.currentCmd == "nfs":
108 op.add_option("--server", dest="server", required=1)
109 op.add_option("--dir", dest="dir", required=1)
110 op.add_option("--opts", dest="opts")
111 elif self.currentCmd == "url":
112 op.add_option("--url", dest="url", required=1)
114 (opts, extra) = op.parse_args(args=args)
116 if self.currentCmd == "harddrive":
117 if (getattr(opts, "biospart") == None and getattr(opts, "partition") == None) or \
118 (getattr(opts, "biospart") != None and getattr(opts, "partition") != None):
120 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("One of biospart or partition options must be specified."))
122 self._setToSelf(op, opts)