blob: 580781731b6499b93d977e1b7164a2d484e51e3d [file] [log] [blame]
fmenozzib4f254e2016-06-28 14:03:03 -07001#!/usr/bin/env python
2#
fmenozzi7f2c85e2016-07-12 09:17:39 -07003# Copyright 2016 Google Inc.
fmenozzib4f254e2016-06-28 14:03:03 -07004#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8import argparse
9import sqlite3
10
11def create_database(inpath, outpath):
12 with sqlite3.connect(outpath) as conn:
13 c = conn.cursor();
14 c.execute('''CREATE TABLE IF NOT EXISTS gradients (
fmenozzif023e682016-07-18 08:20:06 -070015 FileName TEXT,
fmenozzi7f2c85e2016-07-12 09:17:39 -070016 ColorCount INTEGER,
17 GradientType TEXT,
18 TileMode TEXT,
19 EvenlySpaced INTEGER,
20 HardStopCount INTEGER,
fmenozzi016e51f2016-07-14 07:44:50 -070021 Verb TEXT,
fmenozzid876a4b2016-07-18 13:33:37 -070022 BoundsWidth INTEGER,
23 BoundsHeight INTEGER,
fmenozzi7f2c85e2016-07-12 09:17:39 -070024 Positions TEXT
fmenozzib4f254e2016-06-28 14:03:03 -070025 )''');
26 c.execute("DELETE FROM gradients");
27
28 with open(inpath, "r") as results:
29 gradients = []
30 for line in [line.strip() for line in results]:
31 gradients.append(line.split());
32
fmenozzif023e682016-07-18 08:20:06 -070033 c.executemany(
fmenozzid876a4b2016-07-18 13:33:37 -070034 "INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
fmenozzif023e682016-07-18 08:20:06 -070035 gradients);
fmenozzib4f254e2016-06-28 14:03:03 -070036
37 conn.commit();
38
39
40if __name__ == "__main__":
41 parser = argparse.ArgumentParser(
42 description = "Transform Lua script output to a SQL DB");
43 parser.add_argument("inpath", help="Path to Lua script output file");
44 parser.add_argument("outpath", help="Path to SQL DB");
45 args = parser.parse_args();
46
47 create_database(args.inpath, args.outpath);