gradients.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. import argparse
  8. import sqlite3
  9. def create_database(inpath, outpath):
  10. with sqlite3.connect(outpath) as conn:
  11. c = conn.cursor();
  12. c.execute('''CREATE TABLE IF NOT EXISTS gradients (
  13. FileName TEXT,
  14. ColorCount INTEGER,
  15. GradientType TEXT,
  16. TileMode TEXT,
  17. EvenlySpaced INTEGER,
  18. HardStopCount INTEGER,
  19. Verb TEXT,
  20. BoundsWidth INTEGER,
  21. BoundsHeight INTEGER,
  22. Positions TEXT
  23. )''');
  24. c.execute("DELETE FROM gradients");
  25. with open(inpath, "r") as results:
  26. gradients = []
  27. for line in [line.strip() for line in results]:
  28. gradients.append(line.split());
  29. c.executemany(
  30. "INSERT INTO gradients VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
  31. gradients);
  32. conn.commit();
  33. if __name__ == "__main__":
  34. parser = argparse.ArgumentParser(
  35. description = "Transform Lua script output to a SQL DB");
  36. parser.add_argument("inpath", help="Path to Lua script output file");
  37. parser.add_argument("outpath", help="Path to SQL DB");
  38. args = parser.parse_args();
  39. create_database(args.inpath, args.outpath);