Commit 1c7e3b26 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[libraries] Port to AssetCommand and implent dependency handling for push

parent 58b6641d
......@@ -78,11 +78,15 @@ import click
from beat.core import library
from beat.backend.python.library import Library
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__)
......@@ -164,14 +168,33 @@ def pull_impl(webapi, prefix, names, force, indentation, cache):
return pull_impl(webapi, prefix, libraries, force, indentation, cache)
def get_dependencies(ctx, asset_name):
prefix = ctx.meta["config"].path
lib = Library(prefix, asset_name)
dependencies = {}
libraries = list(lib.uses.values())
if libraries:
dependencies["libraries"] = libraries
return dependencies
class LibraryCommand(AssetCommand):
asset_info = AssetInfo(
asset_type="library",
diff_fields=["declaration", "code", "description"],
push_fields=["name", "declaration", "code", "description"],
get_dependencies=get_dependencies,
)
@click.group(cls=AliasedGroup)
@click.pass_context
def libraries(ctx):
"""Configuration and manipulation of libraries"""
ctx.meta["asset_type"] = "library"
ctx.meta["diff_fields"] = ["declaration", "code", "description"]
CMD_LIST = [
"list",
......@@ -184,9 +207,10 @@ CMD_LIST = [
"fork",
"rm",
"diff",
"push",
]
commands.initialise_asset_commands(libraries, CMD_LIST)
commands.initialise_asset_commands(libraries, CMD_LIST, LibraryCommand)
@libraries.command()
......@@ -204,35 +228,3 @@ def pull(ctx, names, force):
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return pull_impl(webapi, ctx.meta["config"].path, names, force, 0, {})
@libraries.command()
@click.argument("names", 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, names, force, dry_run):
"""Uploads libraries to the server
Example:
$ beat libraries push --dry-run yyy
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.push(
webapi,
ctx.meta["config"].path,
"library",
names,
["names", "declaration", "code", "description"],
{},
force,
dry_run,
0,
)
......@@ -62,6 +62,8 @@ class TestOnlineLibraries(core.OnlineAssetTestCase):
"pull": "plot/baselib/1",
"diff": "plot/baselib/1",
"create": "user/newobject/1",
"push": "user/nest1/1",
"not_owner_push": "errors/invalid_mix/1",
}
def _modify_asset(self, asset_name):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment