fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 3 | # Copyright 2016 Google Inc. |
fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
| 8 | import argparse |
| 9 | import sqlite3 |
| 10 | |
| 11 | def create_database(inpath, outpath): |
| 12 | with sqlite3.connect(outpath) as conn: |
| 13 | c = conn.cursor(); |
| 14 | c.execute('''CREATE TABLE IF NOT EXISTS gradients ( |
fmenozzi | f023e68 | 2016-07-18 08:20:06 -0700 | [diff] [blame] | 15 | FileName TEXT, |
fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 16 | ColorCount INTEGER, |
| 17 | GradientType TEXT, |
| 18 | TileMode TEXT, |
| 19 | EvenlySpaced INTEGER, |
| 20 | HardStopCount INTEGER, |
fmenozzi | 016e51f | 2016-07-14 07:44:50 -0700 | [diff] [blame] | 21 | Verb TEXT, |
fmenozzi | d876a4b | 2016-07-18 13:33:37 -0700 | [diff] [blame] | 22 | BoundsWidth INTEGER, |
| 23 | BoundsHeight INTEGER, |
fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 24 | Positions TEXT |
fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 25 | )'''); |
| 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 | |
fmenozzi | f023e68 | 2016-07-18 08:20:06 -0700 | [diff] [blame] | 33 | c.executemany( |
fmenozzi | d876a4b | 2016-07-18 13:33:37 -0700 | [diff] [blame] | 34 | "INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", |
fmenozzi | f023e68 | 2016-07-18 08:20:06 -0700 | [diff] [blame] | 35 | gradients); |
fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 36 | |
| 37 | conn.commit(); |
| 38 | |
| 39 | |
| 40 | if __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); |