| 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 FileName TEXT, |
| 16 ColorCount INTEGER, | 16 ColorCount INTEGER, |
| 17 GradientType TEXT, | 17 GradientType TEXT, |
| 18 TileMode TEXT, | 18 TileMode TEXT, |
| 19 EvenlySpaced INTEGER, | 19 EvenlySpaced INTEGER, |
| 20 HardStopCount INTEGER, | 20 HardStopCount INTEGER, |
| 21 Verb TEXT, | 21 Verb TEXT, |
| 22 BoundsWidth INTEGER, |
| 23 BoundsHeight INTEGER, |
| 22 Positions TEXT | 24 Positions TEXT |
| 23 )'''); | 25 )'''); |
| 24 c.execute("DELETE FROM gradients"); | 26 c.execute("DELETE FROM gradients"); |
| 25 | 27 |
| 26 with open(inpath, "r") as results: | 28 with open(inpath, "r") as results: |
| 27 gradients = [] | 29 gradients = [] |
| 28 for line in [line.strip() for line in results]: | 30 for line in [line.strip() for line in results]: |
| 29 gradients.append(line.split()); | 31 gradients.append(line.split()); |
| 30 | 32 |
| 31 c.executemany( | 33 c.executemany( |
| 32 "INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?, ?, ?)", | 34 "INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", |
| 33 gradients); | 35 gradients); |
| 34 | 36 |
| 35 conn.commit(); | 37 conn.commit(); |
| 36 | 38 |
| 37 | 39 |
| 38 if __name__ == "__main__": | 40 if __name__ == "__main__": |
| 39 parser = argparse.ArgumentParser( | 41 parser = argparse.ArgumentParser( |
| 40 description = "Transform Lua script output to a SQL DB"); | 42 description = "Transform Lua script output to a SQL DB"); |
| 41 parser.add_argument("inpath", help="Path to Lua script output file"); | 43 parser.add_argument("inpath", help="Path to Lua script output file"); |
| 42 parser.add_argument("outpath", help="Path to SQL DB"); | 44 parser.add_argument("outpath", help="Path to SQL DB"); |
| 43 args = parser.parse_args(); | 45 args = parser.parse_args(); |
| 44 | 46 |
| 45 create_database(args.inpath, args.outpath); | 47 create_database(args.inpath, args.outpath); |
| OLD | NEW |