OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright 2015 Google Inc. |
| 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 ( |
| 15 ColorCount INTEGER, |
| 16 GradientType TEXT, |
| 17 TileMode TEXT, |
| 18 EvenlySpaced INTEGER, |
| 19 HardStops INTEGER |
| 20 )'''); |
| 21 c.execute("DELETE FROM gradients"); |
| 22 |
| 23 with open(inpath, "r") as results: |
| 24 gradients = [] |
| 25 for line in [line.strip() for line in results]: |
| 26 gradients.append(line.split()); |
| 27 |
| 28 c.executemany("INSERT INTO gradients VALUES (?, ?, ?, ?, ?)", |
| 29 gradients); |
| 30 |
| 31 conn.commit(); |
| 32 |
| 33 |
| 34 if __name__ == "__main__": |
| 35 parser = argparse.ArgumentParser( |
| 36 description = "Transform Lua script output to a SQL DB"); |
| 37 parser.add_argument("inpath", help="Path to Lua script output file"); |
| 38 parser.add_argument("outpath", help="Path to SQL DB"); |
| 39 args = parser.parse_args(); |
| 40 |
| 41 create_database(args.inpath, args.outpath); |
OLD | NEW |