Skip to content

Commit

Permalink
Added README for POI backup
Browse files Browse the repository at this point in the history
  • Loading branch information
n1kPLV committed Sep 27, 2023
1 parent 67064bf commit b7e5a61
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
39 changes: 39 additions & 0 deletions poi-backup-and-restore/README.md
Original file line number Diff line number Diff line change
@@ -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 <backup_file.json>`,
where ``<backup_file.json>`` 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 <backup_file.json>`,
where ``<backup_file.json>`` 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`.
5 changes: 4 additions & 1 deletion poi-backup-and-restore/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion poi-backup-and-restore/src/model.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit b7e5a61

Please sign in to comment.