diff options
author | Rob Austein <sra@hactrn.net> | 2011-10-19 00:33:20 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2011-10-19 00:33:20 +0000 |
commit | 4175936042112fb797481dc5a23a153572f08b8b (patch) | |
tree | 6a31c56d71e547e0b70c84a72ac737243aed4d81 /rpkid/rpki-sql-setup.py | |
parent | e35e9b57df45c8dc8ef00f43efc3c0e0b6ab88c7 (diff) |
Wrap SQL schemas up so rpki-sql-setup doesn't have to be run in the
build tree (see #8). This appears to work properly but needs more
testing, leaving ticket open for now.
Also cleaned up a few things that should have moved from scripts/ to
buildtools/ a long time ago.
svn path=/trunk/; revision=4056
Diffstat (limited to 'rpkid/rpki-sql-setup.py')
-rw-r--r-- | rpkid/rpki-sql-setup.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/rpkid/rpki-sql-setup.py b/rpkid/rpki-sql-setup.py index 7e4abec6..051f6980 100644 --- a/rpkid/rpki-sql-setup.py +++ b/rpkid/rpki-sql-setup.py @@ -21,21 +21,19 @@ PERFORMANCE OF THIS SOFTWARE. import os, getopt, sys, rpki.config, getpass, warnings -from rpki.mysql_import import MySQLdb +import rpki.sql_schemas -schema_dir = os.path.normpath(sys.path[0]) +from rpki.mysql_import import MySQLdb -def read_schema(filename): +def read_schema(name): """ Convert an SQL file into a list of SQL statements. """ lines = [] - f = open(filename) - for line in f: + for line in getattr(rpki.sql_schemas, name).splitlines(): line = " ".join(line.split()) if line and not line.startswith("--"): lines.append(line) - f.close() return [statement.strip() for statement in " ".join(lines).rstrip(";").split(";")] def sql_setup(name): @@ -45,7 +43,7 @@ def sql_setup(name): database = cfg.get("sql-database", section = name) username = cfg.get("sql-username", section = name) password = cfg.get("sql-password", section = name) - schema = read_schema(os.path.join(schema_dir, "%s.sql" % name)) + schema = read_schema(name) print "Creating database", database cur = rootdb.cursor() |