Skip to content
Snippets Groups Projects
Commit 31b737f9 authored by Romin's avatar Romin :eye:
Browse files

Update to Version 0.8.0

parent 2a62024b
Branches
Tags
No related merge requests found
Showing
with 243 additions and 14544 deletions
...@@ -3,3 +3,8 @@ __pycache__/ ...@@ -3,3 +3,8 @@ __pycache__/
*.egg-info/ *.egg-info/
.ipynb_checkpoints .ipynb_checkpoints
.dist/ .dist/
token.txt
.coverage
.mypy_cache/
public/
playground.py
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Coscine Python SDK # Coscine Python SDK
# Copyright (c) 2018-2022 RWTH Aachen University # Copyright (c) 2018-2022 RWTH Aachen University
# Licensed under the terms of the MIT License # Licensed under the terms of the MIT License
# ############################################################################# ###############################################################################
# Coscine, short for Collaborative Scientific Integration Environment is # Coscine, short for Collaborative Scientific Integration Environment is
# a platform for research data management (RDM). # a platform for research data management (RDM).
# For more information on Coscine visit https://www.coscine.de/. # For more information on Coscine visit https://www.coscine.de/.
...@@ -15,22 +15,134 @@ ...@@ -15,22 +15,134 @@
############################################################################### ###############################################################################
# File description # File description
############################################################################### ###############################################################################
# This GitLab-CI script builds the Coscine Python SDK package and pushes # This GitLab-CI script contains various jobs for building the
# a release to the python package index (https://pypi.org/project/coscine/). # Coscine Python SDK package, pushing a new release to the python
# It is triggered upon the creation of a new tag 'vX.X.X' where # package index (https://pypi.org/project/coscine/) or for static analysis
# X is a number in [0, 9]. # of the package and its sourcecode.
# For the deployment to pypi the authentication token 'PYPI_TOKEN' is required # For the deployment to pypi the authentication token 'PYPI_TOKEN' is required
# to be present in the GitLab repository settings. # to be present in the GitLab repository settings.
# Documentation is built and deployed to a local GitLab-Pages instance. # Documentation is built and deployed to a local GitLab-Pages instance.
############################################################################### ###############################################################################
stages: stages:
- quality assurance
- test - test
- pages - pages
- prepare deploy
- deploy - deploy
############################################################################### ###############################################################################
# Job: unittest # This job tests the python packaging for following recommended standards and
# best practices. If the package does not receive a perfect score of 10
# the job fails.
###############################################################################
module analysis with pyroma:
stage: prepare deploy
tags:
- "runner:docker"
image: python:latest
before_script:
- python -V
- pip --version
- pip install pyroma
script:
- python -m pyroma --min 10 -d .
when: manual
###############################################################################
# This job tests the sourcecode in the python module for formatting and
# following best practices.
# Since tabs are used for indentation, some settings have been turned off.
###############################################################################
static analysis with flake8:
stage: quality assurance
tags:
- "runner:docker"
image: python:latest
before_script:
- python -V
- pip install flake8
script:
- python -m flake8 src/coscine --statistics --count
--per-file-ignores="__init__.py:F401"
--ignore="W191,W503,E128,E302,E305"
--show-source
when: manual
###############################################################################
# This job tests the sourcecode in the python module for formatting and
# following best practices.
###############################################################################
static analysis with pylint:
stage: quality assurance
tags:
- "runner:docker"
image: python:latest
before_script:
- python -V
- pip install pylint
script:
- python -m pylint -f colorized --indent-string="\t" --fail-under=8
src/coscine
when: manual
###############################################################################
# This job tests the sourcecode in the python module for type conformity.
# --ignore-missing-imports : Do not error on type checking external
# dependencies in case they are not typed.
###############################################################################
type checking with mypy:
stage: quality assurance
tags:
- "runner:docker"
image: python:latest
before_script:
- python -V
- pip install mypy
script:
- mkdir .mypy-cache/
- python -m mypy src/coscine --ignore-missing-imports
--install-types --non-interactive
when: manual
###############################################################################
# This job determines the minimum python version required to run the package.
###############################################################################
determine minimum python version with vermin:
stage: prepare deploy
tags:
- "runner:docker"
image: python:latest
before_script:
- python -V
- pip install vermin
script:
- vermin -vvv --no-parse-comments --eval-annotations --target=3.7-
--pessimistic --violations --backport typing src/coscine
when: manual
###############################################################################
# This job makes sure that no fatal security flaws are shipped
# with the package.
###############################################################################
analyse security:
stage: quality assurance
tags:
- "runner:docker"
image: python:latest
before_script:
- python -V
- pip install bandit
script:
- python -m bandit -r src/coscine
when: manual
############################################################################### ###############################################################################
# This job tests the sourcecode in the python module. # This job tests the sourcecode in the python module.
############################################################################### ###############################################################################
...@@ -42,16 +154,14 @@ unittest: ...@@ -42,16 +154,14 @@ unittest:
image: python:3.7 image: python:3.7
before_script: before_script:
- python -V - python -V
- pip install coverage
- pip install .
script: script:
- coverage run -m unittest discover src/tests - COSCINE_API_TOKEN=${COSCINE_API_TOKEN}
python -m unittest discover src/tests
when: manual
############################################################################### ###############################################################################
# Job: release # This job builds and deploys the Coscine Python SDK packge to the
############################################################################### # Python Package index (PyPi). It is triggered with a new GitLab commit tag.
# This job builds and deploys the python packge to the
# Python Package index. It is triggered upon a new GitLab commit tag.
############################################################################### ###############################################################################
release: release:
...@@ -62,11 +172,9 @@ release: ...@@ -62,11 +172,9 @@ release:
before_script: before_script:
- python -V - python -V
- pip --version - pip --version
- pip install --upgrade pip
- pip --version
- pip list - pip list
script:
- pip install wheel twine - pip install wheel twine
script:
- python setup.py sdist bdist_wheel - python setup.py sdist bdist_wheel
- TWINE_PASSWORD=${PYPI_TOKEN} TWINE_USERNAME=__token__ - TWINE_PASSWORD=${PYPI_TOKEN} TWINE_USERNAME=__token__
python -m twine upload --repository pypi dist/* python -m twine upload --repository pypi dist/*
...@@ -75,23 +183,22 @@ release: ...@@ -75,23 +183,22 @@ release:
- $CI_COMMIT_TAG =~ /v[0-9]*\.[0-9]*\.[0-9]*/ - $CI_COMMIT_TAG =~ /v[0-9]*\.[0-9]*\.[0-9]*/
############################################################################### ###############################################################################
# Job: pages (documentation) # This job builds and deploys the documentation to a GitLab-Pages instance.
############################################################################### # It must be called "pages" and it must produce artificats called "public"!
# This job builds and deploys the documentation to a local
# GitLab-Pages instance.
############################################################################### ###############################################################################
pages: pages:
stage: deploy stage: pages
tags: tags:
- "runner:docker" - "runner:docker"
image: "python:3.7" image: "python:3.7"
before_script: before_script:
- python -V - python -V
- pip install -U pdoc3 - pip install pdoc
- pip install . - pip install -r requirements.txt
script: script:
- python -m pdoc --html --force --template-dir src/docs/template -o ./public ./src/coscine - python -m pdoc --docformat numpy --template-dir src/docs/template
-o ./public ./src/coscine !coscine.cache !coscine.defaults
- ls -la ./public - ls -la ./public
artifacts: artifacts:
paths: paths:
......
# Contributing to the Coscine Python SDK # Contributing to the Coscine Python SDK
## General ## General
The Coscine Python SDK is open source software and not developed by The Coscine Python SDK is open source software and not developed by
the Coscine team. Instead it is developed by the userbase of Coscine, the Coscine team. Instead it is developed by the userbase of Coscine,
which is researchers, data stewards and project managers. which is researchers, data stewards and project managers.
...@@ -9,38 +7,53 @@ If you belong to that userbase and would like to improve this package, ...@@ -9,38 +7,53 @@ If you belong to that userbase and would like to improve this package,
you are more than welcome to contribute. you are more than welcome to contribute.
## Contribution Workflow ## Contribution Workflow
The general flow of contributing to this repository is: The general flow of contributing to this repository is:
1. Create a fork of the repository and make your changes in your fork.
1. Create a fork of the repository and make your changes in your fork. In case you are not an RWTH member you may not have full access to the RWTH Gitlab and may not be able to fork projects. If you would like to participate, you need to be added to the project. Please contact [the community team](mailto:coscine-technical-adaptation@itc.rwth-aachen.de) and state your intention of contributing to the project. They will be able to grant you developer rights, which enable you to create merge requests inside the repository. In case you are not an RWTH member you may not have full access to
2. When you’re ready, create a new merge request. the [RWTH Gitlab instance] and may not be able to fork projects.
If you would like to participate anyway, you need to be added to the project.
Please contact the [Coscine Community Team] and state your intention of
contributing to the project. They will be able to grant you developer rights,
which enable you to create merge requests inside of community repositories.
2. When you’re ready and satisfied with the changes in your fork,
create a new merge request.
3. Ensure you provide complete and accurate information in the merge 3. Ensure you provide complete and accurate information in the merge
request’s description request’s description.
4. Once you’re ready, mark your MR as ready for review. 4. Once you’re ready, mark your MR as ready for review.
5. The Maintainers of this package will take a look at your contribution 5. The Maintainers of this package will take a look at your contribution
and incorporate the changes into the repository, if no fatal flaws and incorporate the changes into the repository, provided no fatal flaws
have been detected. have been detected and your proposed change is actually useful.
For small suggestions / changes you can also open an issue with
a feature request.
[RWTH Gitlab instance]: https://git.rwth-aachen.de
[Coscine Community Team]: mailto:coscine-technical-adaptation@itc.rwth-aachen.de
## Code convention & Style guidelines ## Code convention & Style guidelines
Consider some general guidelines to help making (your) code readable and
in line with the rest of the code in this package.
- limit the column size to 80 columns for each line - limit the column size to 80 columns for each line
- Links and other indivisible elements are exempt from this rule - Tabs vs. spaces - this package uses tabs
- When breaking a line in python, use \ - Set the tabsize in your editor to 4 to be in line with the 80 column rule
- Set tabsize to 4 - Use [numpy DOCstrings](https://numpydoc.readthedocs.io/en/latest/format.html)
- Use line-feed LF for modules, classes, methods and functions
- Set encoding to UTF-8 - Write type hints
- Use DOCstrings for modules, classes, methods and functions - Write self descriptive code, use sensible variable/function names
- Use [numpy DOCstring format](https://numpydoc.readthedocs.io/en/latest/format.html) - Roughly stick to PEP8
- Write self descriptive code - Try to comply with the minimum python version currently supported
- Variable and function names should indicate what's going on by the pacckage. This version will probably align with
- Code should make comments unncessecary (except in rare complicated cases) https://devguide.python.org/versions/. The CI Pipeline contains a job
to determine the minimum python version supported.
Stick to the following template for sourcecode files:
Roughly stick to the following template for sourcecode files:
```python ```python
############################################################################### ###############################################################################
# Coscine Python SDK # Coscine Python SDK
# Copyright (c) 2018-2022 RWTH Aachen University # Copyright (c) 2018-2022 RWTH Aachen University
# ############################################################################# # Licensed under the terms of the MIT License
###############################################################################
# Coscine, short for Collaborative Scientific Integration Environment is # Coscine, short for Collaborative Scientific Integration Environment is
# a platform for research data management (RDM). # a platform for research data management (RDM).
# For more information on Coscine visit https://www.coscine.de/. # For more information on Coscine visit https://www.coscine.de/.
...@@ -65,36 +78,19 @@ TODO ...@@ -65,36 +78,19 @@ TODO
from __future__ import annotations from __future__ import annotations
############################################################################### ###############################################################################
# Global variables # Module globals / Constants
############################################################################### ###############################################################################
############################################################################### ###############################################################################
# Class # Classes / Functions / Scripts
############################################################################### ###############################################################################
############################################################################### ###############################################################################
``` ```
- Seperating elements with 80 column comments makes it easier to scroll ## CI Pipelines
between elements such as functions as their boundaries become apparent This repository is configured to work with a variety of static analysis tools
- Seperating sourcecode with different purposes by big 80 column comments and automatic documentation generators. For an overview over the different
divides the source file into different sections and gives the file CI/CD Pipelines, have a look at [.gitlab-ci.yml](.gitlab-ci.yml).
a structure, which can be searched through by using a search string Install the tools mentioned in the jobs on your local system to test your
such as '# section'. fork locally. Documentation is provided in the ci configuration file.
---------------------
## Deployment
(Re-)Build the documentation with
```bash
cd ./coscine-python-sdk
py -m pip install pdoc3
py -m pdoc --html --force --template-dir src/docs/template -o ./public ./src/coscine
```
## Maintainers
To deploy code to PyPi and essentially publish a new version of the Python
SDK, create a new Tag in the GitLab-repository with the new version 'vX.X.X'.
Monitor the GitLab-Ci pipeline and check whether everything went ok.
# Coscine Python SDK # Coscine Python SDK
![Coscine] ![Python] ![Coscine] ![Python]
[Coscine](https://coscine.rwth-aachen.de/), short for Collaborative Scientific [Coscine](https://coscine.de/), short for **Co**llaborative **Sc**ientific
Integration Environment is a platform for research data management (RDM). **In**tegration **E**nvironment, is a platform for Research Data Management.
For more information on Coscine visit the [Coscine Landing Page].
[Coscine]: ./data/coscine_logo_rgb.png [Coscine]: ./data/coscine_logo_rgb.png
[Python]: ./data/python-powered-w-200x80.png [Python]: ./data/python-powered-w-200x80.png
[Coscine Landing Page]: https://www.coscine.de/ [Coscine Landing Page]: https://www.coscine.de/
## About ## About
The *Coscine Python SDK* is an open source python package providing The *Coscine Python SDK* is an open source python package providing
a pythonic client interface to the Coscine REST API. It is compatible a pythonic interface to the *Coscine* REST API.
with Python versions 3.7+. ### Features:
Features (to name a few): - **Project Management**
- Project Management - Create, modify or delete projects
- Create, modify or delete a project - Add/Invite members to projects and set their roles
- Add/Invite members to a project and set their roles - Download projects and all their content
- Download a project and all of its contents - **Resource Management**
- Resource Management - Create, modify or delete resources
- Create, modify or delete a resource - Download resources and all of their content
- Download a resource and all of its contents - **File and Metadata Management**
- File and Metadata Management
- Upload, download and delete files - Upload, download and delete files
- Interact with metadata in an intuitive pythonic manner - Interact with metadata in an intuitive pythonic manner
- Fetch S3 access credentials - Fetch S3 access credentials
> **Note** > **DISCLAIMER**
> Please note that this python module is developed and maintained > Please note that this python module is developed and maintained
> by the scientific community and even though Copyright remains with > by the scientific community and even though Copyright remains with
> RWTH Aachen, it is not an official service that RWTH Aachen > *RWTH Aachen*, it is not an official service that *RWTH Aachen*
> provides support for. > provides support for.
## Code example ## Example Code
Shown below is a small code snippet highlighting some functionality
offered by this package.
**Uploading a file to a resource located in a subproject:**
```python ```python
import coscine import coscine
from datetime import datetime
cfg = coscine.Config() token: str = "My Coscine API Token"
client = coscine.Client(cfg.token) client = coscine.Client(token)
project = client.project("My Project") project = client.project("My Project").subproject("My Subproject")
resource = project.resource("My Resource") resource = project.resource("My Resource")
resource.upload("file.txt", "C:/databases/file.txt") metadata = resource.metadata_form()
for file in resource.objects(): metadata["Author"] = "Dr. Akula"
print(file.name) metadata["Created"] = datetime.now()
print(file.metadata()) metadata["Discipline"] = "Medicine"
if file.size > 4096: file.delete() metadata["DAP"] = 0.32
metadata = resource.object("path/to/file.csv").form() # ...
metadata["Author"] = "John Doe" resource.upload("file.txt", "C:/databases/file.txt", metadata)
resource.object("path/to/file.csv").update(metadata)
project.download("/home/datascience", metadata=True)
``` ```
## Installation **Listing all files in all resources of a project:**
```python
import coscine
### via the Python Package Index (PyPi) token: str = "My Coscine API Token"
client = coscine.Client(token)
for resource in client.project("My Project").resources():
for file in resource.contents():
if not file.is_folder:
print(file.path)
```
The *Coscine Python SDK* is hosted on the *Python Package Index (PyPi)*: More examples can be found in the online [documentation].
https://pypi.org/project/coscine/
[documentation]: https://coscine.pages.rwth-aachen.de/community-features/coscine-python-sdk
## Installation
### via the Python Package Index (PyPi)
The *Coscine Python SDK* is hosted on the [*Python Package Index (PyPi)*].
You can download and install the package with *pip*: You can download and install the package with *pip*:
```bash ```bash
py -m pip install coscine py -m pip install coscine
``` ```
### via Conda [*Python Package Index (PyPi)*]: https://pypi.org/project/coscine/
### via Conda
The package version hosted on the *Python Package Index (PyPi)* is The package version hosted on the *Python Package Index (PyPi)* is
automatically mirrored in the community driven packaging for *Conda*. automatically mirrored in the community driven packaging for *Conda*.
You can download and install the package with *conda*: You can download and install the package with *conda*:
```bash ```bash
conda install -c conda-forge coscine conda install -c conda-forge coscine
``` ```
### via Git ### via Git
Manual installation: Manual installation:
```bash ```bash
git clone https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk.git git clone https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk.git
...@@ -88,30 +91,31 @@ py setup.py ...@@ -88,30 +91,31 @@ py setup.py
``` ```
## Documentation ## Documentation
The source code has been thorougly documented with *Python DOCstrings*. The source code has been thorougly documented with *Python DOCstrings*.
Documentation can be generated via a variety of tools that take advantage Documentation can be generated via a variety of tools that take advantage
of these *DOCstrings*, such as [pydoc] or [pdoc3]. of these *DOCstrings*, such as [pydoc] or [pdoc].
Use the following script to generate documentation with *pdoc3*: Use the following script to generate documentation with *pdoc*:
```bash ```bash
cd ./coscine-python-sdk cd ./coscine-python-sdk
py -m pip install pdoc3 py -m pip install pdoc
py -m pdoc --html --force --template-dir src/docs/template -o ./public ./src/coscine py -m pdoc --docformat numpy --template-dir src/docs/template -o ./public ./src/coscine
``` ```
The documentation inside of this repository is automatically deployed to The documentation inside of this repository is automatically deployed to
a [GitLab-Pages instance] for online access. a [GitLab-Pages instance] for online access.
[GitLab-Pages instance]:https://coscine.pages.rwth-aachen.de/community-features/coscine-python-sdk/coscine [GitLab-Pages instance]:https://coscine.pages.rwth-aachen.de/community-features/coscine-python-sdk/coscine
[pydoc]:https://docs.python.org/3/library/pydoc.html [pydoc]:https://docs.python.org/3/library/pydoc.html
[pdoc3]:https://pypi.org/project/pdoc3/ [pdoc]:https://pypi.org/project/pdoc/
## Contact ## Contact
To report bugs, request features or resolve questions open an issue inside To report bugs, request features or resolve questions open an issue inside
of the current git repository. of the current git repository.
Contributions and any help on improving this package are appreciated. To Contributions and any help on improving this package are appreciated. To
contribute source code you may fork the repository and open a merge request contribute source code you may fork the repository and open a merge request
or simply submit a short and relevant snippet or fix inside of an issue. or simply submit a short and relevant snippet or fix inside of an issue.
More information on contributing can be found in [CONTRIBUTING.txt].
[CONTRIBUTING.txt]: ./CONTRIBUTING.txt
## License ## License
......
This diff is collapsed.
This diff is collapsed.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>coscine.config API documentation</title>
<meta name="description" content="This file provides an easy way of reading coscine-python-sdk
config files." />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
<style>.homelink{display:block;font-size:2em;font-weight:bold;color:#555;padding-bottom:.5em;border-bottom:1px solid silver}.homelink:hover{color:inherit}.homelink img{max-width:20%;max-height:5em;margin:auto;margin-bottom:.3em}</style>
<link rel="canonical" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk">
<link rel="icon" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk/-/raw/master/data/coscine_logo_rgb.png">
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>coscine.config</code></h1>
</header>
<section id="section-intro">
<p>This file provides an easy way of reading coscine-python-sdk
config files.</p>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">###############################################################################
# Coscine Python SDK
# Copyright (c) 2018-2022 RWTH Aachen University
# Licensed under the terms of the MIT License
# #############################################################################
# Coscine, short for Collaborative Scientific Integration Environment is
# a platform for research data management (RDM).
# For more information on Coscine visit https://www.coscine.de/.
#
# Please note that this python module is open source software primarily
# developed and maintained by the scientific community. It is not
# an official service that RWTH Aachen provides support for.
###############################################################################
###############################################################################
# File description
###############################################################################
&#34;&#34;&#34;
This file provides an easy way of reading coscine-python-sdk
config files.
&#34;&#34;&#34;
###############################################################################
# Dependencies
###############################################################################
from __future__ import annotations
from .__about__ import __version__
from .defaults import APPDIR
import json
import os
###############################################################################
# Class
###############################################################################
class Config:
&#34;&#34;&#34;
A class to read from coscine-python-sdk config files.
Lookup order:
0. Custom path specified in constructor (fail if not found)
1. Local config file
2. Local config directory
3. System directory (e.g. User/AppData/Local/... on Windows)
&#34;&#34;&#34;
token: str
language: str
concurrent: bool
###############################################################################
def __init__(self, path: str = &#34;&#34;) -&gt; None:
&#34;&#34;&#34;
Initialized the configuration file interface with an
optional path argument.
Parameters
-----------
path : str
If set to a valid file path, an attempt is made to laod
the file referenced by path as a config.
Raises
-------
FileNotFoundError
In case no config file could have been located.
&#34;&#34;&#34;
if path:
self.load(path)
elif os.path.exists(&#34;.config.json&#34;):
self.load(&#34;.config.json&#34;)
elif os.path.exists(&#34;.coscine/&#34;):
self.load(os.path.join(&#34;.coscine/&#34;, &#34;config.json&#34;))
elif os.path.exists(APPDIR.user_config_dir):
self.load(os.path.join(APPDIR.user_config_dir, &#34;config.json&#34;))
else:
raise FileNotFoundError(&#34;Failed to locate config file!&#34;)
###############################################################################
def load(self, path: str) -&gt; None:
&#34;&#34;&#34;
Loads a valid coscine-python-sdk config file and validates
the file for correctness.
Parameters
-----------
path : str
The filepath to the configuration file (must include filename)
&#34;&#34;&#34;
with open(path, &#34;r&#34;) as fd:
data = json.load(fd)
self.token = data[&#34;token&#34;] if &#34;token&#34; in data else None
self.language = data[&#34;language&#34;] if &#34;language&#34; in data else None
self.concurrent = data[&#34;concurrent&#34;] if &#34;concurrent&#34; in data else True
###############################################################################</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="coscine.config.Config"><code class="flex name class">
<span>class <span class="ident">Config</span></span>
<span>(</span><span>path: str = '')</span>
</code></dt>
<dd>
<div class="desc"><p>A class to read from coscine-python-sdk config files.
Lookup order:<br>
0. Custom path specified in constructor (fail if not found)<br>
1. Local config file<br>
2. Local config directory<br>
3. System directory (e.g. User/AppData/Local/&hellip; on Windows)
</p>
<p>Initialized the configuration file interface with an
optional path argument.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>path</code></strong> :&ensp;<code>str</code></dt>
<dd>If set to a valid file path, an attempt is made to laod
the file referenced by path as a config.</dd>
</dl>
<h2 id="raises">Raises</h2>
<dl>
<dt><code>FileNotFoundError</code></dt>
<dd>In case no config file could have been located.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class Config:
&#34;&#34;&#34;
A class to read from coscine-python-sdk config files.
Lookup order:
0. Custom path specified in constructor (fail if not found)
1. Local config file
2. Local config directory
3. System directory (e.g. User/AppData/Local/... on Windows)
&#34;&#34;&#34;
token: str
language: str
concurrent: bool
###############################################################################
def __init__(self, path: str = &#34;&#34;) -&gt; None:
&#34;&#34;&#34;
Initialized the configuration file interface with an
optional path argument.
Parameters
-----------
path : str
If set to a valid file path, an attempt is made to laod
the file referenced by path as a config.
Raises
-------
FileNotFoundError
In case no config file could have been located.
&#34;&#34;&#34;
if path:
self.load(path)
elif os.path.exists(&#34;.config.json&#34;):
self.load(&#34;.config.json&#34;)
elif os.path.exists(&#34;.coscine/&#34;):
self.load(os.path.join(&#34;.coscine/&#34;, &#34;config.json&#34;))
elif os.path.exists(APPDIR.user_config_dir):
self.load(os.path.join(APPDIR.user_config_dir, &#34;config.json&#34;))
else:
raise FileNotFoundError(&#34;Failed to locate config file!&#34;)
###############################################################################
def load(self, path: str) -&gt; None:
&#34;&#34;&#34;
Loads a valid coscine-python-sdk config file and validates
the file for correctness.
Parameters
-----------
path : str
The filepath to the configuration file (must include filename)
&#34;&#34;&#34;
with open(path, &#34;r&#34;) as fd:
data = json.load(fd)
self.token = data[&#34;token&#34;] if &#34;token&#34; in data else None
self.language = data[&#34;language&#34;] if &#34;language&#34; in data else None
self.concurrent = data[&#34;concurrent&#34;] if &#34;concurrent&#34; in data else True</code></pre>
</details>
<h3>Class variables</h3>
<dl>
<dt id="coscine.config.Config.concurrent"><code class="name">var <span class="ident">concurrent</span> : bool</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="coscine.config.Config.language"><code class="name">var <span class="ident">language</span> : str</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="coscine.config.Config.token"><code class="name">var <span class="ident">token</span> : str</code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="coscine.config.Config.load"><code class="name flex">
<span>def <span class="ident">load</span></span>(<span>self, path: str) ‑> None</span>
</code></dt>
<dd>
<div class="desc"><p>Loads a valid coscine-python-sdk config file and validates
the file for correctness.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>path</code></strong> :&ensp;<code>str</code></dt>
<dd>The filepath to the configuration file (must include filename)</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def load(self, path: str) -&gt; None:
&#34;&#34;&#34;
Loads a valid coscine-python-sdk config file and validates
the file for correctness.
Parameters
-----------
path : str
The filepath to the configuration file (must include filename)
&#34;&#34;&#34;
with open(path, &#34;r&#34;) as fd:
data = json.load(fd)
self.token = data[&#34;token&#34;] if &#34;token&#34; in data else None
self.language = data[&#34;language&#34;] if &#34;language&#34; in data else None
self.concurrent = data[&#34;concurrent&#34;] if &#34;concurrent&#34; in data else True</code></pre>
</details>
</dd>
</dl>
</dd>
</dl>
</section>
</article>
<nav id="sidebar">
<header>
<a class="homelink" rel="home" title="Coscine Home" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk">
<img src="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk/-/raw/master/data/coscine_logo_rgb.png" alt="">
</a>
</header>
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="coscine" href="index.html">coscine</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="coscine.config.Config" href="#coscine.config.Config">Config</a></code></h4>
<ul class="">
<li><code><a title="coscine.config.Config.concurrent" href="#coscine.config.Config.concurrent">concurrent</a></code></li>
<li><code><a title="coscine.config.Config.language" href="#coscine.config.Config.language">language</a></code></li>
<li><code><a title="coscine.config.Config.load" href="#coscine.config.Config.load">load</a></code></li>
<li><code><a title="coscine.config.Config.token" href="#coscine.config.Config.token">token</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>
\ No newline at end of file
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>coscine.defaults API documentation</title>
<meta name="description" content="This file defines default and constant data internally used by
multiple modules to avoid redefinitions." />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
<style>.homelink{display:block;font-size:2em;font-weight:bold;color:#555;padding-bottom:.5em;border-bottom:1px solid silver}.homelink:hover{color:inherit}.homelink img{max-width:20%;max-height:5em;margin:auto;margin-bottom:.3em}</style>
<link rel="canonical" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk">
<link rel="icon" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk/-/raw/master/data/coscine_logo_rgb.png">
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>coscine.defaults</code></h1>
</header>
<section id="section-intro">
<p>This file defines default and constant data internally used by
multiple modules to avoid redefinitions.</p>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">###############################################################################
# Coscine Python SDK
# Copyright (c) 2018-2022 RWTH Aachen University
# Licensed under the terms of the MIT License
# #############################################################################
# Coscine, short for Collaborative Scientific Integration Environment is
# a platform for research data management (RDM).
# For more information on Coscine visit https://www.coscine.de/.
#
# Please note that this python module is open source software primarily
# developed and maintained by the scientific community. It is not
# an official service that RWTH Aachen provides support for.
###############################################################################
###############################################################################
# File description
###############################################################################
&#34;&#34;&#34;
This file defines default and constant data internally used by
multiple modules to avoid redefinitions.
&#34;&#34;&#34;
###############################################################################
# Dependencies
###############################################################################
from __future__ import annotations
from typing import List
from appdirs import AppDirs
from .__about__ import __version__
###############################################################################
# The time format for parsing Coscine date strings with datetime
TIMEFORMAT: str = &#34;%Y-%m-%dT%H:%M:%S&#34;
# Build default application directory paths
APPDIR: AppDirs = AppDirs(&#34;coscine-python-sdk&#34;, &#34;Coscine&#34;)
# The name for the persistent cache file storage
CACHEFILE: str = f&#34;{__version__}-cache.json&#34;
# The languages supported by the Coscine Python SDK
LANGUAGES: List[str] = [&#34;de&#34;, &#34;en&#34;]
# Supported formats for printing forms
TABLE_FORMATS: List[str] = [&#34;str&#34;, &#34;csv&#34;, &#34;json&#34;, &#34;html&#34;]
###############################################################################</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
</article>
<nav id="sidebar">
<header>
<a class="homelink" rel="home" title="Coscine Home" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk">
<img src="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk/-/raw/master/data/coscine_logo_rgb.png" alt="">
</a>
</header>
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="coscine" href="index.html">coscine</a></code></li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>
\ No newline at end of file
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>coscine.exceptions API documentation</title>
<meta name="description" content="This file defines all of the exceptions raised by the Coscine Python SDK.
The base exception class is called CoscineException. It directly inherits
…" />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
<style>.homelink{display:block;font-size:2em;font-weight:bold;color:#555;padding-bottom:.5em;border-bottom:1px solid silver}.homelink:hover{color:inherit}.homelink img{max-width:20%;max-height:5em;margin:auto;margin-bottom:.3em}</style>
<link rel="canonical" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk">
<link rel="icon" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk/-/raw/master/data/coscine_logo_rgb.png">
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>coscine.exceptions</code></h1>
</header>
<section id="section-intro">
<p>This file defines all of the exceptions raised by the Coscine Python SDK.
The base exception class is called CoscineException. It directly inherits
its properties from the standard Python Exception class.
Although never used directly it provides the basis for more specific
exceptions, thus allowing you to catch any Coscine exception with just one
except statement:
try:
something()
except coscine.CoscineException: # Gotta Catch 'Em All
print("Oh Dios Mio!")</p>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">###############################################################################
# Coscine Python SDK
# Copyright (c) 2018-2022 RWTH Aachen University
# Licensed under the terms of the MIT License
# #############################################################################
# Coscine, short for Collaborative Scientific Integration Environment is
# a platform for research data management (RDM).
# For more information on Coscine visit https://www.coscine.de/.
#
# Please note that this python module is open source software primarily
# developed and maintained by the scientific community. It is not
# an official service that RWTH Aachen provides support for.
###############################################################################
###############################################################################
# File description
###############################################################################
&#34;&#34;&#34;
This file defines all of the exceptions raised by the Coscine Python SDK.
The base exception class is called CoscineException. It directly inherits
its properties from the standard Python Exception class.
Although never used directly it provides the basis for more specific
exceptions, thus allowing you to catch any Coscine exception with just one
except statement:
try:
something()
except coscine.CoscineException: # Gotta Catch &#39;Em All
print(&#34;Oh Dios Mio!&#34;)
&#34;&#34;&#34;
###############################################################################
# Class definition
###############################################################################
class CoscineException(Exception):
&#34;&#34;&#34;
Coscine base Exception class.
&#34;&#34;&#34;
###############################################################################
class ConnectionError(CoscineException):
&#34;&#34;&#34;
A ConnectionError is raised in case the client is not able to establish
a connection with the Coscine servers.
&#34;&#34;&#34;
pass
###############################################################################
class AuthorizationError(CoscineException):
&#34;&#34;&#34;
AuthorizationErrors are thrown in case of an invalid
or empty Coscine ApiToken.
&#34;&#34;&#34;
pass
###############################################################################
class PermissionError(CoscineException):
&#34;&#34;&#34;
A PermissionError is thrown in cases where the owner of
the Coscine API token does not hold enough privileges to access
a certain path or perform a certain action.
&#34;&#34;&#34;
pass
###############################################################################
class ClientError(CoscineException):
&#34;&#34;&#34;
An ambiguous error has been made or detected on the client side.
&#34;&#34;&#34;
pass
###############################################################################
class ServerError(CoscineException):
&#34;&#34;&#34;
An ambiguous error has been made or detected on the Coscine server.
&#34;&#34;&#34;
pass
###############################################################################</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="coscine.exceptions.AuthorizationError"><code class="flex name class">
<span>class <span class="ident">AuthorizationError</span></span>
<span>(</span><span>*args, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"><p>AuthorizationErrors are thrown in case of an invalid
or empty Coscine ApiToken.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class AuthorizationError(CoscineException):
&#34;&#34;&#34;
AuthorizationErrors are thrown in case of an invalid
or empty Coscine ApiToken.
&#34;&#34;&#34;
pass</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
<li><a title="coscine.exceptions.CoscineException" href="#coscine.exceptions.CoscineException">CoscineException</a></li>
<li>builtins.Exception</li>
<li>builtins.BaseException</li>
</ul>
</dd>
<dt id="coscine.exceptions.ClientError"><code class="flex name class">
<span>class <span class="ident">ClientError</span></span>
<span>(</span><span>*args, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"><p>An ambiguous error has been made or detected on the client side.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class ClientError(CoscineException):
&#34;&#34;&#34;
An ambiguous error has been made or detected on the client side.
&#34;&#34;&#34;
pass</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
<li><a title="coscine.exceptions.CoscineException" href="#coscine.exceptions.CoscineException">CoscineException</a></li>
<li>builtins.Exception</li>
<li>builtins.BaseException</li>
</ul>
</dd>
<dt id="coscine.exceptions.ConnectionError"><code class="flex name class">
<span>class <span class="ident">ConnectionError</span></span>
<span>(</span><span>*args, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"><p>A ConnectionError is raised in case the client is not able to establish
a connection with the Coscine servers.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class ConnectionError(CoscineException):
&#34;&#34;&#34;
A ConnectionError is raised in case the client is not able to establish
a connection with the Coscine servers.
&#34;&#34;&#34;
pass</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
<li><a title="coscine.exceptions.CoscineException" href="#coscine.exceptions.CoscineException">CoscineException</a></li>
<li>builtins.Exception</li>
<li>builtins.BaseException</li>
</ul>
</dd>
<dt id="coscine.exceptions.CoscineException"><code class="flex name class">
<span>class <span class="ident">CoscineException</span></span>
<span>(</span><span>*args, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"><p>Coscine base Exception class.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class CoscineException(Exception):
&#34;&#34;&#34;
Coscine base Exception class.
&#34;&#34;&#34;</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
<li>builtins.Exception</li>
<li>builtins.BaseException</li>
</ul>
<h3>Subclasses</h3>
<ul class="hlist">
<li><a title="coscine.exceptions.AuthorizationError" href="#coscine.exceptions.AuthorizationError">AuthorizationError</a></li>
<li><a title="coscine.exceptions.ClientError" href="#coscine.exceptions.ClientError">ClientError</a></li>
<li><a title="coscine.exceptions.ConnectionError" href="#coscine.exceptions.ConnectionError">ConnectionError</a></li>
<li><a title="coscine.exceptions.PermissionError" href="#coscine.exceptions.PermissionError">PermissionError</a></li>
<li><a title="coscine.exceptions.ServerError" href="#coscine.exceptions.ServerError">ServerError</a></li>
</ul>
</dd>
<dt id="coscine.exceptions.PermissionError"><code class="flex name class">
<span>class <span class="ident">PermissionError</span></span>
<span>(</span><span>*args, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"><p>A PermissionError is thrown in cases where the owner of
the Coscine API token does not hold enough privileges to access
a certain path or perform a certain action.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class PermissionError(CoscineException):
&#34;&#34;&#34;
A PermissionError is thrown in cases where the owner of
the Coscine API token does not hold enough privileges to access
a certain path or perform a certain action.
&#34;&#34;&#34;
pass</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
<li><a title="coscine.exceptions.CoscineException" href="#coscine.exceptions.CoscineException">CoscineException</a></li>
<li>builtins.Exception</li>
<li>builtins.BaseException</li>
</ul>
</dd>
<dt id="coscine.exceptions.ServerError"><code class="flex name class">
<span>class <span class="ident">ServerError</span></span>
<span>(</span><span>*args, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"><p>An ambiguous error has been made or detected on the Coscine server.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class ServerError(CoscineException):
&#34;&#34;&#34;
An ambiguous error has been made or detected on the Coscine server.
&#34;&#34;&#34;
pass</code></pre>
</details>
<h3>Ancestors</h3>
<ul class="hlist">
<li><a title="coscine.exceptions.CoscineException" href="#coscine.exceptions.CoscineException">CoscineException</a></li>
<li>builtins.Exception</li>
<li>builtins.BaseException</li>
</ul>
</dd>
</dl>
</section>
</article>
<nav id="sidebar">
<header>
<a class="homelink" rel="home" title="Coscine Home" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk">
<img src="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk/-/raw/master/data/coscine_logo_rgb.png" alt="">
</a>
</header>
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="coscine" href="index.html">coscine</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="coscine.exceptions.AuthorizationError" href="#coscine.exceptions.AuthorizationError">AuthorizationError</a></code></h4>
</li>
<li>
<h4><code><a title="coscine.exceptions.ClientError" href="#coscine.exceptions.ClientError">ClientError</a></code></h4>
</li>
<li>
<h4><code><a title="coscine.exceptions.ConnectionError" href="#coscine.exceptions.ConnectionError">ConnectionError</a></code></h4>
</li>
<li>
<h4><code><a title="coscine.exceptions.CoscineException" href="#coscine.exceptions.CoscineException">CoscineException</a></code></h4>
</li>
<li>
<h4><code><a title="coscine.exceptions.PermissionError" href="#coscine.exceptions.PermissionError">PermissionError</a></code></h4>
</li>
<li>
<h4><code><a title="coscine.exceptions.ServerError" href="#coscine.exceptions.ServerError">ServerError</a></code></h4>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>coscine.utils API documentation</title>
<meta name="description" content="This file contains utility classes and functions, mostly taken from another
source like StackOverflow. Credit is given where it is due." />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
<style>.homelink{display:block;font-size:2em;font-weight:bold;color:#555;padding-bottom:.5em;border-bottom:1px solid silver}.homelink:hover{color:inherit}.homelink img{max-width:20%;max-height:5em;margin:auto;margin-bottom:.3em}</style>
<link rel="canonical" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk">
<link rel="icon" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk/-/raw/master/data/coscine_logo_rgb.png">
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>coscine.utils</code></h1>
</header>
<section id="section-intro">
<p>This file contains utility classes and functions, mostly taken from another
source like StackOverflow. Credit is given where it is due.</p>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">###############################################################################
# Coscine Python SDK
# Copyright (c) 2018-2022 RWTH Aachen University
# Licensed under the terms of the MIT License
# #############################################################################
# Coscine, short for Collaborative Scientific Integration Environment is
# a platform for research data management (RDM).
# For more information on Coscine visit https://www.coscine.de/.
#
# Please note that this python module is open source software primarily
# developed and maintained by the scientific community. It is not
# an official service that RWTH Aachen provides support for.
###############################################################################
###############################################################################
# File description
###############################################################################
&#34;&#34;&#34;
This file contains utility classes and functions, mostly taken from another
source like StackOverflow. Credit is given where it is due.
&#34;&#34;&#34;
###############################################################################
# Dependencies
###############################################################################
from typing import List, Union
###############################################################################
# Class
###############################################################################
# Source: https://stackoverflow.com/questions/12523586/
# python-format-size-application-converting-b-to-kb-mb-gb-tb
# by Mitch McMabers (https://stackoverflow.com/users/8874388/mitch-mcmabers)
# Licensed under the Public Domain
###############################################################################
class HumanBytes:
METRIC_LABELS: List[str] = [&#34;B&#34;, &#34;kB&#34;, &#34;MB&#34;, &#34;GB&#34;, &#34;TB&#34;, &#34;PB&#34;, &#34;EB&#34;, &#34;ZB&#34;, &#34;YB&#34;]
BINARY_LABELS: List[str] = [&#34;B&#34;, &#34;KiB&#34;, &#34;MiB&#34;, &#34;GiB&#34;, &#34;TiB&#34;, &#34;PiB&#34;, &#34;EiB&#34;, &#34;ZiB&#34;, &#34;YiB&#34;]
PRECISION_OFFSETS: List[float] = [0.5, 0.05, 0.005, 0.0005] # PREDEFINED FOR SPEED.
PRECISION_FORMATS: List[str] = [&#34;{}{:.0f} {}&#34;, &#34;{}{:.1f} {}&#34;, &#34;{}{:.2f} {}&#34;, &#34;{}{:.3f} {}&#34;] # PREDEFINED FOR SPEED.
@staticmethod
def format(num: Union[int, float], metric: bool=False, precision: int=1) -&gt; str:
&#34;&#34;&#34;
Human-readable formatting of bytes, using binary (powers of 1024)
or metric (powers of 1000) representation.
&#34;&#34;&#34;
assert isinstance(num, (int, float)), &#34;num must be an int or float&#34;
assert isinstance(metric, bool), &#34;metric must be a bool&#34;
assert isinstance(precision, int) and precision &gt;= 0 and precision &lt;= 3, &#34;precision must be an int (range 0-3)&#34;
unit_labels = HumanBytes.METRIC_LABELS if metric else HumanBytes.BINARY_LABELS
last_label = unit_labels[-1]
unit_step = 1000 if metric else 1024
unit_step_thresh = unit_step - HumanBytes.PRECISION_OFFSETS[precision]
is_negative = num &lt; 0
if is_negative: # Faster than ternary assignment or always running abs().
num = abs(num)
for unit in unit_labels:
if num &lt; unit_step_thresh:
# VERY IMPORTANT:
# Only accepts the CURRENT unit if we&#39;re BELOW the threshold where
# float rounding behavior would place us into the NEXT unit: F.ex.
# when rounding a float to 1 decimal, any number &#34;&gt;= 1023.95&#34; will
# be rounded to &#34;1024.0&#34;. Obviously we don&#39;t want ugly output such
# as &#34;1024.0 KiB&#34;, since the proper term for that is &#34;1.0 MiB&#34;.
break
if unit != last_label:
# We only shrink the number if we HAVEN&#39;T reached the last unit.
# NOTE: These looped divisions accumulate floating point rounding
# errors, but each new division pushes the rounding errors further
# and further down in the decimals, so it doesn&#39;t matter at all.
num /= unit_step
return HumanBytes.PRECISION_FORMATS[precision].format(&#34;-&#34; if is_negative else &#34;&#34;, num, unit)
###############################################################################</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-classes">Classes</h2>
<dl>
<dt id="coscine.utils.HumanBytes"><code class="flex name class">
<span>class <span class="ident">HumanBytes</span></span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">class HumanBytes:
METRIC_LABELS: List[str] = [&#34;B&#34;, &#34;kB&#34;, &#34;MB&#34;, &#34;GB&#34;, &#34;TB&#34;, &#34;PB&#34;, &#34;EB&#34;, &#34;ZB&#34;, &#34;YB&#34;]
BINARY_LABELS: List[str] = [&#34;B&#34;, &#34;KiB&#34;, &#34;MiB&#34;, &#34;GiB&#34;, &#34;TiB&#34;, &#34;PiB&#34;, &#34;EiB&#34;, &#34;ZiB&#34;, &#34;YiB&#34;]
PRECISION_OFFSETS: List[float] = [0.5, 0.05, 0.005, 0.0005] # PREDEFINED FOR SPEED.
PRECISION_FORMATS: List[str] = [&#34;{}{:.0f} {}&#34;, &#34;{}{:.1f} {}&#34;, &#34;{}{:.2f} {}&#34;, &#34;{}{:.3f} {}&#34;] # PREDEFINED FOR SPEED.
@staticmethod
def format(num: Union[int, float], metric: bool=False, precision: int=1) -&gt; str:
&#34;&#34;&#34;
Human-readable formatting of bytes, using binary (powers of 1024)
or metric (powers of 1000) representation.
&#34;&#34;&#34;
assert isinstance(num, (int, float)), &#34;num must be an int or float&#34;
assert isinstance(metric, bool), &#34;metric must be a bool&#34;
assert isinstance(precision, int) and precision &gt;= 0 and precision &lt;= 3, &#34;precision must be an int (range 0-3)&#34;
unit_labels = HumanBytes.METRIC_LABELS if metric else HumanBytes.BINARY_LABELS
last_label = unit_labels[-1]
unit_step = 1000 if metric else 1024
unit_step_thresh = unit_step - HumanBytes.PRECISION_OFFSETS[precision]
is_negative = num &lt; 0
if is_negative: # Faster than ternary assignment or always running abs().
num = abs(num)
for unit in unit_labels:
if num &lt; unit_step_thresh:
# VERY IMPORTANT:
# Only accepts the CURRENT unit if we&#39;re BELOW the threshold where
# float rounding behavior would place us into the NEXT unit: F.ex.
# when rounding a float to 1 decimal, any number &#34;&gt;= 1023.95&#34; will
# be rounded to &#34;1024.0&#34;. Obviously we don&#39;t want ugly output such
# as &#34;1024.0 KiB&#34;, since the proper term for that is &#34;1.0 MiB&#34;.
break
if unit != last_label:
# We only shrink the number if we HAVEN&#39;T reached the last unit.
# NOTE: These looped divisions accumulate floating point rounding
# errors, but each new division pushes the rounding errors further
# and further down in the decimals, so it doesn&#39;t matter at all.
num /= unit_step
return HumanBytes.PRECISION_FORMATS[precision].format(&#34;-&#34; if is_negative else &#34;&#34;, num, unit)</code></pre>
</details>
<h3>Class variables</h3>
<dl>
<dt id="coscine.utils.HumanBytes.BINARY_LABELS"><code class="name">var <span class="ident">BINARY_LABELS</span> : List[str]</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="coscine.utils.HumanBytes.METRIC_LABELS"><code class="name">var <span class="ident">METRIC_LABELS</span> : List[str]</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="coscine.utils.HumanBytes.PRECISION_FORMATS"><code class="name">var <span class="ident">PRECISION_FORMATS</span> : List[str]</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="coscine.utils.HumanBytes.PRECISION_OFFSETS"><code class="name">var <span class="ident">PRECISION_OFFSETS</span> : List[float]</code></dt>
<dd>
<div class="desc"></div>
</dd>
</dl>
<h3>Static methods</h3>
<dl>
<dt id="coscine.utils.HumanBytes.format"><code class="name flex">
<span>def <span class="ident">format</span></span>(<span>num: Union[int, float], metric: bool = False, precision: int = 1) ‑> str</span>
</code></dt>
<dd>
<div class="desc"><p>Human-readable formatting of bytes, using binary (powers of 1024)
or metric (powers of 1000) representation.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">@staticmethod
def format(num: Union[int, float], metric: bool=False, precision: int=1) -&gt; str:
&#34;&#34;&#34;
Human-readable formatting of bytes, using binary (powers of 1024)
or metric (powers of 1000) representation.
&#34;&#34;&#34;
assert isinstance(num, (int, float)), &#34;num must be an int or float&#34;
assert isinstance(metric, bool), &#34;metric must be a bool&#34;
assert isinstance(precision, int) and precision &gt;= 0 and precision &lt;= 3, &#34;precision must be an int (range 0-3)&#34;
unit_labels = HumanBytes.METRIC_LABELS if metric else HumanBytes.BINARY_LABELS
last_label = unit_labels[-1]
unit_step = 1000 if metric else 1024
unit_step_thresh = unit_step - HumanBytes.PRECISION_OFFSETS[precision]
is_negative = num &lt; 0
if is_negative: # Faster than ternary assignment or always running abs().
num = abs(num)
for unit in unit_labels:
if num &lt; unit_step_thresh:
# VERY IMPORTANT:
# Only accepts the CURRENT unit if we&#39;re BELOW the threshold where
# float rounding behavior would place us into the NEXT unit: F.ex.
# when rounding a float to 1 decimal, any number &#34;&gt;= 1023.95&#34; will
# be rounded to &#34;1024.0&#34;. Obviously we don&#39;t want ugly output such
# as &#34;1024.0 KiB&#34;, since the proper term for that is &#34;1.0 MiB&#34;.
break
if unit != last_label:
# We only shrink the number if we HAVEN&#39;T reached the last unit.
# NOTE: These looped divisions accumulate floating point rounding
# errors, but each new division pushes the rounding errors further
# and further down in the decimals, so it doesn&#39;t matter at all.
num /= unit_step
return HumanBytes.PRECISION_FORMATS[precision].format(&#34;-&#34; if is_negative else &#34;&#34;, num, unit)</code></pre>
</details>
</dd>
</dl>
</dd>
</dl>
</section>
</article>
<nav id="sidebar">
<header>
<a class="homelink" rel="home" title="Coscine Home" href="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk">
<img src="https://git.rwth-aachen.de/coscine/community-features/coscine-python-sdk/-/raw/master/data/coscine_logo_rgb.png" alt="">
</a>
</header>
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="coscine" href="index.html">coscine</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="coscine.utils.HumanBytes" href="#coscine.utils.HumanBytes">HumanBytes</a></code></h4>
<ul class="">
<li><code><a title="coscine.utils.HumanBytes.BINARY_LABELS" href="#coscine.utils.HumanBytes.BINARY_LABELS">BINARY_LABELS</a></code></li>
<li><code><a title="coscine.utils.HumanBytes.METRIC_LABELS" href="#coscine.utils.HumanBytes.METRIC_LABELS">METRIC_LABELS</a></code></li>
<li><code><a title="coscine.utils.HumanBytes.PRECISION_FORMATS" href="#coscine.utils.HumanBytes.PRECISION_FORMATS">PRECISION_FORMATS</a></code></li>
<li><code><a title="coscine.utils.HumanBytes.PRECISION_OFFSETS" href="#coscine.utils.HumanBytes.PRECISION_OFFSETS">PRECISION_OFFSETS</a></code></li>
<li><code><a title="coscine.utils.HumanBytes.format" href="#coscine.utils.HumanBytes.format">format</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
appdirs==1.4.4 appdirs==1.4.4
colorama==0.4.4 colorama==0.4.6
prettytable==2.2.1 prettytable==3.5.0
rdflib==5.0.0 rdflib==6.2.0
requests==2.25.1 requests==2.28.1
requests_toolbelt==0.9.1 requests-toolbelt==0.10.1
setuptools==49.2.1 setuptools==63.2.0
tqdm==4.60.0 tqdm==4.64.1
python-dateutil==2.8.2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment