Pylint (3) + tests
This commit is contained in:
parent
86ecf555fd
commit
7b4c677eae
4
bot.py
4
bot.py
|
@ -2,6 +2,8 @@
|
|||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
"Main bot module."
|
||||
|
||||
import time
|
||||
import ast
|
||||
import datetime as dt
|
||||
|
@ -1437,7 +1439,7 @@ def process1():
|
|||
|
||||
def process2():
|
||||
"The process updates duty order for every forum once a `period` seconds."
|
||||
period = int(config['settings']['notify_period'])
|
||||
period = int(config["settings"]["notify_period"])
|
||||
prev_time = time.time()
|
||||
while True:
|
||||
cur_time = time.time()
|
||||
|
|
|
@ -9,3 +9,14 @@ import configparser
|
|||
CONFIG_FILENAME = "config.ini"
|
||||
config = configparser.ConfigParser()
|
||||
config.read(CONFIG_FILENAME)
|
||||
|
||||
def check_field(field: str, t: type):
|
||||
"Checks if the config field does exist and has the correct type."
|
||||
a = config
|
||||
for i in field.split('.'):
|
||||
a = a[i]
|
||||
a = t(a)
|
||||
|
||||
check_field("tokens.prod", str)
|
||||
check_field("tokens.devel", str)
|
||||
check_field("settings.notify_period", int)
|
||||
|
|
37
main.py
37
main.py
|
@ -2,35 +2,46 @@
|
|||
#
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
"Executable with autoupdate. Only runs bot module."
|
||||
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
proc = None
|
||||
|
||||
def stop():
|
||||
global proc
|
||||
os.kill(proc.pid, signal.SIGTERM)
|
||||
class Runner:
|
||||
"Runs optimized bot script."
|
||||
__proc = None
|
||||
|
||||
def start():
|
||||
global proc
|
||||
proc = subprocess.Popen(["python", "-OO", "bot.py"])
|
||||
def stop(self):
|
||||
"Stop the script."
|
||||
os.kill(self.__proc.pid, signal.SIGTERM)
|
||||
|
||||
def start(self):
|
||||
"Start the script."
|
||||
self.__proc = subprocess.Popen(["python", "-OO", "bot.py"])
|
||||
|
||||
|
||||
bot_runner = Runner()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
branch = os.popen("git rev-parse --abbrev-ref HEAD").read()[:-1]
|
||||
print("Starting")
|
||||
start()
|
||||
bot_runner.start()
|
||||
while True:
|
||||
print("Updater")
|
||||
os.system("git fetch --quiet")
|
||||
if os.popen("git log " + branch + "..origin/" + branch + " --oneline").read().strip() != '':
|
||||
if (
|
||||
os.popen("git log " + branch + "..origin/" + branch + " --oneline")
|
||||
.read()
|
||||
.strip()
|
||||
!= ""
|
||||
):
|
||||
print("Updating")
|
||||
stop()
|
||||
bot_runner.stop()
|
||||
os.system("git pull --quiet")
|
||||
os.system("git gc --quiet --aggressive --prune=all")
|
||||
start()
|
||||
bot_runner.start()
|
||||
time.sleep(60 * 60 * 1)
|
||||
|
|
Loading…
Reference in New Issue