aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/lua/gradients.py
blob: 580781731b6499b93d977e1b7164a2d484e51e3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
#
# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import argparse
import sqlite3

def create_database(inpath, outpath):
    with sqlite3.connect(outpath) as conn:
        c = conn.cursor();
        c.execute('''CREATE TABLE IF NOT EXISTS gradients (
                        FileName      TEXT,
                        ColorCount    INTEGER,
                        GradientType  TEXT,
                        TileMode      TEXT,
                        EvenlySpaced  INTEGER,
                        HardStopCount INTEGER,
                        Verb          TEXT,
                        BoundsWidth   INTEGER,
                        BoundsHeight  INTEGER,
                        Positions     TEXT
                     )''');
        c.execute("DELETE FROM gradients");

        with open(inpath, "r") as results:
            gradients = []
            for line in [line.strip() for line in results]:
                gradients.append(line.split());

            c.executemany(
                "INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                gradients);

            conn.commit();


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
            description = "Transform Lua script output to a SQL DB");
    parser.add_argument("inpath",  help="Path to Lua script output file");
    parser.add_argument("outpath", help="Path to SQL DB");
    args = parser.parse_args();

    create_database(args.inpath, args.outpath);