Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • ec325a8
  • /
  • scripts
  • /
  • _validators.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:58d56c1d9b9aa6237de9d1552e6ea4701c6b0256
directory badge
swh:1:dir:13c996cc896df00c72ea79a948959f08af0c56d5

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
_validators.py
"""
byceps.scripts.validators
~~~~~~~~~~~~~~~~~~~~~~~~~

Validators for use with Click_.

.. _Click: https://click.palletsprojects.com/

:Copyright: 2014-2025 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from uuid import UUID

import click

from byceps.services.brand import brand_service
from byceps.services.brand.models import Brand, BrandID
from byceps.services.party import party_service
from byceps.services.party.models import Party, PartyID
from byceps.services.site import site_service
from byceps.services.site.models import Site, SiteID
from byceps.services.user import user_service
from byceps.services.user.models.user import User, UserID


def validate_brand(ctx, param, brand_id: BrandID) -> Brand:
    brand = brand_service.find_brand(brand_id)

    if not brand:
        raise click.BadParameter(f'Unknown brand ID "{brand_id}".')

    return brand


def validate_party(ctx, param, party_id_value: str) -> Party:
    party = party_service.find_party(PartyID(party_id_value))

    if not party:
        raise click.BadParameter(f'Unknown party ID "{party_id_value}".')

    return party


def validate_site(ctx, param, site_id_value: str) -> Site:
    site = site_service.find_site(SiteID(site_id_value))

    if not site:
        raise click.BadParameter(f'Unknown site ID "{site_id_value}".')

    return site


def validate_user_id(ctx, param, user_id_value: str) -> User:
    user_id = validate_user_id_format(ctx, param, user_id_value)

    user = user_service.find_user(user_id)

    if not user:
        raise click.BadParameter(f'Unknown user ID "{user_id}".')

    return user


def validate_user_id_format(ctx, param, user_id_value: str) -> UserID:
    try:
        return UserID(UUID(user_id_value))
    except ValueError as exc:
        raise click.BadParameter(
            f'Invalid user ID "{user_id_value}": {exc}'
        ) from exc


def validate_user_screen_name(ctx, param, screen_name: str) -> User:
    user = user_service.find_user_by_screen_name(screen_name)

    if not user:
        raise click.BadParameter(f'Unknown user screen name "{screen_name}".')

    return user

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API