~rjarry/dlrepo

dlrepo: format: add delete method v1 APPLIED

Julien Floret: 1
 format: add delete method

 5 files changed, 44 insertions(+), 8 deletions(-)
#1113271 .build.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rjarry/dlrepo/patches/47654/mbox | git am -3
Learn more about email & git

[PATCH dlrepo] format: add delete method Export this patch

It can be useful to delete a specific job format without deleting the
entire job. For example if there is a mistake in some additional
documentation or test result and we want to update it without
deleting and re-uploading the entire job.

Signed-off-by: Julien Floret <julien.floret@6wind.com>
Acked-by: Thomas Faivre <thomas.faivre@6wind.com>
---
 dlrepo-cli              | 17 +++++++++--------
 dlrepo/fs/fmt.py        |  5 +++++
 dlrepo/fs/job.py        |  1 +
 dlrepo/views/fmt.py     | 16 ++++++++++++++++
 docs/dlrepo-api.7.scdoc | 13 +++++++++++++
 5 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/dlrepo-cli b/dlrepo-cli
index 33f141b98201..dfea4b5865eb 100755
--- a/dlrepo-cli
+++ b/dlrepo-cli
@@ -487,21 +487,22 @@ def internal(args):
    Arg("branch", metavar="BRANCH", help="the branch name"),
    Arg("tag", metavar="TAG", nargs="?", help="the tag name"),
    Arg("job", metavar="JOB", nargs="?", help="the job name"),
    Arg("format", metavar="FORMAT", nargs="?", help="the artifact format"),
)
def delete(args):
    """
    Delete a job, a tag or a branch and all its tags recursively.
    Delete a branch, a tag, a job or a format.
    """
    client = HttpClient(args.url)
    params = {}
    url = os.path.join("branches", args.branch)
    if args.tag:
        if args.job:
            url = os.path.join("branches", args.branch, args.tag, args.job) + "/"
        else:
            url = os.path.join("branches", args.branch, args.tag) + "/"
    else:
        url = os.path.join("branches", args.branch) + "/"
    client.delete(url, params)
        url = os.path.join(url, args.tag)
    if args.job:
        url = os.path.join(url, args.job)
    if args.format:
        url = os.path.join(url, args.format)
    client.delete(url + "/", params)


# --------------------------------------------------------------------------------------
diff --git a/dlrepo/fs/fmt.py b/dlrepo/fs/fmt.py
index 487bff1d4c7e..bfa001a15082 100644
--- a/dlrepo/fs/fmt.py
+++ b/dlrepo/fs/fmt.py
@@ -229,3 +229,8 @@ class ArtifactFormat(SubDir):
                os.link(fpath, blob)

        self.digest_path().write_text(json.dumps(new_digests, sort_keys=True))

    def delete(self):
        if not self.exists():
            raise FileNotFoundError()
        self.root().rmtree(self._path)
diff --git a/dlrepo/fs/job.py b/dlrepo/fs/job.py
index c2884399d25e..833fdc941809 100644
--- a/dlrepo/fs/job.py
+++ b/dlrepo/fs/job.py
@@ -117,6 +117,7 @@ class Job(SubDir):
            if not d.is_symlink():
                continue
            if not d.is_dir():
                d.unlink()
                continue
            try:
                if d.resolve().samefile(self.path() / d.name):
diff --git a/dlrepo/views/fmt.py b/dlrepo/views/fmt.py
index 5378cb9e8016..33876764141c 100644
--- a/dlrepo/views/fmt.py
+++ b/dlrepo/views/fmt.py
@@ -2,6 +2,7 @@
# Copyright (c) 2021 Robin Jarry
# SPDX-License-Identifier: BSD-3-Clause

import asyncio
import logging
from typing import Callable

@@ -71,6 +72,21 @@ class FormatDirView(BaseView):
            raise web.HTTPInternalServerError(reason="post process failed") from e
        return web.Response()

    async def delete(self):
        """
        Delete a format.
        """
        loop = asyncio.get_running_loop()
        try:
            fmt = _get_format(self.repo(), self.request.match_info)
            await loop.run_in_executor(None, fmt.delete)
            self.repo().schedule_cleanup_orphans()
        except FileNotFoundError as e:
            raise web.HTTPNotFound() from e
        except OSError as e:
            raise web.HTTPBadRequest(reason=str(e)) from e
        return web.Response()


# --------------------------------------------------------------------------------------
class FormatArchiveView(BaseView):
diff --git a/docs/dlrepo-api.7.scdoc b/docs/dlrepo-api.7.scdoc
index d8eeabf388a1..f76e710acd36 100644
--- a/docs/dlrepo-api.7.scdoc
+++ b/docs/dlrepo-api.7.scdoc
@@ -428,6 +428,19 @@ Delete the specified _{job}_ and all its artifact formats.
	- _404_: the specified _{job}_ does not exist.
	- _405_: _{tag}_ is either _latest_, _stable_ or _oldstable_.

# ARTIFACT FORMATS

## DELETE /branches/{branch}/{tag}/{job}/{format}/
## DELETE /~{user}/branches/{branch}/{tag}/{job}/{format}/

Delete the specified artifact format.

*Access:*
	_d_
*Errors:*
	- _404_: the specified _{format}_ does not exist.
	- _405_: _{tag}_ is either _latest_, _stable_ or _oldstable_.

# PRODUCTS

## GET /products/
-- 
2.39.2
dlrepo/patches/.build.yml: SUCCESS in 1m49s

[format: add delete method][0] from [Julien Floret][1]

[0]: https://lists.sr.ht/~rjarry/dlrepo/patches/47654
[1]: mailto:julien.floret@6wind.com

✓ #1113271 SUCCESS dlrepo/patches/.build.yml https://builds.sr.ht/~rjarry/job/1113271
Julien Floret <julien.floret@6wind.com> wrote: