Skip to content

Commit

Permalink
Autocomplete implemented.
Browse files Browse the repository at this point in the history
    * Annotated paramters used for command creation.
    * Platform gets initialized in the __main__.py@main()
  • Loading branch information
janosmurai committed Dec 14, 2023
1 parent 1c04606 commit 958863c
Show file tree
Hide file tree
Showing 44 changed files with 603 additions and 497 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Development Environments for embedded software development.
> The DEM can be used locally, but it is in alpha state, so expect major new features!
<p align="center">
:star2: Contributors and early adopters are welcome! :star2:
Contributors and early adopters are welcome!
</p>

## Concept
Expand Down Expand Up @@ -85,21 +85,25 @@ To be able to use the DEM on your PC, you need to have the following software in

## Installation

DEM is available in the [PyPI repository](https://pypi.org/project/axem-dem/). Install it with:
Use the following install script to get the latest version of DEM:
curl -fsSL 'https://raw.githubusercontent.com/axem-solutions/dem/main/install-dem.sh' | bash

### Alternative installation

If all the prerequisites are fulfilled, the DEM can be installed from the
[PyPI repository](https://pypi.org/project/axem-dem/):

pip install axem-dem

:information_source: The package name is axem-dem, but the command is `dem`.

### Enable autocompletion

You can also install it with install-dem.sh from our repository. The installer script checks if the corresponding python version is available and installs the docker and axem-dem pip module.
Download it with the following command:
After installation, you can enable the autocompletion for bash and zsh shells

curl 'https://raw.githubusercontent.com/axem-solutions/dem/main/install-dem.sh' > install-dem.sh

Then execute it:
dem --install-completion

./install-dem.sh
> Note for zsh users: `compinit` must be called from your .zshrc.
## Quick start

Expand Down
8 changes: 6 additions & 2 deletions dem/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@

from dem import __command__
from dem.cli.console import stderr, stdout
from dem.core.exceptions import RegistryError, ContainerEngineError
from dem.core.exceptions import RegistryError, ContainerEngineError, InternalError
import dem.cli.main
import docker.errors
from dem.core.core import Core
from dem.core.platform import DevEnvLocalSetup
from dem.cli.tui.tui_user_output import TUIUserOutput

def main():
""" Entry point for the CLI application"""

# Create the Development Platform
dem.cli.main.platform = DevEnvLocalSetup()

# Connect the UI to the user output interface
Core.set_user_output(TUIUserOutput())

Expand All @@ -30,7 +34,7 @@ def main():
stdout.print("\nHint: The input repository might not exist in the registry.")
elif "400" in str(e):
stdout.print("\nHint: The input parameters might not be valid.")
except ContainerEngineError as e:
except (ContainerEngineError, InternalError) as e:
stderr.print("[red]" + str(e) + "[/]")

# Call the main() when run as `python -m`
Expand Down
4 changes: 2 additions & 2 deletions dem/cli/command/add_cat_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from dem.core.platform import DevEnvLocalSetup
from dem.cli.console import stdout

def execute(name: str, url:str) -> None:
def execute(platform: DevEnvLocalSetup, name: str, url:str) -> None:
""" Add a new Dev Env Catalog.
Args:
name -- name of the catalog
url -- URL of the catalog's JSON file
"""
platform = DevEnvLocalSetup()

catalog_config = {
"name": name,
"url": url
Expand Down
8 changes: 2 additions & 6 deletions dem/cli/command/add_host_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@

from dem.core.platform import DevEnvLocalSetup
from dem.cli.console import stdout
import json
import os

def execute(name: str, address: str) -> None:
def execute(platform: DevEnvLocalSetup, name: str, address: str) -> None:
""" Add a new host.
Args:
name -- name of the host
address -- IP or hostname of the host
"""

if not name or not address:
stdout.print("[red]Error: NAME or ADDRESS cannot be empty.[/]")
exit(1)

platform = DevEnvLocalSetup()
data = platform.config_file.deserialized.get("hosts", []) # this way the data object is a list
data = platform.config_file.deserialized.get("hosts", [])

if not data:
platform.config_file.deserialized["hosts"] = [{"name": name, "address": address}]
Expand Down
4 changes: 2 additions & 2 deletions dem/cli/command/add_reg_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from dem.core.platform import DevEnvLocalSetup
from dem.cli.console import stdout

def execute(name: str, url:str) -> None:
def execute(platform: DevEnvLocalSetup, name: str, url:str) -> None:
""" Add a new registry.
Args:
name -- name or IP address of the registry
url -- API URL of the registry
"""
platform = DevEnvLocalSetup()

registry = {
"name": name,
"url": url
Expand Down
3 changes: 1 addition & 2 deletions dem/cli/command/cp_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def cp_given_dev_env(platform: DevEnvLocalSetup, dev_env_to_cp: DevEnv,
platform.local_dev_envs.append(new_dev_env)
platform.flush_to_file()

def execute(dev_env_to_cp_name: str, new_dev_env_name: str) -> None:
platform = DevEnvLocalSetup()
def execute(platform: DevEnvLocalSetup, dev_env_to_cp_name: str, new_dev_env_name: str) -> None:
dev_env_to_cp = get_dev_env_to_cp(platform, dev_env_to_cp_name)

if (dev_env_to_cp is not None and
Expand Down
3 changes: 1 addition & 2 deletions dem/cli/command/create_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ def create_dev_env(platform: DevEnvLocalSetup, dev_env_name: str) -> DevEnv:

return new_dev_env

def execute(dev_env_name: str) -> None:
platform = DevEnvLocalSetup()
def execute(platform: DevEnvLocalSetup, dev_env_name: str) -> None:
dev_env = create_dev_env(platform, dev_env_name)

# Validate the Dev Env creation
Expand Down
4 changes: 1 addition & 3 deletions dem/cli/command/del_cat_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
from dem.core.platform import DevEnvLocalSetup
from dem.cli.console import stdout, stderr

def execute(catalog_name: str) -> None:
def execute(platform: DevEnvLocalSetup, catalog_name: str) -> None:
""" Delete the Dev Env Catalog.
Args:
catalog_name -- name of the catalog to delete
"""
platform = DevEnvLocalSetup()

for catalog_config in platform.dev_env_catalogs.list_catalog_configs():
if catalog_config["name"] == catalog_name:
platform.dev_env_catalogs.delete_catalog(catalog_config)
Expand Down
4 changes: 1 addition & 3 deletions dem/cli/command/del_reg_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
from dem.core.platform import DevEnvLocalSetup
from dem.cli.console import stdout, stderr

def execute(registry_name: str) -> None:
def execute(platform: DevEnvLocalSetup, registry_name: str) -> None:
""" Delete the registry.
Args:
registry_name -- name of the registry to delete
"""
platform = DevEnvLocalSetup()

for registry in platform.registries.list_registry_configs():
if registry["name"] == registry_name:
platform.registries.delete_registry(registry)
Expand Down
3 changes: 1 addition & 2 deletions dem/cli/command/delete_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def remove_unused_tool_images(deleted_dev_env: DevEnv, dev_env_local_setup: DevE
if tool_image not in all_required_tool_images:
try_to_delete_tool_image(tool_image, dev_env_local_setup)

def execute(dev_env_name: str) -> None:
platform = DevEnvLocalSetup()
def execute(platform: DevEnvLocalSetup, dev_env_name: str) -> None:
dev_env_to_delete = platform.get_dev_env_by_name(dev_env_name)

if dev_env_to_delete is None:
Expand Down
9 changes: 4 additions & 5 deletions dem/cli/command/export_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import json, os

def check_is_directory(param: str):
if None != param:
if "" != param:
return(os.path.isdir(param))
else:
return False

def check_is_path_contains_spec_char(param: str):
special_chars=re.compile('[~/\^]')
if None != param:
if "" != param:
if None != special_chars.search(param):
return True
else:
Expand All @@ -34,7 +34,7 @@ def create_exported_dev_env_json(dev_env_name: str,dev_env_json: str,given_path:
elif True == check_is_path_contains_spec_char(given_path):
file_name=""
file_path=given_path
elif None != given_path:
elif "" != given_path:
file_name=given_path
file_path=""
else:
Expand All @@ -45,8 +45,7 @@ def create_exported_dev_env_json(dev_env_name: str,dev_env_json: str,given_path:
json.dump(dev_env_json, exported_file, indent=4)
exported_file.close()

def execute(dev_env_name: str, path_to_export: str) -> None:
platform = DevEnvLocalSetup()
def execute(platform: DevEnvLocalSetup, dev_env_name: str, path_to_export: str) -> None:
dev_env_to_export = platform.get_dev_env_by_name(dev_env_name)
if dev_env_to_export is not None:
try:
Expand Down
3 changes: 1 addition & 2 deletions dem/cli/command/info_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def print_info(dev_env: (DevEnv | DevEnv)) -> None:
image_status_messages[tool["image_status"]])
stdout.print(tool_info_table)

def execute(arg_dev_env_name: str) -> None:
platform = DevEnvLocalSetup()
def execute(platform: DevEnvLocalSetup, arg_dev_env_name: str) -> None:
dev_env = platform.get_dev_env_by_name(arg_dev_env_name)

if dev_env is None:
Expand Down
3 changes: 1 addition & 2 deletions dem/cli/command/list_cat_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from dem.cli.console import stdout
from rich.table import Table

def execute() -> None:
def execute(platform: DevEnvLocalSetup) -> None:
""" List available Development Environment Catalogs."""
platform = DevEnvLocalSetup()
catalog_config = None
table = Table()
table.add_column("name")
Expand Down
3 changes: 1 addition & 2 deletions dem/cli/command/list_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def list_tool_images(platform: DevEnvLocalSetup, local: bool, org: bool) -> None
else:
stdout.print("[yellow]No images are available in the registries!")

def execute(local: bool, org: bool, env: bool, tool: bool) -> None:
platform = DevEnvLocalSetup()
def execute(platform: DevEnvLocalSetup, local: bool, org: bool, env: bool, tool: bool) -> None:
if ((local == True) or (org == True)) and (env == True) and (tool == False):
list_dev_envs(platform, local, org)
elif ((local == True) or (org == True)) and (env == False) and (tool == True):
Expand Down
3 changes: 1 addition & 2 deletions dem/cli/command/list_reg_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from dem.cli.console import stdout
from rich.table import Table

def execute() -> None:
def execute(platform: DevEnvLocalSetup) -> None:
""" List available registries."""
platform = DevEnvLocalSetup()
registry = None
table = Table()
table.add_column("name")
Expand Down
4 changes: 1 addition & 3 deletions dem/cli/command/load_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def load_dev_env_to_dev_env_json(dev_env_local_setup: DevEnvLocalSetup,path_to_d
raw_file.close()
return True

def execute(path_to_dev_env: str) -> None:
platform = DevEnvLocalSetup()

def execute(platform: DevEnvLocalSetup, path_to_dev_env: str) -> None:
if check_is_file_exist(path_to_dev_env) is True:
retval = load_dev_env_to_dev_env_json(platform,path_to_dev_env)
if retval == True:
Expand Down
3 changes: 1 addition & 2 deletions dem/cli/command/modify_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ def handle_user_confirm(confirmation: str, dev_env_local: DevEnv,
dev_env_local_setup.pull_images(dev_env_local.tools)


def execute(dev_env_name: str) -> None:
platform = DevEnvLocalSetup()
def execute(platform: DevEnvLocalSetup, dev_env_name: str) -> None:
dev_env_local = platform.get_dev_env_by_name(dev_env_name)

if dev_env_local is None:
Expand Down
4 changes: 1 addition & 3 deletions dem/cli/command/pull_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def install_to_dev_env_json(local_dev_env: DevEnv | None, catalog_dev_env: DevEn

return local_dev_env

def execute(dev_env_name: str) -> None:
# Get the organization's Dev Env if available.
platform = DevEnvLocalSetup()
def execute(platform: DevEnvLocalSetup, dev_env_name: str) -> None:
catalog_dev_env: DevEnv | None = None

if not platform.dev_env_catalogs.catalogs:
Expand Down
3 changes: 1 addition & 2 deletions dem/cli/command/rename_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from dem.core.platform import DevEnvLocalSetup
from dem.cli.console import stderr

def execute(dev_env_name_to_rename: str, new_dev_env_name: str) -> None:
platform = DevEnvLocalSetup()
def execute(platform: DevEnvLocalSetup, dev_env_name_to_rename: str, new_dev_env_name: str) -> None:
dev_env_to_rename = platform.get_dev_env_by_name(dev_env_name_to_rename)

if dev_env_to_rename is not None:
Expand Down
4 changes: 2 additions & 2 deletions dem/cli/command/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def handle_missing_tool_images(missing_tool_images: set[str], dev_env_local: Dev
platform.pull_images(dev_env_local.tools)
stdout.print("[green]DEM fixed the " + dev_env_local.name + "![/]")

def execute(dev_env_name: str, container_arguments: list[str]) -> None:
def execute(platform: DevEnvLocalSetup, dev_env_name: str, container_arguments: list[str]) -> None:
""" Execute the run command in the given Dev Env context. If something is wrong with the Dev
Env the DEM can try to fix it.
Args:
dev_env_name -- name of the Development Environment
container_arguments -- arguments passed to the container
"""
platform = DevEnvLocalSetup()

dev_env_local = platform.get_dev_env_by_name(dev_env_name)

if dev_env_local is None:
Expand Down
Loading

0 comments on commit 958863c

Please sign in to comment.