Skip to content

Commit

Permalink
Adds db_location script.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsharf committed Jul 8, 2023
1 parent 4950dd1 commit 8e4cfe1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/cb2game/server/db_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Utility to locate the database file used by a CB2 instance.
Run with:
```
python3 -m cb2game.server.db_location --config_filepath="path/to/config.yaml"
```
"""

import logging
import os
import sys

import fire

from cb2game.server.config.config import Config, ReadConfigOrDie

logger = logging.getLogger(__name__)


def main(config_filepath: str = ""):
"""Locate the database file used by a CB2 instance.
Args:
config_filepath: Path to the config file used by the CB2 instance.
"""
logging.basicConfig(level=logging.INFO)

if config_filepath == "":
config = Config()
logger.info(
f"Showing location of default database. Specify --config_filepath to see the location for a specific config."
)
else:
if not os.path.exists(config_filepath):
logger.error(f"Provided config file does not exist: {config_filepath}")
sys.exit(1)
config = ReadConfigOrDie(config_filepath)
print(f"Database path: {config.database_path()}")


if __name__ == "__main__":
fire.Fire(main)

0 comments on commit 8e4cfe1

Please sign in to comment.