From ef3ccc8d104271644a10a6d7eacd0d9d6d4acfc0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 9 Oct 2018 19:40:26 +0200 Subject: [PATCH] fix use of new database for sendreport et al --- .gitignore | 1 + process/CMakeLists.txt | 4 ++-- process/epasswd.py | 2 +- process/getemail.py | 22 ++++++++++++++++++++++ process/sendreport.sh | 12 ++++-------- 5 files changed, 30 insertions(+), 11 deletions(-) create mode 100755 process/getemail.py diff --git a/.gitignore b/.gitignore index 3dcf24224..75ec9a227 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ ipch/ *.user *~ +*.pyc *.bak bin/ build*/ diff --git a/process/CMakeLists.txt b/process/CMakeLists.txt index 0ffb7b4a2..bbd9b8c38 100644 --- a/process/CMakeLists.txt +++ b/process/CMakeLists.txt @@ -1,7 +1,7 @@ install(PROGRAMS create-orders backup-eressea run-turn send-zip-report send-bz2-report compress.py compress.sh epasswd.py orders-process -process-orders.py accept-orders.py -checkpasswd.py sendreport.sh sendreports.sh orders-accept DESTINATION bin) +process-orders.py accept-orders.py getemail.py checkpasswd.py +sendreport.sh sendreports.sh orders-accept DESTINATION bin) install(DIRECTORY cron/ DESTINATION bin USE_SOURCE_PERMISSIONS FILES_MATCHING PATTERN "*.cron") diff --git a/process/epasswd.py b/process/epasswd.py index 4798967a9..4cac6e1ce 100755 --- a/process/epasswd.py +++ b/process/epasswd.py @@ -35,7 +35,7 @@ class EPasswd: def __init__(self): self.data = {} - def set_data(no, email, passwd): + def set_data(self, no, email, passwd): lc_id = lower(no) self.data[lc_id] = {} self.data[lc_id]["id"] = no diff --git a/process/getemail.py b/process/getemail.py new file mode 100755 index 000000000..d9951bcb0 --- /dev/null +++ b/process/getemail.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +import sys, re +from epasswd import EPasswd + +if len(sys.argv)<3: + sys.exit(-2) + +filename=sys.argv[1] +myfaction=sys.argv[2] + +pw_data = EPasswd() +try: + pw_data.load_database(filename) +except: + pw_data.load_file(filename) + +if pw_data.fac_exists(myfaction): + email = pw_data.get_email(myfaction) + print(email) + sys.exit(0) +sys.exit(-1) diff --git a/process/sendreport.sh b/process/sendreport.sh index d8fe79d47..7b1afccf0 100755 --- a/process/sendreport.sh +++ b/process/sendreport.sh @@ -45,12 +45,8 @@ fi bash "${FACTION}.sh" "$EMAIL" || reply "Unbekannte Partei $FACTION" -if [ -e "$ERESSEA/game-$GAME/eressea.db" ]; then - SQL="select email from faction f left join faction_data fd on fd.faction_id=f.id where f.game_id=$GAME AND fd.code='$FACTION' and fd.turn=(select max(turn) from faction_data fx where fx.faction_id=f.id)" - OWNER=$(sqlite3 "$ERESSEA/game-$GAME/eressea.db" "$SQL") - if [ ! -z "$OWNER" ]; then - echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \ - | mutt -s "Reportnachforderung Partei ${FACTION}" "$OWNER" - fi +OWNER=$(getfaction.py "$PWFILE" "$FACTION") +if [ ! -z "$OWNER" ]; then + echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \ + | mutt -s "Reportnachforderung Partei ${FACTION}" "$OWNER" fi -