mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-01 15:54:53 +00:00
Go back to using direct psycopg2 for docs loading
This removes the dependency on django from docload, facilitating incremental upgrades of the infrastructure. This now requires a new docload.ini file in the tools/docs directory, with a section "db" and a setting "dsn".
This commit is contained in:
1
tools/docs/.gitignore
vendored
Normal file
1
tools/docs/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
docload.ini
|
@ -8,15 +8,9 @@ import tarfile
|
|||||||
import re
|
import re
|
||||||
import tidy
|
import tidy
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
from ConfigParser import ConfigParser
|
||||||
|
|
||||||
|
import psycopg2
|
||||||
# Set up for accessing django
|
|
||||||
from django.core.management import setup_environ
|
|
||||||
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), '../../pgweb'))
|
|
||||||
import settings
|
|
||||||
setup_environ(settings)
|
|
||||||
|
|
||||||
from django.db import connection, transaction
|
|
||||||
|
|
||||||
pagecount = 0
|
pagecount = 0
|
||||||
quiet = False
|
quiet = False
|
||||||
@ -68,12 +62,17 @@ quiet = options.quiet
|
|||||||
ver = sys.argv[1]
|
ver = sys.argv[1]
|
||||||
tarfilename = sys.argv[2]
|
tarfilename = sys.argv[2]
|
||||||
|
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'docload.ini'))
|
||||||
|
|
||||||
if not os.path.isfile(tarfilename):
|
if not os.path.isfile(tarfilename):
|
||||||
print "File %s not found" % tarfilename
|
print "File %s not found" % tarfilename
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
tf = tarfile.open(tarfilename)
|
tf = tarfile.open(tarfilename)
|
||||||
|
|
||||||
|
connection = psycopg2.connect(config.get('db', 'dsn'))
|
||||||
|
|
||||||
curs = connection.cursor()
|
curs = connection.cursor()
|
||||||
# Verify that the version exists, and what we're loading
|
# Verify that the version exists, and what we're loading
|
||||||
curs.execute("SELECT current FROM core_version WHERE tree=%(v)s", {'v': ver})
|
curs.execute("SELECT current FROM core_version WHERE tree=%(v)s", {'v': ver})
|
||||||
@ -118,7 +117,7 @@ curs.execute("SELECT varnish_purge('^/docs/' || %(v)s || '/')", {'v': ver})
|
|||||||
if iscurrent:
|
if iscurrent:
|
||||||
curs.execute("SELECT varnish_purge('^/docs/current/')")
|
curs.execute("SELECT varnish_purge('^/docs/current/')")
|
||||||
|
|
||||||
transaction.commit_unless_managed()
|
connection.commit()
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
if not quiet: print "Done (%i pages)." % pagecount
|
if not quiet: print "Done (%i pages)." % pagecount
|
||||||
|
Reference in New Issue
Block a user