support db password in config file

This commit is contained in:
Maximilian Keßler 2023-07-05 20:59:20 +02:00
parent 967daf1914
commit 37a342e63d
Signed by: max
GPG key ID: BCC5A619923C0BA5
3 changed files with 6 additions and 4 deletions

View file

@ -67,7 +67,7 @@ def subcommand_download(
): ):
if game_id is not None: if game_id is not None:
download_data.detailed_export_game(game_id) download_data.detailed_export_game(game_id)
logger.info("Successfully exported game ") logger.info("Successfully exported game {}".format(game_id))
if variant_id is not None: if variant_id is not None:
download_data.download_games(variant_id, export_all) download_data.download_games(variant_id, export_all)
logger.info("Successfully exported games for variant id {}".format(variant_id)) logger.info("Successfully exported games for variant id {}".format(variant_id))

View file

@ -46,6 +46,7 @@ class DBConnectionManager:
self.config_file = Path(platformdirs.user_config_dir(constants.APP_NAME, ensure_exists=True)) / 'config.yaml' self.config_file = Path(platformdirs.user_config_dir(constants.APP_NAME, ensure_exists=True)) / 'config.yaml'
self.db_name: str = constants.DEFAULT_DB_NAME self.db_name: str = constants.DEFAULT_DB_NAME
self.db_user: str = constants.DEFAULT_DB_USER self.db_user: str = constants.DEFAULT_DB_USER
self.db_pass: Optional[str] = None
def read_config(self): def read_config(self):
logger.debug("DB connection configuration read from {}".format(self.config_file)) logger.debug("DB connection configuration read from {}".format(self.config_file))
@ -54,6 +55,7 @@ class DBConnectionManager:
config = yaml.safe_load(f) config = yaml.safe_load(f)
self.db_name = config.get('dbname', None) self.db_name = config.get('dbname', None)
self.db_user = config.get('dbuser', None) self.db_user = config.get('dbuser', None)
self.db_pass = config.get('dbpass', None)
if self.db_name is None: if self.db_name is None:
logger.verbose("Falling back to default database name {}".format(constants.DEFAULT_DB_NAME)) logger.verbose("Falling back to default database name {}".format(constants.DEFAULT_DB_NAME))
self.db_name = constants.DEFAULT_DB_NAME self.db_name = constants.DEFAULT_DB_NAME
@ -76,7 +78,8 @@ class DBConnectionManager:
raise FileExistsError("Configuration file already exists, not overriding.") raise FileExistsError("Configuration file already exists, not overriding.")
self.config_file.write_text( self.config_file.write_text(
"dbname: {}\n" "dbname: {}\n"
"dbuser: {}".format( "dbuser: {}\n"
"dbpass: null".format(
constants.DEFAULT_DB_NAME, constants.DEFAULT_DB_NAME,
constants.DEFAULT_DB_USER constants.DEFAULT_DB_USER
) )
@ -84,7 +87,7 @@ class DBConnectionManager:
logger.info("Initialised default config file {}".format(self.config_file)) logger.info("Initialised default config file {}".format(self.config_file))
def connect(self): def connect(self):
conn = psycopg2.connect("dbname={} user={}".format(self.db_name, self.db_user)) conn = psycopg2.connect("dbname={} user={}".format(self.db_name, self.db_user, self.db_pass))
cur = conn.cursor() cur = conn.cursor()
self.lazy_conn.set_conn(conn) self.lazy_conn.set_conn(conn)
self.lazy_cur.set_cur(cur) self.lazy_cur.set_cur(cur)

View file

@ -122,7 +122,6 @@ def detailed_export_game(
), ),
starting_player starting_player
) )
print(game.instance.hand_size, game.instance.num_players)
for action in actions: for action in actions:
game.make_action(action) game.make_action(action)
score = game.score score = game.score