Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
cd205446
Unverified
Commit
cd205446
authored
Jan 08, 2025
by
Jakob Görgen
Browse files
symphony/cli: reduced code duplication by using generic table print method
parent
b2696fc5
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
89 deletions
+32
-89
symphony/cli/simbricks/cli/commands/admin.py
symphony/cli/simbricks/cli/commands/admin.py
+5
-6
symphony/cli/simbricks/cli/commands/instantiations.py
symphony/cli/simbricks/cli/commands/instantiations.py
+3
-3
symphony/cli/simbricks/cli/commands/namespaces.py
symphony/cli/simbricks/cli/commands/namespaces.py
+5
-7
symphony/cli/simbricks/cli/commands/runners.py
symphony/cli/simbricks/cli/commands/runners.py
+8
-6
symphony/cli/simbricks/cli/commands/simulations.py
symphony/cli/simbricks/cli/commands/simulations.py
+3
-3
symphony/cli/simbricks/cli/commands/systems.py
symphony/cli/simbricks/cli/commands/systems.py
+4
-4
symphony/cli/simbricks/cli/utils.py
symphony/cli/simbricks/cli/utils.py
+4
-60
No files found.
symphony/cli/simbricks/cli/commands/admin.py
View file @
cd205446
...
...
@@ -23,7 +23,7 @@
from
typer
import
Typer
,
Option
from
typing_extensions
import
Annotated
from
simbricks.client.provider
import
client_provider
from
..utils
import
async_cli
,
print_
namespace_table
from
..utils
import
async_cli
,
print_
table_generic
app
=
Typer
(
help
=
"SimBricks admin commands."
)
...
...
@@ -34,7 +34,7 @@ async def ns_ls():
"""List all available namespaces."""
client
=
client_provider
.
admin_client
namespaces
=
await
client
.
get_all_ns
()
print_
n
amespace
_table
(
namespaces
)
print_
table_generic
(
"N
amespace
s"
,
namespaces
,
"id"
,
"name"
,
"parent_id"
)
@
app
.
command
()
...
...
@@ -43,7 +43,7 @@ async def ns_ls_id(ident: int):
"""List namespace with given id ident."""
client
=
client_provider
.
admin_client
namespace
=
await
client
.
get_ns
(
ns_id
=
ident
)
print_
n
amespace
_table
(
[
namespace
])
print_
table_generic
(
"N
amespace
"
,
[
namespace
]
,
"id"
,
"name"
,
"parent_id"
)
@
app
.
command
()
...
...
@@ -52,9 +52,8 @@ async def ns_create(name: str, parent_id: Annotated[int, Option(help="optional p
"""Create a new namespace."""
client
=
client_provider
.
admin_client
namespace
=
await
client
.
create_ns
(
parent_id
=
parent_id
,
name
=
name
)
ns_id
=
namespace
[
"id"
]
print
(
f
"Creating namespace
{
name
}
in
{
client_provider
.
namespace
}
. New namespace:
{
ns_id
}
"
)
print_table_generic
(
"Namespace"
,
[
namespace
],
"id"
,
"name"
,
"parent_id"
)
@
app
.
command
()
@
async_cli
()
...
...
symphony/cli/simbricks/cli/commands/instantiations.py
View file @
cd205446
...
...
@@ -23,7 +23,7 @@
from
typer
import
Typer
from
simbricks.client.provider
import
client_provider
from
..utils
import
async_cli
from
..utils
import
print_
instantiations_table
from
..utils
import
print_
table_generic
app
=
Typer
(
help
=
"Managing SimBricks Instantiations."
)
...
...
@@ -33,7 +33,7 @@ app = Typer(help="Managing SimBricks Instantiations.")
async
def
ls
():
"""List Instantiations."""
insts
=
await
client_provider
.
simbricks_client
.
get_instantiations
()
print_
instantiations_table
(
insts
)
print_
table_generic
(
"Instantiations"
,
insts
,
"id"
,
"simulation_id"
)
@
app
.
command
()
...
...
@@ -41,7 +41,7 @@ async def ls():
async
def
show
(
inst_id
:
int
):
"""Show individual Instantiation."""
inst
=
await
client_provider
.
simbricks_client
.
get_instantiation
(
instantiation_id
=
inst_id
)
print_
instantiations_table
([
inst
]
)
print_
table_generic
(
"Instantiations"
,
[
inst
],
"id"
,
"simulation_id"
)
@
app
.
command
()
...
...
symphony/cli/simbricks/cli/commands/namespaces.py
View file @
cd205446
...
...
@@ -22,7 +22,7 @@
from
typer
import
Typer
from
simbricks.client.provider
import
client_provider
from
..utils
import
async_cli
,
print_
namespace_table
,
print_members_table
from
..utils
import
async_cli
,
print_
table_generic
,
print_members_table
app
=
Typer
(
help
=
"Managing SimBricks namespaces."
)
...
...
@@ -34,7 +34,7 @@ async def ls():
client
=
client_provider
.
ns_client
namespaces
=
await
client
.
get_all
()
print_
n
amespace
_table
(
namespaces
)
print_
table_generic
(
"N
amespace
s"
,
namespaces
,
"id"
,
"name"
,
"parent_id"
)
@
app
.
command
()
...
...
@@ -44,7 +44,7 @@ async def ls_id(ident: int):
client
=
client_provider
.
ns_client
namespace
=
await
client
.
get_ns
(
ident
)
print_
n
amespace
_table
(
[
namespace
])
print_
table_generic
(
"N
amespace
"
,
[
namespace
]
,
"id"
,
"name"
,
"parent_id"
)
@
app
.
command
()
...
...
@@ -54,7 +54,7 @@ async def ls_cur():
client
=
client_provider
.
ns_client
namespace
=
await
client
.
get_cur
()
print_
n
amespace
_table
(
[
namespace
])
print_
table_generic
(
"N
amespace
"
,
[
namespace
]
,
"id"
,
"name"
,
"parent_id"
)
@
app
.
command
()
...
...
@@ -70,9 +70,7 @@ async def create(name: str):
# create the actual namespace
namespace
=
await
client
.
create
(
parent_id
=
cur_ns_id
,
name
=
name
)
ns_id
=
namespace
[
"id"
]
print
(
f
"Creating namespace
{
name
}
in
{
client_provider
.
namespace
}
. New namespace:
{
ns_id
}
"
)
print_table_generic
(
"Namespace"
,
[
namespace
],
"id"
,
"name"
,
"parent_id"
)
@
app
.
command
()
...
...
symphony/cli/simbricks/cli/commands/runners.py
View file @
cd205446
...
...
@@ -23,7 +23,7 @@
from
typer
import
Typer
,
Option
from
typing_extensions
import
Annotated
from
simbricks.client.provider
import
client_provider
from
..utils
import
async_cli
,
print_runner_table
,
print_table_generic
from
..utils
import
async_cli
,
print_table_generic
app
=
Typer
(
help
=
"Managing SimBricks runners."
)
...
...
@@ -33,8 +33,8 @@ app = Typer(help="Managing SimBricks runners.")
@
async_cli
()
async
def
ls
():
"""List runners."""
runs
=
await
client_provider
.
runner_client
.
list_runners
()
print_
runner_table
(
runs
)
run
ner
s
=
await
client_provider
.
runner_client
.
list_runners
()
print_
table_generic
(
"Runners"
,
runners
,
"id"
,
"label"
,
"tags"
)
@
app
.
command
()
...
...
@@ -42,7 +42,7 @@ async def ls():
async
def
show
(
runner_id
:
int
):
"""Show individual runner."""
runner
=
await
client_provider
.
runner_client
.
get_runner
(
runner_id
=
runner_id
)
print_
runner_table
([
runner
]
)
print_
table_generic
(
"Runners"
,
[
runner
],
"id"
,
"label"
,
"tags"
)
@
app
.
command
()
...
...
@@ -57,7 +57,7 @@ async def delete(runner_id: int):
async
def
create
(
label
:
str
,
tags
:
list
[
str
]):
"""Update a runner with the the given label and tags."""
runner
=
await
client_provider
.
runner_client
.
create_runner
(
label
=
label
,
tags
=
tags
)
print_
runner_table
([
runner
]
)
print_
table_generic
(
"Runner"
,
[
runner
],
"id"
,
"label"
,
"tags"
)
@
app
.
command
()
...
...
@@ -106,5 +106,7 @@ async def ls_events(
limit
:
Annotated
[
int
|
None
,
Option
(
"--limit"
,
"-l"
,
help
=
"Limit results."
)]
=
None
,
):
"""List runner related events"""
events
=
await
client_provider
.
runner_client
.
get_events
(
action
=
action
,
run_id
=
run_id
,
event_status
=
event_status
,
limit
=
limit
)
events
=
await
client_provider
.
runner_client
.
get_events
(
action
=
action
,
run_id
=
run_id
,
event_status
=
event_status
,
limit
=
limit
)
print_table_generic
(
"Events"
,
events
,
"id"
,
"runner_id"
,
"action"
,
"run_id"
,
"event_status"
)
symphony/cli/simbricks/cli/commands/simulations.py
View file @
cd205446
...
...
@@ -23,7 +23,7 @@
from
typer
import
Typer
from
simbricks.client.provider
import
client_provider
from
..utils
import
async_cli
from
..utils
import
print_
simulations_table
from
..utils
import
print_
table_generic
app
=
Typer
(
help
=
"Managing SimBricks Simulations."
)
...
...
@@ -33,7 +33,7 @@ app = Typer(help="Managing SimBricks Simulations.")
async
def
ls
():
"""List Simulations."""
simulations
=
await
client_provider
.
simbricks_client
.
get_simulations
()
print_
s
imulations
_table
(
simulations
)
print_
table_generic
(
"S
imulations
"
,
simulations
,
"id"
,
"system_id"
)
@
app
.
command
()
...
...
@@ -41,7 +41,7 @@ async def ls():
async
def
show
(
sim_id
:
int
):
"""Show individual Simulation."""
sim
=
await
client_provider
.
simbricks_client
.
get_simulation
(
simulation_id
=
sim_id
)
print_
simulations_table
([
sim
]
)
print_
table_generic
(
"Simulation"
,
[
sim
],
"id"
,
"system_id"
)
@
app
.
command
()
...
...
symphony/cli/simbricks/cli/commands/systems.py
View file @
cd205446
...
...
@@ -23,7 +23,7 @@
from
typer
import
Typer
from
simbricks.client.provider
import
client_provider
from
..utils
import
async_cli
from
..utils
import
print_
systems_table
from
..utils
import
print_
table_generic
app
=
Typer
(
help
=
"Managing SimBricks Systems."
)
...
...
@@ -33,15 +33,15 @@ app = Typer(help="Managing SimBricks Systems.")
async
def
ls
():
"""List Systems."""
systems
=
await
client_provider
.
simbricks_client
.
get_systems
()
print_
systems_table
(
s
ystems
=
systems
)
print_
table_generic
(
"S
ystems
"
,
systems
,
"id"
)
@
app
.
command
()
@
async_cli
()
async
def
show
(
system_id
:
int
):
"""Show individual System."""
run
=
await
client_provider
.
simbricks_client
.
get_system
(
system_id
=
system_id
)
print_
systems_table
([
run
]
)
system
=
await
client_provider
.
simbricks_client
.
get_system
(
system_id
=
system_id
)
print_
table_generic
(
"Systems"
,
[
system
],
"id"
)
@
app
.
command
()
...
...
symphony/cli/simbricks/cli/utils.py
View file @
cd205446
...
...
@@ -41,12 +41,13 @@ def async_cli():
return
decorator_async_cli
def
print_table_generic
(
title
:
str
,
to_print
,
*
args
):
table
=
Table
(
title
=
title
)
for
key
in
args
:
table
.
add_column
(
key
)
for
val
in
to_print
:
row
=
[
str
(
val
[
key
])
for
key
in
args
]
table
.
add_row
(
*
row
)
...
...
@@ -54,63 +55,6 @@ def print_table_generic(title: str, to_print, *args):
console
=
Console
()
console
.
print
(
table
)
def
print_namespace_table
(
namespaces
)
->
None
:
table
=
Table
()
table
.
add_column
(
"Id"
)
table
.
add_column
(
"name"
)
table
.
add_column
(
"parent"
)
for
ns
in
namespaces
:
table
.
add_row
(
str
(
ns
[
"id"
]),
str
(
ns
[
"name"
]),
str
(
ns
[
"parent_id"
]))
console
=
Console
()
console
.
print
(
table
)
def
print_systems_table
(
systems
):
table
=
Table
()
table
.
add_column
(
"Id"
)
for
sys
in
systems
:
table
.
add_row
(
str
(
sys
[
"id"
]))
console
=
Console
()
console
.
print
(
table
)
def
print_simulations_table
(
instantiations
):
table
=
Table
()
table
.
add_column
(
"Id"
)
table
.
add_column
(
"SystemId"
)
for
sys
in
instantiations
:
table
.
add_row
(
str
(
sys
[
"id"
]),
str
(
sys
[
"system_id"
]))
console
=
Console
()
console
.
print
(
table
)
def
print_instantiations_table
(
instantiations
):
table
=
Table
()
table
.
add_column
(
"Id"
)
table
.
add_column
(
"SimulationId"
)
for
sys
in
instantiations
:
table
.
add_row
(
str
(
sys
[
"id"
]),
str
(
sys
[
"simulation_id"
]))
console
=
Console
()
console
.
print
(
table
)
def
print_runner_table
(
runners
):
table
=
Table
()
table
.
add_column
(
"Id"
)
table
.
add_column
(
"Label"
)
table
.
add_column
(
"Tags"
)
for
r
in
runners
:
ts
=
[]
for
t
in
r
[
"tags"
]:
ts
.
append
(
t
[
"label"
])
table
.
add_row
(
str
(
r
[
"id"
]),
str
(
r
[
"label"
]),
","
.
join
(
ts
))
console
=
Console
()
console
.
print
(
table
)
def
print_members_table
(
members
:
dict
[
str
,
list
[
dict
]]):
table
=
Table
()
...
...
@@ -120,6 +64,6 @@ def print_members_table(members: dict[str, list[dict]]):
table
.
add_column
(
"Last"
)
for
r
,
ms
in
members
.
items
():
for
m
in
ms
:
table
.
add_row
(
r
,
m
[
'
username
'
],
m
[
'
first_name
'
],
m
[
'
last_name
'
])
table
.
add_row
(
r
,
m
[
"
username
"
],
m
[
"
first_name
"
],
m
[
"
last_name
"
])
console
=
Console
()
console
.
print
(
table
)
\ No newline at end of file
console
.
print
(
table
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment