blob: 0fa4c49775d3c09d8a380461bfc6ad19982e14cd [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 (
fmenozzi7f2c85e2016-07-12 09:17:39 -070015 ColorCount INTEGER,
16 GradientType TEXT,
17 TileMode TEXT,
18 EvenlySpaced INTEGER,
19 HardStopCount INTEGER,
fmenozzi016e51f2016-07-14 07:44:50 -070020 Verb TEXT,
fmenozzi7f2c85e2016-07-12 09:17:39 -070021 Positions TEXT
fmenozzib4f254e2016-06-28 14:03:03 -070022 )''');
23 c.execute("DELETE FROM gradients");
24
25 with open(inpath, "r") as results:
26 gradients = []
27 for line in [line.strip() for line in results]:
28 gradients.append(line.split());
29
fmenozzi016e51f2016-07-14 07:44:50 -070030 c.executemany("INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?, ?)",
fmenozzib4f254e2016-06-28 14:03:03 -070031 gradients);
32
33 conn.commit();
34
35
36if __name__ == "__main__":
37 parser = argparse.ArgumentParser(
38 description = "Transform Lua script output to a SQL DB");
39 parser.add_argument("inpath", help="Path to Lua script output file");
40 parser.add_argument("outpath", help="Path to SQL DB");
41 args = parser.parse_args();
42
43 create_database(args.inpath, args.outpath);