|
8 | 8 | import subprocess
|
9 | 9 | import tempfile
|
10 | 10 | from collections import defaultdict
|
11 |
| -from typing import TYPE_CHECKING, Generator, List |
| 11 | +from typing import TYPE_CHECKING, ContextManager, Generator, List |
12 | 12 |
|
13 | 13 | from .btrfs import do_dedupe, is_btrfs
|
14 |
| -from .system import System, SystemConfig |
| 14 | +from .system import MaintenanceSystem, System, SystemConfig |
15 | 15 | from .utils import is_on_rotational, pause_automounting
|
16 | 16 |
|
17 | 17 | if TYPE_CHECKING:
|
@@ -47,10 +47,36 @@ def list_images(self) -> List[str]:
|
47 | 47 |
|
48 | 48 | def create_system(self, name: str) -> System:
|
49 | 49 | """
|
50 |
| - Instantiate a System from its name or path |
| 50 | + Instantiate a System by its name |
51 | 51 | """
|
52 | 52 | raise NotImplementedError(f"{self.__class__.__name__}.create_system is not implemented")
|
53 | 53 |
|
| 54 | + def system(self, name: str) -> ContextManager[System]: |
| 55 | + """ |
| 56 | + Instantiate a System that can only be used for the duration |
| 57 | + of this context manager. |
| 58 | + """ |
| 59 | + # raise NotImplementedError(f"{self.__class__.__name__}.maintenance_system is not implemented") |
| 60 | + @contextlib.contextmanager |
| 61 | + def res(): |
| 62 | + yield self.create_system(name) |
| 63 | + return res() |
| 64 | + |
| 65 | + def maintenance_system(self, name: str) -> ContextManager[MaintenanceSystem]: |
| 66 | + """ |
| 67 | + Instantiate a MaintenanceSystem that can only be used for the duration |
| 68 | + of this context manager. |
| 69 | +
|
| 70 | + This allows maintenance to be transactional, limited to backends that |
| 71 | + support it, so that errors in the maintenance roll back to the previous |
| 72 | + state and do not leave an inconsistent OS image |
| 73 | + """ |
| 74 | + # raise NotImplementedError(f"{self.__class__.__name__}.maintenance_system is not implemented") |
| 75 | + @contextlib.contextmanager |
| 76 | + def res(): |
| 77 | + yield self.create_system(name) |
| 78 | + return res() |
| 79 | + |
54 | 80 | def add_dependencies(self, images: List[str]) -> List[str]:
|
55 | 81 | """
|
56 | 82 | Add dependencies to the given list of images, returning the extended
|
|
0 commit comments