Skip to content

Commit

Permalink
CH-151 Refactor to clean up some loose ends
Browse files Browse the repository at this point in the history
  • Loading branch information
condar-metacell committed Oct 8, 2024
1 parent 90f8454 commit f5725a5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
3 changes: 3 additions & 0 deletions tools/deployment-cli-tools/ch_cli_tools/common_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class TemplateType(StrEnum):
DJANGO_APP = 'django-app'
SERVER = 'server'

def database_templates(self):
return [self.DB_POSTGRES, self.DB_NEO4J, self.DB_MONGO]


@dataclass
class CloudHarnessManifest():
Expand Down
20 changes: 17 additions & 3 deletions tools/deployment-cli-tools/harness-application
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ name_pattern = re.compile("[a-z]+((-)?[a-z])?")

PLACEHOLDER = '__APP_NAME__'

def main():
def main() -> None:
app_name, templates = get_command_line_arguments()

app_path = pathlib.Path(APPLICATIONS_SRC_PATH)/app_name
app_path.mkdir(exist_ok=True)

if TemplateType.DJANGO_APP in templates and TemplateType.WEBAPP not in templates:
templates = [TemplateType.BASE, TemplateType.WEBAPP, TemplateType.DB_POSTGRES] + templates
templates = normalize_templates(templates)

if TemplateType.WEBAPP in templates:
handle_webapp_template(app_name, app_path)
Expand Down Expand Up @@ -99,6 +98,21 @@ def get_command_line_arguments() -> tuple[str, list[str]]:
return args.name, args.templates


def normalize_templates(templates: list[str]) -> list[str]:
normalized_templates = list(templates)

if TemplateType.DJANGO_APP in normalized_templates and TemplateType.WEBAPP not in normalized_templates:
django_app_index = normalized_templates.index(TemplateType.DJANGO_APP)
normalized_templates.insert(django_app_index, TemplateType.WEBAPP)

has_database_template = any(template in TemplateType.database_templates() for template in normalized_templates)
if TemplateType.DJANGO_APP in normalize_templates and not has_database_template:
django_app_index = normalized_templates.index(TemplateType.DJANGO_APP)
normalized_templates.insert(django_app_index, TemplateType.DB_POSTGRES)

return normalized_templates


def handle_webapp_template(app_name: str, app_path: pathlib.Path) -> None:
frontend_path = app_path/'frontend'

Expand Down
37 changes: 18 additions & 19 deletions tools/deployment-cli-tools/harness-generate
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ from ch_cli_tools.utils import copymergedir, load_yaml, save_yaml
from ch_cli_tools.common_types import CloudHarnessManifest, TemplateType


def main():
args = get_command_line_arguments()
get_dependencies()

root_path = args.path.absolute()
should_generate = should_generate_interactive if args.is_interactive else lambda _: True

if args.generate_models:
generate_models(root_path, should_generate)

if args.generate_servers:
generate_servers(root_path, should_generate, args.app_name)

if args.generate_clients:
assert args.client_name is not None
generate_clients(root_path, should_generate, args.app_name, args.client_name, args.client_types)


class ClientType(enum.Flag):
TS_CLIENT = enum.auto()
PYTHON_CLIENT = enum.auto()
Expand Down Expand Up @@ -58,25 +76,6 @@ class CommandLineArguments:
return GenerationMode.CLIENTS in self.generation_mode


def main():
args = get_command_line_arguments()
get_dependencies()

root_path = args.path if args.path.is_absolute() else args.path.absolute()

should_generate = should_generate_interactive if args.is_interactive else lambda _: True

if args.generate_models:
generate_models(root_path, should_generate)

if args.generate_servers:
generate_servers(root_path, should_generate, args.app_name)

if args.generate_clients:
assert args.client_name is not None
generate_clients(root_path, should_generate, args.app_name, args.client_name, args.client_types)


def get_command_line_arguments() -> CommandLineArguments:
parser = argparse.ArgumentParser(description='Walk filesystem inside ./applications create application scaffolding.')

Expand Down

0 comments on commit f5725a5

Please sign in to comment.