| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2016 Google Inc. | 3 # Copyright 2016 Google Inc. |
| 4 # | 4 # |
| 5 # Use of this source code is governed by a BSD-style license that can be | 5 # Use of this source code is governed by a BSD-style license that can be |
| 6 # found in the LICENSE file. | 6 # found in the LICENSE file. |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import sqlite3 | 9 import sqlite3 |
| 10 | 10 |
| 11 def create_database(inpath, outpath): | 11 def create_database(inpath, outpath): |
| 12 with sqlite3.connect(outpath) as conn: | 12 with sqlite3.connect(outpath) as conn: |
| 13 c = conn.cursor(); | 13 c = conn.cursor(); |
| 14 c.execute('''CREATE TABLE IF NOT EXISTS gradients ( | 14 c.execute('''CREATE TABLE IF NOT EXISTS gradients ( |
| 15 FileName TEXT, |
| 15 ColorCount INTEGER, | 16 ColorCount INTEGER, |
| 16 GradientType TEXT, | 17 GradientType TEXT, |
| 17 TileMode TEXT, | 18 TileMode TEXT, |
| 18 EvenlySpaced INTEGER, | 19 EvenlySpaced INTEGER, |
| 19 HardStopCount INTEGER, | 20 HardStopCount INTEGER, |
| 20 Verb TEXT, | 21 Verb TEXT, |
| 21 Positions TEXT | 22 Positions TEXT |
| 22 )'''); | 23 )'''); |
| 23 c.execute("DELETE FROM gradients"); | 24 c.execute("DELETE FROM gradients"); |
| 24 | 25 |
| 25 with open(inpath, "r") as results: | 26 with open(inpath, "r") as results: |
| 26 gradients = [] | 27 gradients = [] |
| 27 for line in [line.strip() for line in results]: | 28 for line in [line.strip() for line in results]: |
| 28 gradients.append(line.split()); | 29 gradients.append(line.split()); |
| 29 | 30 |
| 30 c.executemany("INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?, ?)", | 31 c.executemany( |
| 31 gradients); | 32 "INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?, ?, ?)", |
| 33 gradients); |
| 32 | 34 |
| 33 conn.commit(); | 35 conn.commit(); |
| 34 | 36 |
| 35 | 37 |
| 36 if __name__ == "__main__": | 38 if __name__ == "__main__": |
| 37 parser = argparse.ArgumentParser( | 39 parser = argparse.ArgumentParser( |
| 38 description = "Transform Lua script output to a SQL DB"); | 40 description = "Transform Lua script output to a SQL DB"); |
| 39 parser.add_argument("inpath", help="Path to Lua script output file"); | 41 parser.add_argument("inpath", help="Path to Lua script output file"); |
| 40 parser.add_argument("outpath", help="Path to SQL DB"); | 42 parser.add_argument("outpath", help="Path to SQL DB"); |
| 41 args = parser.parse_args(); | 43 args = parser.parse_args(); |
| 42 | 44 |
| 43 create_database(args.inpath, args.outpath); | 45 create_database(args.inpath, args.outpath); |
| OLD | NEW |