659
by drtomc
Add a little script for stuffing exercises into the database. |
1 |
import os |
2 |
import pg |
|
3 |
import sys |
|
4 |
||
5 |
from common import db |
|
6 |
||
7 |
if __name__ == "__main__": |
|
8 |
if len(sys.argv) < 2: |
|
9 |
print >> sys.stderr, "usage: %s filename ..." % sys.argv[0] |
|
10 |
print >> sys.stderr, " insert the given filenames as exercises" |
|
11 |
sys.exit(1) |
|
12 |
||
13 |
conn = db.DB() |
|
14 |
for fname in sys.argv[1:]: |
|
15 |
if not os.access(fname, os.R_OK): |
|
16 |
print >> sys.stderr, "No permission to read %s" % fname |
|
17 |
continue
|
|
18 |
spec = open(fname, "r").read() |
|
19 |
||
20 |
fields = {'identifier':fname, 'spec':spec} |
|
21 |
||
22 |
try: |
|
23 |
conn.insert(fields, 'problem', ['identifier', 'spec']) |
|
24 |
except Exception, e: |
|
25 |
print >> sys.stderr, "error inserting %s: %s" % (fname, repr(e)) |
|
26 |
||
27 |