Gitlab Community Edition Instance

Commit c1d456e7 authored by mhellka's avatar mhellka
Browse files

Added scroll command

parent 111ac021
......@@ -358,6 +358,19 @@ class CDStar:
""" Remove a archive file. This cannot be undone. """
return self.raw("DELETE", vault, archive, file).ok
def scroll(self, vault, start="", limit=1024) -> JsonObject:
return"GET", vault, params={"scroll": start, "limit": limit})
def iter_scroll(self, vault, start="", limit=1024) -> typing.Iterator[JsonObject]:
while True:
page = self.scroll(vault, start=start, limit=limit)
if not page["results"]:
yield from page["results"]
start = page["results"][-1]
if page["count"] < page["limit"]:
def search(
self, vault, q, order=None, limit=0, scroll=None, groups=None
) -> JsonObject:
Scroll all IDs in a vault.
Scrolling requires the `list` vault permission. You can fall back on search-based
scrolling is that is not available.
def register(subparsers):
parser = subparsers.add_parser(
"scroll", help=__doc__.strip().splitlines()[0], description=__doc__
help="Retrieve IDs using search instead of the scroll api",
parser.add_argument("START", nargs="?", help="Start with this ID.")
def qescape(s):
for c in '+-=&|><!(){}[]^"~*?:\\/':
s = s.replace(c, "\\" + c)
return s
def scroll(ctx, args):
client = ctx.client
vault = ctx.vault
start = args.START or ""
if not args.use_search:
for aid in client.iter_scroll(vault, start=start):
q = "is:archive"
if start:
q = "{} AND id:>{}".format(q, qescape(start))
for hit in client.iter_search(vault, q, order="id"):
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