install.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import sqlite3
  4. MIGRATION_FILE = 'migration.sql'
  5. EXIT_ERROR = 2
  6. EXIT_WARNING = 1
  7. EXIT_SUCCESS = 0
  8. def migration_task():
  9. print "%s Starting tables creation"%(unichr(0x25ba).encode('utf-8'))
  10. conn = sqlite3.connect('application.db')
  11. c = conn.cursor()
  12. with open(MIGRATION_FILE) as fd:
  13. migration = "".join(fd.readlines())
  14. try:
  15. c.executescript(migration)
  16. except sqlite3.OperationalError, e:
  17. print " %s Something has failed during tables creation"%(unichr(0x00d7).encode('utf-8'))
  18. print str(e)
  19. return EXIT_ERROR
  20. conn.commit()
  21. conn.close()
  22. print " %s Tables creation done with success"%(unichr(0x2713).encode('utf-8'))
  23. return EXIT_SUCCESS
  24. tasks = [migration_task]
  25. def install():
  26. for task in tasks:
  27. return_value = task()
  28. if return_value:
  29. print " %s Installation failed"%(unichr(0x00d7).encode('utf-8'))
  30. exit(EXIT_ERROR)
  31. print "-"*80
  32. print "%s Install success"%(unichr(0x2713).encode('utf-8'))
  33. print "-"*80
  34. install()