diff options
Diffstat (limited to 'scripts/lib/wic/kickstart/__init__.py')
-rw-r--r-- | scripts/lib/wic/kickstart/__init__.py | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/scripts/lib/wic/kickstart/__init__.py b/scripts/lib/wic/kickstart/__init__.py new file mode 100644 index 0000000000..4f5b778b5d --- /dev/null +++ b/scripts/lib/wic/kickstart/__init__.py | |||
@@ -0,0 +1,125 @@ | |||
1 | #!/usr/bin/python -tt | ||
2 | # | ||
3 | # Copyright (c) 2007 Red Hat, Inc. | ||
4 | # Copyright (c) 2009, 2010, 2011 Intel, Inc. | ||
5 | # | ||
6 | # This program is free software; you can redistribute it and/or modify it | ||
7 | # under the terms of the GNU General Public License as published by the Free | ||
8 | # Software Foundation; version 2 of the License | ||
9 | # | ||
10 | # This program is distributed in the hope that it will be useful, but | ||
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
13 | # for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License along | ||
16 | # with this program; if not, write to the Free Software Foundation, Inc., 59 | ||
17 | # Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | import os, sys, re | ||
20 | import shutil | ||
21 | import subprocess | ||
22 | import string | ||
23 | |||
24 | import pykickstart.sections as kssections | ||
25 | import pykickstart.commands as kscommands | ||
26 | import pykickstart.constants as ksconstants | ||
27 | import pykickstart.errors as kserrors | ||
28 | import pykickstart.parser as ksparser | ||
29 | import pykickstart.version as ksversion | ||
30 | from pykickstart.handlers.control import commandMap | ||
31 | from pykickstart.handlers.control import dataMap | ||
32 | |||
33 | from wic import msger | ||
34 | from wic.utils import errors, misc, runner, fs_related as fs | ||
35 | from custom_commands import wicboot, partition | ||
36 | |||
37 | def read_kickstart(path): | ||
38 | """Parse a kickstart file and return a KickstartParser instance. | ||
39 | |||
40 | This is a simple utility function which takes a path to a kickstart file, | ||
41 | parses it and returns a pykickstart KickstartParser instance which can | ||
42 | be then passed to an ImageCreator constructor. | ||
43 | |||
44 | If an error occurs, a CreatorError exception is thrown. | ||
45 | """ | ||
46 | |||
47 | #version = ksversion.makeVersion() | ||
48 | #ks = ksparser.KickstartParser(version) | ||
49 | |||
50 | using_version = ksversion.DEVEL | ||
51 | commandMap[using_version]["bootloader"] = wicboot.Wic_Bootloader | ||
52 | commandMap[using_version]["part"] = partition.Wic_Partition | ||
53 | commandMap[using_version]["partition"] = partition.Wic_Partition | ||
54 | dataMap[using_version]["PartData"] = partition.Wic_PartData | ||
55 | superclass = ksversion.returnClassForVersion(version=using_version) | ||
56 | |||
57 | class KSHandlers(superclass): | ||
58 | def __init__(self): | ||
59 | superclass.__init__(self, mapping=commandMap[using_version]) | ||
60 | |||
61 | ks = ksparser.KickstartParser(KSHandlers(), errorsAreFatal=False) | ||
62 | |||
63 | try: | ||
64 | ks.readKickstart(path) | ||
65 | except (kserrors.KickstartParseError, kserrors.KickstartError), err: | ||
66 | if msger.ask("Errors occured on kickstart file, skip and continue?"): | ||
67 | msger.warning("%s" % err) | ||
68 | pass | ||
69 | else: | ||
70 | raise errors.KsError("%s" % err) | ||
71 | |||
72 | return ks | ||
73 | |||
74 | def get_image_size(ks, default = None): | ||
75 | __size = 0 | ||
76 | for p in ks.handler.partition.partitions: | ||
77 | if p.mountpoint == "/" and p.size: | ||
78 | __size = p.size | ||
79 | if __size > 0: | ||
80 | return int(__size) * 1024L * 1024L | ||
81 | else: | ||
82 | return default | ||
83 | |||
84 | def get_image_fstype(ks, default = None): | ||
85 | for p in ks.handler.partition.partitions: | ||
86 | if p.mountpoint == "/" and p.fstype: | ||
87 | return p.fstype | ||
88 | return default | ||
89 | |||
90 | def get_image_fsopts(ks, default = None): | ||
91 | for p in ks.handler.partition.partitions: | ||
92 | if p.mountpoint == "/" and p.fsopts: | ||
93 | return p.fsopts | ||
94 | return default | ||
95 | |||
96 | def get_timeout(ks, default = None): | ||
97 | if not hasattr(ks.handler.bootloader, "timeout"): | ||
98 | return default | ||
99 | if ks.handler.bootloader.timeout is None: | ||
100 | return default | ||
101 | return int(ks.handler.bootloader.timeout) | ||
102 | |||
103 | def get_kernel_args(ks, default = "ro rd.live.image"): | ||
104 | if not hasattr(ks.handler.bootloader, "appendLine"): | ||
105 | return default | ||
106 | if ks.handler.bootloader.appendLine is None: | ||
107 | return default | ||
108 | return "%s %s" %(default, ks.handler.bootloader.appendLine) | ||
109 | |||
110 | def get_menu_args(ks, default = ""): | ||
111 | if not hasattr(ks.handler.bootloader, "menus"): | ||
112 | return default | ||
113 | if ks.handler.bootloader.menus in (None, ""): | ||
114 | return default | ||
115 | return "%s" % ks.handler.bootloader.menus | ||
116 | |||
117 | def get_default_kernel(ks, default = None): | ||
118 | if not hasattr(ks.handler.bootloader, "default"): | ||
119 | return default | ||
120 | if not ks.handler.bootloader.default: | ||
121 | return default | ||
122 | return ks.handler.bootloader.default | ||
123 | |||
124 | def get_partitions(ks): | ||
125 | return ks.handler.partition.partitions | ||