mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-03 15:38:59 +00:00

For /media/ changes, generate a classic purge based on the URL. For anything tha'ts not templates *or* media, just don't generate any purges at all (of course).
41 lines
1.1 KiB
Python
Executable File
41 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python
|
|
#
|
|
# This hook script is run by gitdeployer when the code is
|
|
# deployed to a server. figure out which templates have been
|
|
# modified and queue automatic purges for them.
|
|
# Gitdeployer will pass a list of all modified files on
|
|
# stdin.
|
|
|
|
import sys
|
|
import os
|
|
import hashlib
|
|
from ConfigParser import ConfigParser
|
|
import psycopg2
|
|
|
|
# Templates that we don't want to ban automatically
|
|
BANNED_TEMPLATES=(
|
|
'base/base.html',
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
config = ConfigParser()
|
|
config.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'purgehook.ini'))
|
|
conn = psycopg2.connect(config.get('db', 'dsn'))
|
|
curs = conn.cursor()
|
|
|
|
for l in sys.stdin:
|
|
if l.startswith('templates/'):
|
|
tmpl = l[len('templates/'):].strip()
|
|
if not tmpl in BANNED_TEMPLATES:
|
|
curs.execute("SELECT varnish_purge_xkey(%(key)s)", {
|
|
'key': 'pgwt_{0}'.format(hashlib.md5(tmpl).hexdigest()),
|
|
})
|
|
elif l.startswith('media/'):
|
|
# For media we can't xkey, but the URL is exact so we can
|
|
# use a classic single-url purge.
|
|
curs.execute("SELECT varnish_purge('^/' || %(u)s || '$')", {
|
|
'u': l.strip(),
|
|
})
|
|
conn.commit()
|
|
conn.close()
|