-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a Session object to hold shared resources during a work session…
…. refs: #52
- Loading branch information
Showing
11 changed files
with
100 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
import contextlib | ||
from typing import Optional, TYPE_CHECKING | ||
|
||
from . import imagestorage | ||
|
||
if TYPE_CHECKING: | ||
from .moncic import Moncic | ||
|
||
|
||
class Session(contextlib.ExitStack): | ||
""" | ||
Hold shared resourcse during a single-threaded Moncic-CI work session | ||
""" | ||
def __init__(self, moncic: Moncic): | ||
super().__init__() | ||
self.moncic = moncic | ||
|
||
# Storage for OS images | ||
self.image_storage: imagestorage.ImageStorage | ||
if self.moncic.config.imagedir is None: | ||
self.image_storage = imagestorage.ImageStorage.create_default(self) | ||
else: | ||
self.image_storage = imagestorage.ImageStorage.create(self, self.moncic.config.imagedir) | ||
|
||
# Images contained in the image storage | ||
self._images: Optional[imagestorage.Images] = None | ||
|
||
def images(self) -> imagestorage.Images: | ||
""" | ||
Return the Images storage | ||
""" | ||
if self._images is None: | ||
self._images = self.enter_context(self.image_storage.images()) | ||
return self._images | ||
|
||
# def __enter__(self): | ||
# super().__enter__() | ||
# return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.