Use config in jogobot.py

Set configparser.interpolation to none to prevent parsing timestamps
This commit is contained in:
2016-02-25 13:48:38 +01:00
parent 027d7d1543
commit b0c844b2de
2 changed files with 9 additions and 9 deletions

View File

@@ -30,7 +30,7 @@ import configparser
import pywikibot import pywikibot
config = configparser.ConfigParser() config = configparser.ConfigParser(interpolation=None)
config.read(pywikibot.config.get_base_dir() + "/jogobot.conf") config.read(pywikibot.config.get_base_dir() + "/jogobot.conf")
# Make jogobot entrys available in root level (without sections) # Make jogobot entrys available in root level (without sections)

View File

@@ -23,6 +23,7 @@
# #
import os import os
import shlex
from datetime import datetime from datetime import datetime
from email.mime.text import MIMEText from email.mime.text import MIMEText
from subprocess import Popen, PIPE, TimeoutExpired from subprocess import Popen, PIPE, TimeoutExpired
@@ -32,7 +33,7 @@ import pywikibot
from pywikibot.bot import( from pywikibot.bot import(
DEBUG, INFO, WARNING, ERROR, CRITICAL, STDOUT, VERBOSE, logoutput ) DEBUG, INFO, WARNING, ERROR, CRITICAL, STDOUT, VERBOSE, logoutput )
import jogobot.config as config from jogobot.config import config
def output( text, level="INFO", decoder=None, newline=True, def output( text, level="INFO", decoder=None, newline=True,
@@ -41,7 +42,7 @@ def output( text, level="INFO", decoder=None, newline=True,
Wrapper for pywikibot output functions Wrapper for pywikibot output functions
""" """
text = datetime.utcnow().strftime( "%Y-%m-%d %H:%M:%S (UTC) " ) + text text = datetime.utcnow().strftime( config["log_timestamp"] ) + " " + text
if ( level.upper() == "STDOUT" ): if ( level.upper() == "STDOUT" ):
_level = STDOUT _level = STDOUT
@@ -102,7 +103,7 @@ pywikibot.output = pywikibot_output
def sendmail( Subject, Body, To=None, CC=None, BCC=None, def sendmail( Subject, Body, To=None, CC=None, BCC=None,
From="JogoBot <tools.jogobot@tools.wmflabs.org>" ): From=config["mail_from"] ):
""" """
Provides a simple wrapper for exim (MTA) on tool labs Provides a simple wrapper for exim (MTA) on tool labs
Params should be formated according related fields in RFC 5322 Params should be formated according related fields in RFC 5322
@@ -143,7 +144,7 @@ def sendmail( Subject, Body, To=None, CC=None, BCC=None,
# We have no local MTA so we need to catch errors and write to file instead # We have no local MTA so we need to catch errors and write to file instead
try: try:
# Send the message via exim # Send the message via exim
with Popen( config.mail_cmd, stdin=PIPE, with Popen( shlex.split(config['mail_cmd']), stdin=PIPE,
universal_newlines=True ) as MTA: universal_newlines=True ) as MTA:
MTA.communicate(msg.as_string()) MTA.communicate(msg.as_string())
@@ -164,9 +165,9 @@ def sendmail( Subject, Body, To=None, CC=None, BCC=None,
except FileNotFoundError: except FileNotFoundError:
# Local fallback # Local fallback
with open( config.bot_dir + "/Mail.txt", "a" ) as mail: with open( config["dir"] + "/Mail.txt", "a" ) as mail:
mail.write( "\n\n" ) mail.write( "\n\n" )
mail.write( datetime.utcnow().strftime( "%Y-%m-%d %H:%M:%S (UTC)")) mail.write( datetime.utcnow().strftime( config["log_timestamp"]))
mail.write( "\n" + msg.as_string() ) mail.write( "\n" + msg.as_string() )
@@ -218,8 +219,7 @@ class StatusAPI:
self.site = pywikibot.Site() self.site = pywikibot.Site()
# We need the shell working directory # We need the shell working directory
self.cwd = "/home/joni/GOLDERWEB/Daten/Projekte/" +\ self.cwd = config["dir"]
"05_Wikimedia/62_BOT/bot"
def is_disabled_on_wiki( self, task_slug=None ): def is_disabled_on_wiki( self, task_slug=None ):
""" """