diff --git a/poi-backup-and-restore/README.md b/poi-backup-and-restore/README.md new file mode 100644 index 0000000..ab0f3c2 --- /dev/null +++ b/poi-backup-and-restore/README.md @@ -0,0 +1,39 @@ +# RailTrail POI Backup + +This application creates and restores backups of the Points of Interest that are +present in RailTrail. To do that, it simulates a client and requests a list of +all Points of Interest. + +## Requirements + +This tool is written in Python. The minimum supported Python version is 3.10. +To install the required libraries, execute `pip install -r requirements.txt`. +We recommend that you do that in a [virtual environment](https://docs.python.org/3/library/venv.html). + +## Usage + +### Backup + +To create a backup, simply run `python src/main.py backup `, +where ```` is the name of the file where the backup should be +written to. If the filename is not present, the backup will be written to the +standard output instead. + +This will ask you for the backend URI, and a username and password. You can also +provide these values by command line arguments. Remember that providing a password +this way has security implications. + +For a full reference of valid command line options, run `python src/main.py backup --help`. + +### Restore + +To restore a backup, simply run `python src/main.py restore `, +where ```` is the name of the file where the backup should be +read from. If the filename is not present, the program will attempt to read from +stdin instead. + +This will ask you for the backend URI, and a username and password. You can also +provide these values by command line arguments. Remember that providing a password +this way has security implications. + +For a full reference of valid command line options, run `python src/main.py restore --help`. diff --git a/poi-backup-and-restore/src/main.py b/poi-backup-and-restore/src/main.py index cd08eb9..fafc2ab 100644 --- a/poi-backup-and-restore/src/main.py +++ b/poi-backup-and-restore/src/main.py @@ -45,7 +45,7 @@ def backup( )], username: Annotated[str, typer.Option(prompt=True)], password: Annotated[str, typer.Option(prompt=True, hide_input=True)], - indent: Optional[int] = None, + indent: Annotated[Optional[int], typer.Option(help="The number of spaces that the produced JSON should be indented by. Will activate pretty printing of the JSON when present")] = None, file: Annotated[Optional[str], typer.Argument( show_default="STDOUT")] = None ): @@ -110,6 +110,9 @@ def restore( file: Annotated[Optional[str], typer.Argument( show_default="STDIN")] = None ): + """ + Restores a backup of POIs to a given instance of RailTrail + """ source_file = open(file, 'r', encoding='utf8') if file else stdin with source_file: data = BackupFormat.model_validate_json(source_file.read()) diff --git a/poi-backup-and-restore/src/model.py b/poi-backup-and-restore/src/model.py index 16c48ea..25b53ff 100644 --- a/poi-backup-and-restore/src/model.py +++ b/poi-backup-and-restore/src/model.py @@ -1,5 +1,5 @@ from enum import IntEnum -from typing import Annotated +from typing_extensions import Annotated from annotated_types import Interval from pydantic import BaseModel, NonNegativeInt, StrictBool