1#!/usr/bin/env python 2# 3# Copyright 2016 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 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 ( 15 FileName TEXT, 16 ColorCount INTEGER, 17 GradientType TEXT, 18 TileMode TEXT, 19 EvenlySpaced INTEGER, 20 HardStopCount INTEGER, 21 Verb TEXT, 22 BoundsWidth INTEGER, 23 BoundsHeight INTEGER, 24 Positions TEXT 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 33 c.executemany( 34 "INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", 35 gradients); 36 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); 48