Skip to content

Commit

Permalink
#279 the main logic has been NOT changed! How ever this is some refac…
Browse files Browse the repository at this point in the history
…toring and better logging
  • Loading branch information
kozaka-tv committed Jul 13, 2024
1 parent 93dd085 commit 6f65b82
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
9 changes: 5 additions & 4 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@


@asynccontextmanager
async def lifespan(app: FastAPI):
async def start_servant_app(fast_api: FastAPI):
# noinspection PyAsyncCall
asyncio.create_task(Servant().run())

yield
# Add any logs or commands before shutting down.
print('It is shutting down...')
print('Shutting app server down...')


tags_metadata = [
Expand All @@ -25,7 +26,7 @@ async def lifespan(app: FastAPI):
{"name": "put methods", "description": "Boring"},
]

app = FastAPI(lifespan=lifespan, openapi_tags=tags_metadata)
app = FastAPI(lifespan=start_servant_app, openapi_tags=tags_metadata)
# app.add_middleware(
# CORSMiddleware,
# allow_origins=["*"],
Expand Down
6 changes: 4 additions & 2 deletions tests/utils/test_cmd_line_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ def test_custom_config_and_database():

@patch('sys.argv', ['run.py', '-c', 'custom_config.txt'])
def test_invalid_config_extension():
with pytest.raises(ValueError, match="The configuration file must have a '.ini' extension."):
with pytest.raises(ValueError,
match="The configuration file must end with an '.ini' extension! config: custom_config.txt"):
parse_args()


@patch('sys.argv', ['run.py', '-db', 'custom_servant.txt'])
def test_invalid_database_extension():
with pytest.raises(ValueError, match="The database file must have a '.db' extension."):
with pytest.raises(ValueError,
match="The database file must end with an '.db' extension! database: custom_servant.txt"):
parse_args()
11 changes: 7 additions & 4 deletions utils/cmd_line_parser.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import argparse

DEFAULT_CONFIG_INI = 'config.ini'
DEFAULT_SERVANT_DB = 'servant.db'


def parse_args():
parser = argparse.ArgumentParser(description='Servant script for managing Rocksmith sessions.')
parser.add_argument('-c', '--config', default='config.ini',
parser.add_argument('-c', '--config', default=DEFAULT_CONFIG_INI,
help='Path of the configuration file like: my_config.ini')
parser.add_argument('-db', '--database', default='servant.db',
parser.add_argument('-db', '--database', default=DEFAULT_SERVANT_DB,
help='Path of the database file like: my_database.db')

args = parser.parse_args()

config = args.config
if not config.endswith('.ini'):
raise ValueError("The configuration file must have a '.ini' extension.")
raise ValueError("The configuration file must end with an '.ini' extension! config: " + config)

database = args.database
if not database.endswith('.db'):
raise ValueError("The database file must have a '.db' extension.")
raise ValueError("The database file must end with an '.db' extension! database: " + database)

return config, database

0 comments on commit 6f65b82

Please sign in to comment.