You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

create.py 1.4 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8; mode: python; tab-width: 4; indent-tabs-mode: nil -*-
  3. # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8
  4. __author__ = ['"anjingyu" <anjingyu@navinfo.com>']
  5. import os
  6. import sqlite3
  7. DEFAULT_ENTRIES = [
  8. ("audi-t3", "v1.0.3", "http://172.23.140.35:12345/audi-t3/v1.0.3/", "Base URL of Audi T3 map server, 1.0.3"),
  9. ("audi-t3", "v1.0.4", "http://172.23.140.35:12345/audi-t3/v1.0.4/", "Base URL of Audi T3 map server, 1.0.4")
  10. ]
  11. if __name__ == '__main__':
  12. con = None
  13. try:
  14. con = sqlite3.connect("mapserver.db")
  15. # Create db file if not exist
  16. if os.path.isfile("mapserver.db"):
  17. print("DB creation: creating database schema: mapserver.db")
  18. ddl = open('init.sql').read()
  19. sqlite3.complete_statement(ddl)
  20. con.executescript(ddl)
  21. # Create MapServer table and insert some data
  22. cur = con.cursor()
  23. print("Table creation: MapServer")
  24. for entry in DEFAULT_ENTRIES:
  25. print(f"Insert record: {entry}")
  26. cur.execute(f"""INSERT INTO MapServer (id, catalog, version, value, description) values (NULL, "{entry[0]}", "{entry[1]}", "{entry[2]}", "{entry[3]}")""")
  27. con.commit()
  28. except Exception as e:
  29. print("Failed to create database: ", e)
  30. finally:
  31. if con is not None:
  32. con.close()