Mercurial > hg > rlgallery-misc
view py/setupdb.py @ 74:900da50ee11c
Merge lighttpd configuration into one include file.
The lighttpd configuration was previously spread across several files
which were intended to overwrite the defaults. They often became
outdated.
Now all customization is in lighttpd/rlgallery.conf, which should be
included at the end of whatever main lighttpd configuration file is in
use. It should require minimal updates for new lighttpd versions or
distribution changes.
author | John "Elwin" Edwards |
---|---|
date | Wed, 28 Dec 2016 13:12:04 -0500 |
parents | e1de8aeb5ed4 |
children |
line wrap: on
line source
#!/usr/bin/python3 # setupdb.py: initializes the database tables used by the rlg system. import rlgall import psycopg2 webuser = "webserver" allowquery = "GRANT SELECT ON {0} TO " + webuser + ";" dbconn = psycopg2.connect("dbname=rlg") dbcur = dbconn.cursor() dbcur.execute("CREATE TABLE games ( gname varchar(20), offbytes int );") dbcur.execute("CREATE TABLE players (pname text PRIMARY KEY);") dbconn.commit() for game in rlgall.gamelist: dbcur.execute("INSERT INTO games VALUES (%s, %s);", (game.uname, 0)) createquery = "CREATE TABLE " + game.uname + " ( " for i, field in enumerate(game.sqltypes.keys()): createquery += "{0} {1}".format(field, game.sqltypes[field]) if field == "name": createquery += " REFERENCES players(pname)" if i == len(game.sqltypes) - 1: createquery += " )" else: createquery += ", " createquery += ";" #print createquery dbcur.execute(createquery) dbcur.execute(allowquery.format(game.uname)) dbconn.commit() dbcur.close() dbconn.close() exit()