-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The load command renamed to import. Refactoring.
- Loading branch information
1 parent
0a04b36
commit 8ae8c9d
Showing
6 changed files
with
121 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""import CLI command implementation.""" | ||
# dem/cli/command/import_cmd.py | ||
|
||
from dem.core.dev_env import DevEnv | ||
from dem.core.platform import Platform | ||
from dem.cli.console import stderr | ||
import json, os | ||
import typer | ||
|
||
def import_dev_env_from_json(platform: Platform,path_to_dev_env: str) -> None: | ||
""" Import a Development Environment from a JSON file. | ||
Args: | ||
platform (Platform): The platform instance. | ||
path_to_dev_env (str): The path to the JSON file. | ||
Raises: | ||
typer.Abort: If the Development Environment already exists, or the JSON format is | ||
invalid. | ||
""" | ||
raw_file = open(path_to_dev_env, "r") | ||
|
||
try: | ||
dev_env_descriptor_to_import = json.load(raw_file) | ||
|
||
if platform.get_dev_env_by_name(dev_env_descriptor_to_import["name"]) is not None: | ||
stderr.print("[red]Error: The Development Environment already exists.[/]") | ||
raise typer.Abort() | ||
else: | ||
new_dev_env: DevEnv = DevEnv(dev_env_descriptor_to_import) | ||
platform.local_dev_envs.append(new_dev_env) | ||
except json.decoder.JSONDecodeError: | ||
stderr.print("[red]Error: invalid json format.[/]") | ||
raise typer.Abort() | ||
else: | ||
raw_file.close() | ||
|
||
def execute(platform: Platform, path_to_dev_env: str) -> None: | ||
""" Execute the import command. | ||
Args: | ||
platform (Platform): The platform instance. | ||
path_to_dev_env (str): The path to the JSON file. | ||
Raises: | ||
typer.Abort: If the Development Environment already exists, or the JSON format is | ||
invalid. | ||
""" | ||
if os.path.exists(path_to_dev_env): | ||
import_dev_env_from_json(platform,path_to_dev_env) | ||
platform.flush_descriptors() | ||
else: | ||
stderr.print("[red]Error: The input file does not exist.[/]") |
This file was deleted.
Oops, something went wrong.
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