pycldf.cli_util

Functionality to use in commandline tools which need to access CLDF datasets.

class pycldf.cli_util.FlagOrPathType(must_exist=True, type=None)[source]

Argument type allowing input of a path or a boolean.

The boolean can be used to determine whether to download a file from a known location.

Parameters:
  • must_exist (bool) –

  • type (typing.Optional[str]) –

class pycldf.cli_util.UrlOrPathType(must_exist=True, type=None)[source]

Type suitable for argparse arguments, allowing input of URL or local file path.

Parameters:
  • must_exist (bool) –

  • type (typing.Optional[str]) –

pycldf.cli_util.add_catalog_spec(parser, name)[source]

Add CLI arguments suitable to specify a catalog.

Parameters:
  • parser (argparse.ArgumentParser) –

  • name (str) –

Return type:

None

pycldf.cli_util.add_database(parser, must_exist=True)[source]

Add CLI arguments to specify a CLDF SQLite database.

Retrieve in the run function of a command using get_database (see below).

Parameters:
  • parser (argparse.ArgumentParser) –

  • must_exist (bool) –

Return type:

None

pycldf.cli_util.add_dataset(parser)[source]

Adds a positional argument named dataset to the parser to specify a CLDF dataset.

Parameters:

parser (argparse.ArgumentParser) –

Return type:

None

pycldf.cli_util.get_database(args)[source]

Retrieve a Database instance based on CLI input in args (see add_database).

Parameters:

args (argparse.Namespace) –

Return type:

pycldf.db.Database

pycldf.cli_util.get_dataset(args)[source]

Uses the dataset specification in args to return a corresponding Dataset instance.

Parameters:

args (argparse.Namespace) –

Return type:

pycldf.dataset.Dataset

pycldf.cli_util.strtobool(val)[source]

Convert a string representation of truth to true (1) or false (0).

True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’. Raises ValueError if ‘val’ is anything else.

Parameters:

val (str) –

Return type:

int