mirror of
https://github.com/postgres/pgweb.git
synced 2025-07-25 16:02:27 +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:
@ -8,15 +8,9 @@ import tarfile
|
||||
import re
|
||||
import tidy
|
||||
from optparse import OptionParser
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
|
||||
# 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
|
||||
import psycopg2
|
||||
|
||||
pagecount = 0
|
||||
quiet = False
|
||||
@ -68,12 +62,17 @@ quiet = options.quiet
|
||||
ver = sys.argv[1]
|
||||
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):
|
||||
print "File %s not found" % tarfilename
|
||||
sys.exit(1)
|
||||
|
||||
tf = tarfile.open(tarfilename)
|
||||
|
||||
connection = psycopg2.connect(config.get('db', 'dsn'))
|
||||
|
||||
curs = connection.cursor()
|
||||
# Verify that the version exists, and what we're loading
|
||||
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:
|
||||
curs.execute("SELECT varnish_purge('^/docs/current/')")
|
||||
|
||||
transaction.commit_unless_managed()
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
if not quiet: print "Done (%i pages)." % pagecount
|
||||
|
Reference in New Issue
Block a user