Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.cmdline
Commits
76283061
Commit
76283061
authored
Oct 18, 2019
by
Samuel GAIST
Browse files
[dataformats] Port to AssetCommand and implent dependency handling for push
parent
dac5b8ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
beat/cmdline/dataformats.py
View file @
76283061
...
...
@@ -39,12 +39,15 @@ import click
from
beat.core
import
dataformat
from
beat.backend.python.dataformat
import
DataFormat
from
.
import
common
from
.
import
commands
from
.decorators
import
raise_on_error
from
.click_helper
import
AliasedGroup
from
.click_helper
import
AssetCommand
from
.click_helper
import
AssetInfo
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -130,14 +133,33 @@ def pull_impl(webapi, prefix, names, force, indentation, cache):
return
pull_impl
(
webapi
,
prefix
,
dataformats
,
force
,
2
+
indentation
,
cache
)
def
get_dependencies
(
ctx
,
asset_name
):
prefix
=
ctx
.
meta
[
"config"
].
path
df
=
DataFormat
(
prefix
,
asset_name
)
dependencies
=
{}
dataformats
=
list
(
df
.
referenced
.
keys
())
if
dataformats
:
dependencies
[
"dataformats"
]
=
dataformats
return
dependencies
class
DataformatCommand
(
AssetCommand
):
asset_info
=
AssetInfo
(
asset_type
=
"dataformat"
,
diff_fields
=
[
"declaration"
,
"description"
],
push_fields
=
[
"name"
,
"declaration"
,
"description"
],
get_dependencies
=
get_dependencies
,
)
@
click
.
group
(
cls
=
AliasedGroup
)
@
click
.
pass_context
def
dataformats
(
ctx
):
"""Configuration manipulation of data formats"""
ctx
.
meta
[
"asset_type"
]
=
"dataformat"
ctx
.
meta
[
"diff_fields"
]
=
[
"declaration"
,
"description"
]
CMD_LIST
=
[
"list"
,
...
...
@@ -150,9 +172,11 @@ CMD_LIST = [
"fork"
,
"rm"
,
"diff"
,
"push"
,
]
commands
.
initialise_asset_commands
(
dataformats
,
CMD_LIST
)
commands
.
initialise_asset_commands
(
dataformats
,
CMD_LIST
,
DataformatCommand
)
@
dataformats
.
command
()
...
...
@@ -173,35 +197,3 @@ def pull(ctx, name, force):
if
name
is
None
:
return
1
# error
return
pull_impl
(
webapi
,
ctx
.
meta
[
"config"
].
path
,
name
,
force
,
0
,
{})
@
dataformats
.
command
()
@
click
.
argument
(
"name"
,
nargs
=-
1
)
@
click
.
option
(
"--force"
,
help
=
"Performs operation regardless of conflicts"
,
is_flag
=
True
)
@
click
.
option
(
"--dry-run"
,
help
=
"Doesn't really perform the task, just "
"comments what would do"
,
is_flag
=
True
,
)
@
click
.
pass_context
@
raise_on_error
def
push
(
ctx
,
name
,
force
,
dry_run
):
"""Uploads dataformats to the server
Example:
$ beat dataformats push --dry-run yyy
"""
with
common
.
make_webapi
(
ctx
.
meta
[
"config"
])
as
webapi
:
return
common
.
push
(
webapi
,
ctx
.
meta
[
"config"
].
path
,
"dataformat"
,
name
,
[
"name"
,
"declaration"
,
"description"
],
{},
force
,
dry_run
,
0
,
)
beat/cmdline/test/test_dataformats.py
View file @
76283061
...
...
@@ -50,6 +50,8 @@ class TestOnlineDataformats(core.OnlineAssetTestCase):
"pull"
:
"system/bounding_box_video/1"
,
"diff"
:
"system/integer/1"
,
"create"
:
"user/newobject/1"
,
"push"
:
"user/composed/1"
,
"not_owner_push"
:
"system/chart/1"
,
}
def
_modify_asset
(
self
,
asset_name
):
...
...
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