Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Update abstra-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
abstra-bot committed Mar 7, 2023
1 parent 4a0cb44 commit 62490c5
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 21 deletions.
2 changes: 1 addition & 1 deletion abstra_cli/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
from .packages import *
from .public import *
from .dashes import *
from .subdomains import *
from .subdomains import *
2 changes: 0 additions & 2 deletions abstra_cli/apis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,3 @@ def hf_hasura_runner(query, variables={}):
return jsond["data"]

raise Exception(jsond["errors"])


3 changes: 1 addition & 2 deletions abstra_cli/apis/subdomains.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def get_subdomain():

return subdomains[0]["name"]


def update_subdomain(old_name, new_name):
query = """
mutation UpdateSubdomain($old_name: String!, $new_name: String!) {
Expand All @@ -32,5 +33,3 @@ def update_subdomain(old_name, new_name):
.get("update_subdomains", {})
.get("returning", [])
)


11 changes: 10 additions & 1 deletion abstra_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
import abstra_cli.messages as messages
import abstra_cli.decorators as decorators
import abstra_cli.credentials as credentials
from abstra_cli.resources import Forms, Files, Packages, Vars, Hooks, Jobs, Dashes, Subdomains
from abstra_cli.resources import (
Forms,
Files,
Packages,
Vars,
Hooks,
Jobs,
Dashes,
Subdomains,
)


class CLI(object):
Expand Down
16 changes: 12 additions & 4 deletions abstra_cli/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ def deploy(**kwargs):
Files.add(dashes_root_path)

remote_dashes_files = Files.list_dashes_files(dashes_root_path)
local_dashes_files = [d["code"].replace(".py", ".abstradash.json") for d in dashes]
deleted_dashes_files = [f for f in remote_dashes_files if f not in local_dashes_files]
local_dashes_files = [
d["code"].replace(".py", ".abstradash.json") for d in dashes
]
deleted_dashes_files = [
f for f in remote_dashes_files if f not in local_dashes_files
]

for deleted_dash_file in deleted_dashes_files:
deleted_dash_path = deleted_dash_file.replace(".abstradash.json", "").replace(f'{dashes_root_path}/', "")
deleted_dash_path = deleted_dash_file.replace(
".abstradash.json", ""
).replace(f"{dashes_root_path}/", "")
Dashes.remove(deleted_dash_path)
Files.remove(deleted_dash_file, deleted_dash_file.replace(".abstradash.json", ".py"))
Files.remove(
deleted_dash_file, deleted_dash_file.replace(".abstradash.json", ".py")
)

forms = deploy_data.pop("forms", None)
if forms:
Expand Down
1 change: 1 addition & 0 deletions abstra_cli/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def print_jobs(jobs):
f"{utils.format_digits(j['identifier'], max_idt)} - {utils.format_digits(j['schedule'], max_schedule)} - {utils.format_digits(j['title'], max_title)} ({enabled})"
)


def print_subdomains(subdomain):
print(f"workspace subdomain: {subdomain}")

Expand Down
2 changes: 1 addition & 1 deletion abstra_cli/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .packages import Packages
from .resources import Resource
from .dashes import Dashes
from .subdomains import Subdomains
from .subdomains import Subdomains
7 changes: 6 additions & 1 deletion abstra_cli/resources/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ def remove(*args, **kwargs):
@staticmethod
def list_dashes_files(dashes_root_path):
files = apis.list_workspace_files()
return [f['Key'] for f in files if f['Key'].startswith(f'{dashes_root_path}/') and f['Key'].endswith('.abstradash.json')]
return [
f["Key"]
for f in files
if f["Key"].startswith(f"{dashes_root_path}/")
and f["Key"].endswith(".abstradash.json")
]
23 changes: 14 additions & 9 deletions abstra_cli/resources/subdomains.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from abstra_cli.apis import get_subdomain, update_subdomain
import abstra_cli.messages as messages


class Subdomains(Resource):
@staticmethod
def list():
Expand All @@ -11,16 +12,20 @@ def list():
@staticmethod
def update(*args, **kwargs):
if not len(args):
messages.missing_parameters_to_update("name", "subdomain")
exit()
messages.missing_parameters_to_update("name", "subdomain")
exit()

new_subdomain = args[0]
old_subdomain = get_subdomain()
try:
updated_subdomain = update_subdomain(old_subdomain, new_subdomain)
messages.print_subdomains(updated_subdomain[0]['name'])
updated_subdomain = update_subdomain(old_subdomain, new_subdomain)
messages.print_subdomains(updated_subdomain[0]["name"])
except Exception as error:
if len(error.args) > 0 and len(error.args[0]) > 0 and error.args[0][0]['extensions']['code'] == 'constraint-violation':
messages.conflict_name('name', 'subdomain')
else:
messages.update_failed('subdomain')
if (
len(error.args) > 0
and len(error.args[0]) > 0
and error.args[0][0]["extensions"]["code"] == "constraint-violation"
):
messages.conflict_name("name", "subdomain")
else:
messages.update_failed("subdomain")

0 comments on commit 62490c5

Please sign in to comment.