util: add check if purging is enabled

Change-Id: I90cc2062513abec1ec947fc0adb4c3da9d125784
Signed-off-by: SJ <sj@acts.hu>
This commit is contained in:
SJ 2017-05-15 19:57:07 +02:00
parent f69e3cdc42
commit 1e5858179e

View File

@ -35,6 +35,18 @@ def read_options(filename="", opts={}):
opts['server_id'] = "%02x" % config.getint('piler', 'server_id') opts['server_id'] = "%02x" % config.getint('piler', 'server_id')
def is_purge_enabled(opts={}):
cursor = opts['db'].cursor()
cursor.execute("SELECT `value` FROM `option` WHERE `key`='enable_purge'")
row = cursor.fetchone()
if row and row[0] == '1':
return True
return False
def purge_m_files(ids=[], opts={}): def purge_m_files(ids=[], opts={}):
if len(ids) > 0: if len(ids) > 0:
remove_m_files(ids, opts) remove_m_files(ids, opts)
@ -187,6 +199,10 @@ def main():
opts['db'] = dbapi.connect("localhost", opts['username'], opts['db'] = dbapi.connect("localhost", opts['username'],
opts['password'], opts['database']) opts['password'], opts['database'])
if is_purge_enabled(opts) is False:
syslog.syslog("Purging emails is disabled")
sys.exit(1)
cursor = opts['db'].cursor() cursor = opts['db'].cursor()
cursor.execute(SQL_PURGE_SELECT_QUERY) cursor.execute(SQL_PURGE_SELECT_QUERY)