diff options
| author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:38:32 +0100 |
|---|---|---|
| committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:50:20 +0100 |
| commit | e2e6f6fe07049f33cb6348780fa975162752e421 (patch) | |
| tree | b1813295411235d1297a0ed642b1346b24fdfb12 /scripts/lib/mic/3rdparty/pykickstart/commands/partition.py | |
| download | poky-e2e6f6fe07049f33cb6348780fa975162752e421.tar.gz | |
initial commit of Enea Linux 3.1
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'scripts/lib/mic/3rdparty/pykickstart/commands/partition.py')
| -rw-r--r-- | scripts/lib/mic/3rdparty/pykickstart/commands/partition.py | 353 |
1 files changed, 353 insertions, 0 deletions
diff --git a/scripts/lib/mic/3rdparty/pykickstart/commands/partition.py b/scripts/lib/mic/3rdparty/pykickstart/commands/partition.py new file mode 100644 index 0000000000..e65e012d02 --- /dev/null +++ b/scripts/lib/mic/3rdparty/pykickstart/commands/partition.py | |||
| @@ -0,0 +1,353 @@ | |||
| 1 | # | ||
| 2 | # Chris Lumens <clumens@redhat.com> | ||
| 3 | # | ||
| 4 | # Copyright 2005, 2006, 2007, 2008 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.errors import * | ||
| 22 | from pykickstart.options import * | ||
| 23 | |||
| 24 | import gettext | ||
| 25 | import warnings | ||
| 26 | _ = lambda x: gettext.ldgettext("pykickstart", x) | ||
| 27 | |||
| 28 | class FC3_PartData(BaseData): | ||
| 29 | removedKeywords = BaseData.removedKeywords | ||
| 30 | removedAttrs = BaseData.removedAttrs | ||
| 31 | |||
| 32 | def __init__(self, *args, **kwargs): | ||
| 33 | BaseData.__init__(self, *args, **kwargs) | ||
| 34 | self.active = kwargs.get("active", False) | ||
| 35 | self.primOnly = kwargs.get("primOnly", False) | ||
| 36 | self.end = kwargs.get("end", 0) | ||
| 37 | self.fstype = kwargs.get("fstype", "") | ||
| 38 | self.grow = kwargs.get("grow", False) | ||
| 39 | self.maxSizeMB = kwargs.get("maxSizeMB", 0) | ||
| 40 | self.format = kwargs.get("format", True) | ||
| 41 | self.onbiosdisk = kwargs.get("onbiosdisk", "") | ||
| 42 | self.disk = kwargs.get("disk", "") | ||
| 43 | self.onPart = kwargs.get("onPart", "") | ||
| 44 | self.recommended = kwargs.get("recommended", False) | ||
| 45 | self.size = kwargs.get("size", None) | ||
| 46 | self.start = kwargs.get("start", 0) | ||
| 47 | self.mountpoint = kwargs.get("mountpoint", "") | ||
| 48 | |||
| 49 | def __eq__(self, y): | ||
| 50 | if self.mountpoint: | ||
| 51 | return self.mountpoint == y.mountpoint | ||
| 52 | else: | ||
| 53 | return False | ||
| 54 | |||
| 55 | def _getArgsAsStr(self): | ||
| 56 | retval = "" | ||
| 57 | |||
| 58 | if self.active: | ||
| 59 | retval += " --active" | ||
| 60 | if self.primOnly: | ||
| 61 | retval += " --asprimary" | ||
| 62 | if hasattr(self, "end") and self.end != 0: | ||
| 63 | retval += " --end=%s" % self.end | ||
| 64 | if self.fstype != "": | ||
| 65 | retval += " --fstype=\"%s\"" % self.fstype | ||
| 66 | if self.grow: | ||
| 67 | retval += " --grow" | ||
| 68 | if self.maxSizeMB > 0: | ||
| 69 | retval += " --maxsize=%d" % self.maxSizeMB | ||
| 70 | if not self.format: | ||
| 71 | retval += " --noformat" | ||
| 72 | if self.onbiosdisk != "": | ||
| 73 | retval += " --onbiosdisk=%s" % self.onbiosdisk | ||
| 74 | if self.disk != "": | ||
| 75 | retval += " --ondisk=%s" % self.disk | ||
| 76 | if self.onPart != "": | ||
| 77 | retval += " --onpart=%s" % self.onPart | ||
| 78 | if self.recommended: | ||
| 79 | retval += " --recommended" | ||
| 80 | if self.size and self.size != 0: | ||
| 81 | retval += " --size=%s" % self.size | ||
| 82 | if hasattr(self, "start") and self.start != 0: | ||
| 83 | retval += " --start=%s" % self.start | ||
| 84 | |||
| 85 | return retval | ||
| 86 | |||
| 87 | def __str__(self): | ||
| 88 | retval = BaseData.__str__(self) | ||
| 89 | if self.mountpoint: | ||
| 90 | mountpoint_str = "%s" % self.mountpoint | ||
| 91 | else: | ||
| 92 | mountpoint_str = "(No mount point)" | ||
| 93 | retval += "part %s%s\n" % (mountpoint_str, self._getArgsAsStr()) | ||
| 94 | return retval | ||
| 95 | |||
| 96 | class FC4_PartData(FC3_PartData): | ||
| 97 | removedKeywords = FC3_PartData.removedKeywords | ||
| 98 | removedAttrs = FC3_PartData.removedAttrs | ||
| 99 | |||
| 100 | def __init__(self, *args, **kwargs): | ||
| 101 | FC3_PartData.__init__(self, *args, **kwargs) | ||
| 102 | self.bytesPerInode = kwargs.get("bytesPerInode", 4096) | ||
| 103 | self.fsopts = kwargs.get("fsopts", "") | ||
| 104 | self.label = kwargs.get("label", "") | ||
| 105 | |||
| 106 | def _getArgsAsStr(self): | ||
| 107 | retval = FC3_PartData._getArgsAsStr(self) | ||
| 108 | |||
| 109 | if hasattr(self, "bytesPerInode") and self.bytesPerInode != 0: | ||
| 110 | retval += " --bytes-per-inode=%d" % self.bytesPerInode | ||
| 111 | if self.fsopts != "": | ||
| 112 | retval += " --fsoptions=\"%s\"" % self.fsopts | ||
| 113 | if self.label != "": | ||
| 114 | retval += " --label=%s" % self.label | ||
| 115 | |||
| 116 | return retval | ||
| 117 | |||
| 118 | class RHEL5_PartData(FC4_PartData): | ||
| 119 | removedKeywords = FC4_PartData.removedKeywords | ||
| 120 | removedAttrs = FC4_PartData.removedAttrs | ||
| 121 | |||
| 122 | def __init__(self, *args, **kwargs): | ||
| 123 | FC4_PartData.__init__(self, *args, **kwargs) | ||
| 124 | self.encrypted = kwargs.get("encrypted", False) | ||
| 125 | self.passphrase = kwargs.get("passphrase", "") | ||
| 126 | |||
| 127 | def _getArgsAsStr(self): | ||
| 128 | retval = FC4_PartData._getArgsAsStr(self) | ||
| 129 | |||
| 130 | if self.encrypted: | ||
| 131 | retval += " --encrypted" | ||
| 132 | |||
| 133 | if self.passphrase != "": | ||
| 134 | retval += " --passphrase=\"%s\"" % self.passphrase | ||
| 135 | |||
| 136 | return retval | ||
| 137 | |||
| 138 | class F9_PartData(FC4_PartData): | ||
| 139 | removedKeywords = FC4_PartData.removedKeywords + ["bytesPerInode"] | ||
| 140 | removedAttrs = FC4_PartData.removedAttrs + ["bytesPerInode"] | ||
| 141 | |||
| 142 | def __init__(self, *args, **kwargs): | ||
| 143 | FC4_PartData.__init__(self, *args, **kwargs) | ||
| 144 | self.deleteRemovedAttrs() | ||
| 145 | |||
| 146 | self.fsopts = kwargs.get("fsopts", "") | ||
| 147 | self.label = kwargs.get("label", "") | ||
| 148 | self.fsprofile = kwargs.get("fsprofile", "") | ||
| 149 | self.encrypted = kwargs.get("encrypted", False) | ||
| 150 | self.passphrase = kwargs.get("passphrase", "") | ||
| 151 | |||
| 152 | def _getArgsAsStr(self): | ||
| 153 | retval = FC4_PartData._getArgsAsStr(self) | ||
| 154 | |||
| 155 | if self.fsprofile != "": | ||
| 156 | retval += " --fsprofile=\"%s\"" % self.fsprofile | ||
| 157 | if self.encrypted: | ||
| 158 | retval += " --encrypted" | ||
| 159 | |||
| 160 | if self.passphrase != "": | ||
| 161 | retval += " --passphrase=\"%s\"" % self.passphrase | ||
| 162 | |||
| 163 | return retval | ||
| 164 | |||
| 165 | class F11_PartData(F9_PartData): | ||
| 166 | removedKeywords = F9_PartData.removedKeywords + ["start", "end"] | ||
| 167 | removedAttrs = F9_PartData.removedAttrs + ["start", "end"] | ||
| 168 | |||
| 169 | class F12_PartData(F11_PartData): | ||
| 170 | removedKeywords = F11_PartData.removedKeywords | ||
| 171 | removedAttrs = F11_PartData.removedAttrs | ||
| 172 | |||
| 173 | def __init__(self, *args, **kwargs): | ||
| 174 | F11_PartData.__init__(self, *args, **kwargs) | ||
| 175 | |||
| 176 | self.escrowcert = kwargs.get("escrowcert", "") | ||
| 177 | self.backuppassphrase = kwargs.get("backuppassphrase", False) | ||
| 178 | |||
| 179 | def _getArgsAsStr(self): | ||
| 180 | retval = F11_PartData._getArgsAsStr(self) | ||
| 181 | |||
| 182 | if self.encrypted and self.escrowcert != "": | ||
| 183 | retval += " --escrowcert=\"%s\"" % self.escrowcert | ||
| 184 | |||
| 185 | if self.backuppassphrase: | ||
| 186 | retval += " --backuppassphrase" | ||
| 187 | |||
| 188 | return retval | ||
| 189 | |||
| 190 | F14_PartData = F12_PartData | ||
| 191 | |||
| 192 | class FC3_Partition(KickstartCommand): | ||
| 193 | removedKeywords = KickstartCommand.removedKeywords | ||
| 194 | removedAttrs = KickstartCommand.removedAttrs | ||
| 195 | |||
| 196 | def __init__(self, writePriority=130, *args, **kwargs): | ||
| 197 | KickstartCommand.__init__(self, writePriority, *args, **kwargs) | ||
| 198 | self.op = self._getParser() | ||
| 199 | |||
| 200 | self.partitions = kwargs.get("partitions", []) | ||
| 201 | |||
| 202 | def __str__(self): | ||
| 203 | retval = "" | ||
| 204 | |||
| 205 | for part in self.partitions: | ||
| 206 | retval += part.__str__() | ||
| 207 | |||
| 208 | if retval != "": | ||
| 209 | return "# Disk partitioning information\n" + retval | ||
| 210 | else: | ||
| 211 | return "" | ||
| 212 | |||
| 213 | def _getParser(self): | ||
| 214 | def part_cb (option, opt_str, value, parser): | ||
| 215 | if value.startswith("/dev/"): | ||
| 216 | parser.values.ensure_value(option.dest, value[5:]) | ||
| 217 | else: | ||
| 218 | parser.values.ensure_value(option.dest, value) | ||
| 219 | |||
| 220 | op = KSOptionParser() | ||
| 221 | op.add_option("--active", dest="active", action="store_true", | ||
| 222 | default=False) | ||
| 223 | op.add_option("--asprimary", dest="primOnly", action="store_true", | ||
| 224 | default=False) | ||
| 225 | op.add_option("--end", dest="end", action="store", type="int", | ||
| 226 | nargs=1) | ||
| 227 | op.add_option("--fstype", "--type", dest="fstype") | ||
| 228 | op.add_option("--grow", dest="grow", action="store_true", default=False) | ||
| 229 | op.add_option("--maxsize", dest="maxSizeMB", action="store", type="int", | ||
| 230 | nargs=1) | ||
| 231 | op.add_option("--noformat", dest="format", action="store_false", | ||
| 232 | default=True) | ||
| 233 | op.add_option("--onbiosdisk", dest="onbiosdisk") | ||
| 234 | op.add_option("--ondisk", "--ondrive", dest="disk") | ||
| 235 | op.add_option("--onpart", "--usepart", dest="onPart", action="callback", | ||
| 236 | callback=part_cb, nargs=1, type="string") | ||
| 237 | op.add_option("--recommended", dest="recommended", action="store_true", | ||
| 238 | default=False) | ||
| 239 | op.add_option("--size", dest="size", action="store", type="int", | ||
| 240 | nargs=1) | ||
| 241 | op.add_option("--start", dest="start", action="store", type="int", | ||
| 242 | nargs=1) | ||
| 243 | return op | ||
| 244 | |||
| 245 | def parse(self, args): | ||
| 246 | (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno) | ||
| 247 | |||
| 248 | pd = self.handler.PartData() | ||
| 249 | self._setToObj(self.op, opts, pd) | ||
| 250 | pd.lineno = self.lineno | ||
| 251 | if extra: | ||
| 252 | pd.mountpoint = extra[0] | ||
| 253 | if pd in self.dataList(): | ||
| 254 | warnings.warn(_("A partition with the mountpoint %s has already been defined.") % pd.mountpoint) | ||
| 255 | else: | ||
| 256 | pd.mountpoint = None | ||
| 257 | |||
| 258 | return pd | ||
| 259 | |||
| 260 | def dataList(self): | ||
| 261 | return self.partitions | ||
| 262 | |||
| 263 | class FC4_Partition(FC3_Partition): | ||
| 264 | removedKeywords = FC3_Partition.removedKeywords | ||
| 265 | removedAttrs = FC3_Partition.removedAttrs | ||
| 266 | |||
| 267 | def __init__(self, writePriority=130, *args, **kwargs): | ||
| 268 | FC3_Partition.__init__(self, writePriority, *args, **kwargs) | ||
| 269 | |||
| 270 | def part_cb (option, opt_str, value, parser): | ||
| 271 | if value.startswith("/dev/"): | ||
| 272 | parser.values.ensure_value(option.dest, value[5:]) | ||
| 273 | else: | ||
| 274 | parser.values.ensure_value(option.dest, value) | ||
| 275 | |||
| 276 | def _getParser(self): | ||
| 277 | op = FC3_Partition._getParser(self) | ||
| 278 | op.add_option("--bytes-per-inode", dest="bytesPerInode", action="store", | ||
| 279 | type="int", nargs=1) | ||
| 280 | op.add_option("--fsoptions", dest="fsopts") | ||
| 281 | op.add_option("--label", dest="label") | ||
| 282 | return op | ||
| 283 | |||
| 284 | class RHEL5_Partition(FC4_Partition): | ||
| 285 | removedKeywords = FC4_Partition.removedKeywords | ||
| 286 | removedAttrs = FC4_Partition.removedAttrs | ||
| 287 | |||
| 288 | def __init__(self, writePriority=130, *args, **kwargs): | ||
| 289 | FC4_Partition.__init__(self, writePriority, *args, **kwargs) | ||
| 290 | |||
| 291 | def part_cb (option, opt_str, value, parser): | ||
| 292 | if value.startswith("/dev/"): | ||
| 293 | parser.values.ensure_value(option.dest, value[5:]) | ||
| 294 | else: | ||
| 295 | parser.values.ensure_value(option.dest, value) | ||
| 296 | |||
| 297 | def _getParser(self): | ||
| 298 | op = FC4_Partition._getParser(self) | ||
| 299 | op.add_option("--encrypted", action="store_true", default=False) | ||
| 300 | op.add_option("--passphrase") | ||
| 301 | return op | ||
| 302 | |||
| 303 | class F9_Partition(FC4_Partition): | ||
| 304 | removedKeywords = FC4_Partition.removedKeywords | ||
| 305 | removedAttrs = FC4_Partition.removedAttrs | ||
| 306 | |||
| 307 | def __init__(self, writePriority=130, *args, **kwargs): | ||
| 308 | FC4_Partition.__init__(self, writePriority, *args, **kwargs) | ||
| 309 | |||
| 310 | def part_cb (option, opt_str, value, parser): | ||
| 311 | if value.startswith("/dev/"): | ||
| 312 | parser.values.ensure_value(option.dest, value[5:]) | ||
| 313 | else: | ||
| 314 | parser.values.ensure_value(option.dest, value) | ||
| 315 | |||
| 316 | def _getParser(self): | ||
| 317 | op = FC4_Partition._getParser(self) | ||
| 318 | op.add_option("--bytes-per-inode", deprecated=1) | ||
| 319 | op.add_option("--fsprofile") | ||
| 320 | op.add_option("--encrypted", action="store_true", default=False) | ||
| 321 | op.add_option("--passphrase") | ||
| 322 | return op | ||
| 323 | |||
| 324 | class F11_Partition(F9_Partition): | ||
| 325 | removedKeywords = F9_Partition.removedKeywords | ||
| 326 | removedAttrs = F9_Partition.removedAttrs | ||
| 327 | |||
| 328 | def _getParser(self): | ||
| 329 | op = F9_Partition._getParser(self) | ||
| 330 | op.add_option("--start", deprecated=1) | ||
| 331 | op.add_option("--end", deprecated=1) | ||
| 332 | return op | ||
| 333 | |||
| 334 | class F12_Partition(F11_Partition): | ||
| 335 | removedKeywords = F11_Partition.removedKeywords | ||
| 336 | removedAttrs = F11_Partition.removedAttrs | ||
| 337 | |||
| 338 | def _getParser(self): | ||
| 339 | op = F11_Partition._getParser(self) | ||
| 340 | op.add_option("--escrowcert") | ||
| 341 | op.add_option("--backuppassphrase", action="store_true", default=False) | ||
| 342 | return op | ||
| 343 | |||
| 344 | class F14_Partition(F12_Partition): | ||
| 345 | removedKeywords = F12_Partition.removedKeywords | ||
| 346 | removedAttrs = F12_Partition.removedAttrs | ||
| 347 | |||
| 348 | def _getParser(self): | ||
| 349 | op = F12_Partition._getParser(self) | ||
| 350 | op.remove_option("--bytes-per-inode") | ||
| 351 | op.remove_option("--start") | ||
| 352 | op.remove_option("--end") | ||
| 353 | return op | ||
