Gitlab Community Edition Instance

Commit eac72783 authored by mhellka's avatar mhellka Committed by Marcel Hellkamp
Browse files

Docstrings and TODOs

parent f11cd052
......@@ -143,9 +143,11 @@ class CDStar:
self.rollback()
def service_info(self):
""" Get information about the cdstar service instance """
return self.rest('GET')
def vault_info(self, vault: str):
""" Get information about a vault """
return self.rest('GET', vault)
def archive_info(self, vault, archive, meta=False, files=False):
......@@ -157,7 +159,15 @@ class CDStar:
query.setdefault("with", []).append("files")
return self.rest("GET", vault, archive, params=query)
def file_info(self, vault, archive, name, meta=False):
""" Get information about a file """
query = {"info": "true"}
if meta:
query['with'] = "meta"
return self.rest("GET", vault, archive, _fix_filename(name), params=query)
def create_archive(self, vault, form: "FormUpdate" = None):
""" Create a new archive. """
if form:
return self.rest("POST", vault, data=form.body,
headers={'Content-Type': form.content_type})
......@@ -165,6 +175,7 @@ class CDStar:
return self.rest("POST", vault)
def update_archive(self, vault, archive, form: "FormUpdate"):
""" Update an existing archive """
return self.rest("POST", vault, archive, data=form.body,
headers={'Content-Type': form.content_type})
......@@ -206,15 +217,9 @@ class CDStar:
headers = {'Range': "bytes={}-".format(offset)} if offset > 0 else {}
return self.raw("GET", vault, archive, _fix_filename(name), stream=True, headers=headers)
def file_info(self, vault, archive, name, meta=False):
""" Get information about a file """
query = {"info": "true"}
if meta:
query['with'] = "meta"
return self.rest("GET", vault, archive, _fix_filename(name), params=query)
def search(self, vault, q, order=None, limit=0, scroll=None, groups=None):
""" Perform a search and return the SearchResults document.
See iter_search() for a way to fetch more than `limit` results.
"""
query = {"q": q}
......@@ -315,7 +320,8 @@ class FormUpdate:
"""
if not name.startswith("/"):
name = "/" + name
if isinstance(src, str):
if isinstance(src, PATH_TYPES):
# TODO: Check what types are accepted as file-like and buold a lazily opened wrapper.
self.fields.append((name, (os.path.basename(src), open(src, "rb"), type)))
elif hasattr(src, 'fileno') or hasattr(src, 'getvalue'):
self.fields.append((name, (os.path.basename(src), src, type)))
......@@ -325,10 +331,13 @@ class FormUpdate:
def acl(self, subject, *permissions):
""" Set permissions for a subject. Existing permissions for the same subject are replaced.
:param subject: A subject-name, @groupname or one of `$any`, `$user`, `$user`
:param permissions:
:return: self
"""
# TODO: Check for valid subject and permission names
sub = "acl:{}".format(subject)
self.fields.append((sub, ','.join(permissions)))
return self
......@@ -336,6 +345,7 @@ class FormUpdate:
def meta(self, field, *values, file=None):
"""
Set metadata for the archive, or a file within the archive.
:param field: Meta-attribute field name. Should start with a schema prefix (e.g. `dc:` for DublinCore)
:param values: Values for this meta attribute.
:param file: File name to attach the metadata to. If not set, it is assigned to the entire archive.
......
Supports Markdown
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