Skip to content

Commit

Permalink
client: create project (#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Jul 13, 2022
1 parent 0f970ca commit 43a9be0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions mpcontribs-client/mpcontribs/client/__init__.py
Expand Up @@ -726,6 +726,29 @@ def get_project(self, name: str = None) -> Type[Dict]:

return Dict(self.projects.get_entry(pk=name, _fields=["_all"]).result())

def create_project(self, name: str, title: str, authors: str, description: str, url: str):
"""Create a project
Args:
name (str): unique name matching `^[a-zA-Z0-9_]{3,31}$`
title (str): unique title with 5-30 characters
authors (str): comma-separated list of authors
description (str): brief description (max 1500 characters)
url (str): URL for primary reference (paper/website/...)
"""
queries = [{"name": name}, {"title": title}]
for query in queries:
if self.get_totals(query=query, resource="projects")[0]:
logger.error(f"Project with {query} already exists!")
return

project = {
"name": name, "title": title, "authors": authors, "description": description,
"references": [{"label": "REF", "url": url}]
}
owner = self.projects.create_entry(project=project).result().get("owner")
logger.info(f"Project `{name}` created with owner `{owner}`")

def get_contribution(self, cid: str) -> Type[Dict]:
"""Retrieve full contribution entry
Expand Down Expand Up @@ -1011,6 +1034,7 @@ def get_totals(
Args:
query (dict): query to select resource entries
timeout (int): cancel remaining requests if timeout exceeded (in seconds)
resource (str): type of resource
op (str): operation to calculate total pages for, one of
("get", "create", "update", "delete", "download")
Expand Down

0 comments on commit 43a9be0

Please sign in to comment.