Latest release: 0.1.1 (2025-10-02)
lockss-pybasic provides basic utilities for various LOCKSS projects written in Python.
lockss.pybasic.cliutilCommand line utilities.
BaseCliis a base class for command line interfaces that uses pydantic-argparse to define arguments and subcommands, and rich-argparse to display help messages. For each commandx-y-zinduced by apydantic-argparsefield namedx_y_zderiving fromBaseModel, thedispatch()method expects a method named_x_y_z.StringCommandprovides a pydantic-argparse way to define a subcommand whose only purpose is printing a string, withCOPYRIGHT_DESCRIPTION,LICENSE_DESCRIPTIONandVERSION_DESCRIPTIONconstants provided for convenience. Example:class MyCliModel(BaseModel): copyright: Optional[StringCommand.type(my_copyright_string)] = Field(description=COPYRIGHT_DESCRIPTION)
at_most_one_from_enumandget_from_enumprovide a facility for defining a pydantic-argparse model that defines one command line option per constant of anEnum, using anenumkeyword argument in theFielddefinition. Example:class Orientation(Enum): horizontal = 1 vertical = 2 diagonal = 3 DEFAULT_ORIENTATION = Orientation.horizontal class MyCliModel(BaseModel): diagonal: Optional[bool] = Field(False, description='display diagonally', enum=Orientation) horizontal: Optional[bool] = Field(False, description='display horizontally', enum=Orientation) unrelated: Optional[bool] = Field(...) vertical: Optional[bool] = Field(False, description='display vertically', enum=Orientation) @root_validator def _at_most_one_orientation(cls, values): return at_most_one_from_enum(cls, values, Orientation) def get_orientation(self) -> Orientation: return get_from_enum(self, Orientation, DEFAULT_ORIENTATION)
lockss.pybasic.errorutilError and exception utilities.
InternalErroris a no-arg subclass ofRuntimeError.
lockss.pybasic.fileutilFile and path utilities.
file_linesreturns the non-empty lines of a file stripped of comments that begin with#and run to the end of a line.pathtakes a string orPurePathand returns aPathfor whichPath.expanduser()andPath.resolve()have been called.
lockss.pybasic.outpututilUtilities to work with tabulate.
OutputFormatis anEnumof all the output formats fromtabulate.tabulate_formats.OutputFormatOptionsdefines a pydantic-argparse model for setting an output format fromOutputFormat.
See CHANGELOG.rst.