]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use 0 as the default value for partition sizes instead of None 1165/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 4 Sep 2022 19:06:54 +0000 (21:06 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 7 Sep 2022 13:24:43 +0000 (15:24 +0200)
mkosi/__init__.py
mkosi/backend.py
tests/test_init.py

index 276e8479e3b5665146297e2dfc374fe672f077ff..ea36ae31defe8a701af641aef3a72b19fc739520 100644 (file)
@@ -776,19 +776,19 @@ def initialize_partition_table(state: MkosiState, force: bool = False) -> None:
     for condition, label, size, type_uuid, name, read_only in (
             (state.config.bootable,
              PartitionIdentifier.esp, state.config.esp_size, GPT_ESP, "ESP System Partition", False),
-            (state.config.bios_size is not None,
+            (state.config.bios_size > 0,
              PartitionIdentifier.bios, state.config.bios_size, GPT_BIOS, "BIOS Boot Partition", False),
-            (state.config.xbootldr_size is not None,
+            (state.config.xbootldr_size > 0,
              PartitionIdentifier.xbootldr, state.config.xbootldr_size, GPT_XBOOTLDR, "Boot Loader Partition", False),
-            (state.config.swap_size is not None,
+            (state.config.swap_size > 0,
              PartitionIdentifier.swap, state.config.swap_size, GPT_SWAP, "Swap Partition", False),
-            (no_btrfs and state.config.home_size is not None,
+            (no_btrfs and state.config.home_size > 0,
              PartitionIdentifier.home, state.config.home_size, GPT_HOME, "Home Partition", False),
-            (no_btrfs and state.config.srv_size is not None,
+            (no_btrfs and state.config.srv_size > 0,
              PartitionIdentifier.srv, state.config.srv_size, GPT_SRV, "Server Data Partition", False),
-            (no_btrfs and state.config.var_size is not None,
+            (no_btrfs and state.config.var_size > 0,
              PartitionIdentifier.var, state.config.var_size, GPT_VAR, "Variable Data Partition", False),
-            (no_btrfs and state.config.tmp_size is not None,
+            (no_btrfs and state.config.tmp_size > 0,
              PartitionIdentifier.tmp, state.config.tmp_size, GPT_TMP, "Temporary Data Partition", False),
             (not is_generated_root(state.config),
              PartitionIdentifier.root, state.config.root_size,
@@ -796,7 +796,7 @@ def initialize_partition_table(state: MkosiState, force: bool = False) -> None:
              root_partition_description(state.config),
              state.config.read_only)):
 
-        if condition and size is not None:
+        if condition and size > 0:
             table.add(label, size, type_uuid, name, read_only=read_only)
 
     state.partition_table = table
@@ -5873,10 +5873,10 @@ def parse_args_file_group(
     return create_parser().parse_args(config_files + argv)
 
 
-def parse_bytes(num_bytes: Optional[str], *, sector_size: int = 512) -> Optional[int]:
+def parse_bytes(num_bytes: Optional[str], *, sector_size: int = 512) -> int:
     """Convert a string for a number of bytes into a number rounding up to sector size."""
     if num_bytes is None:
-        return None
+        return 0
 
     if num_bytes.endswith("G"):
         factor = 1024 ** 3
@@ -6515,10 +6515,10 @@ def load_args(args: argparse.Namespace) -> MkosiConfig:
     args.swap_size = parse_bytes(args.swap_size)
     args.bios_size = parse_bytes(args.bios_size)
 
-    if args.root_size is None:
+    if args.root_size == 0:
         args.root_size = 3 * 1024 * 1024 * 1024
 
-    if args.bootable and args.esp_size is None:
+    if args.bootable and args.esp_size == 0:
         args.esp_size = 256 * 1024 * 1024
 
     if args.secure_boot_key is not None:
@@ -6675,15 +6675,15 @@ def yes_no_or(b: Union[bool, str]) -> str:
     return b if isinstance(b, str) else yes_no(b)
 
 
-def format_bytes_or_disabled(sz: Optional[int]) -> str:
-    if sz is None:
+def format_bytes_or_disabled(sz: int) -> str:
+    if sz == 0:
         return "(disabled)"
 
     return format_bytes(sz)
 
 
-def format_bytes_or_auto(sz: Optional[int]) -> str:
-    if sz is None:
+def format_bytes_or_auto(sz: int) -> str:
+    if sz == 0:
         return "(automatic)"
 
     return format_bytes(sz)
index 880f532308ed1698579dff1c10eccaa979040b32..911d6620c9d60718ca49cb2a9c98413295b56d6f 100644 (file)
@@ -525,14 +525,14 @@ class MkosiConfig:
     nspawn_settings: Optional[Path]
     base_image: Optional[Path]
     root_size: int
-    esp_size: Optional[int]
-    xbootldr_size: Optional[int]
-    swap_size: Optional[int]
-    home_size: Optional[int]
-    srv_size: Optional[int]
-    var_size: Optional[int]
-    tmp_size: Optional[int]
-    bios_size: Optional[int]
+    esp_size: int
+    xbootldr_size: int
+    swap_size: int
+    home_size: int
+    srv_size: int
+    var_size: int
+    tmp_size: int
+    bios_size: int
     usr_only: bool
     split_artifacts: bool
     checksum: bool
index 2281e1c8dcc5e716d8a38d4bf2c1877b3dcf3586..7c65ca39e52410ca6acf1735083775644ca265a0 100644 (file)
@@ -58,7 +58,7 @@ def test_copy_file(tmpdir: Path) -> None:
 
 
 def test_parse_bytes() -> None:
-    assert mkosi.parse_bytes(None) is None
+    assert mkosi.parse_bytes(None) == 0
     assert mkosi.parse_bytes("1") == 512
     assert mkosi.parse_bytes("1000") == 1024
     assert mkosi.parse_bytes("1K") == 1024