summaryrefslogtreecommitdiff
path: root/loader/purge_frontend_message.py
blob: 6f051b7d4b47bb231b67785cad8039615016cc0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
#
# purge_frontend_message.py - issue varnish purge for the message
# in question, to for example force an expire of a hidden message.
#

import os
import sys

from optparse import OptionParser
from configparser import ConfigParser

import psycopg2

from lib.varnish import VarnishPurger

if __name__ == "__main__":
    optparser = OptionParser()
    optparser.add_option('-m', '--msgid', dest='msgid', help='Messageid to load')

    (opt, args) = optparser.parse_args()

    if (len(args)):
        print("No bare arguments accepted")
        optparser.print_help()
        sys.exit(1)

    if not opt.msgid:
        print("Message-id must be specified")
        optparser.print_help()
        sys.exit(1)

    cfg = ConfigParser()
    cfg.read('%s/archives.ini' % os.path.realpath(os.path.dirname(sys.argv[0])))
    try:
        connstr = cfg.get('db', 'connstr')
    except Exception:
        connstr = 'need_connstr'

    conn = psycopg2.connect(connstr)
    curs = conn.cursor()

    curs.execute("SELECT id, threadid FROM messages WHERE messageid=%(msgid)s", {
        'msgid': opt.msgid,
    })
    id, threadid = curs.fetchone()

    VarnishPurger(cfg).purge([int(threadid), ])
    conn.close()