PageRenderTime 148ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/onyx/core/__init__.py

https://gitlab.com/Aituglo/Onyx
Python | 88 lines | 68 code | 18 blank | 2 comment | 12 complexity | 4abf59f5d30b156f1751ffac62f9e836 MD5 | raw file
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. __version__ = '0.1.4'
  4. import os
  5. import os.path
  6. from os.path import exists
  7. import sys
  8. import site
  9. import platform
  10. reload(sys)
  11. sys.setdefaultencoding('utf-8')
  12. import onyx
  13. from flask import Flask
  14. from flask_sqlalchemy import SQLAlchemy
  15. from flask_login import LoginManager , login_user , login_required
  16. from flask import flash , request , render_template , url_for , redirect
  17. from flask_mail import Mail, Message
  18. template_folder = os.path.dirname(os.path.dirname(__file__)) + '/templates'
  19. static_folder = os.path.dirname(os.path.dirname(__file__)) + '/static'
  20. core = Flask('app', template_folder=template_folder , static_folder=static_folder)
  21. core.config.from_object('onyx.bddconfig')
  22. db = SQLAlchemy(core)
  23. if exists(str(onyx.__path__[0]) + "/core/config/mail.py") == True:
  24. from onyx.core.config import mail
  25. else:
  26. print('notexist')
  27. mail = Mail(core)
  28. core.config['SECRET_KEY'] = 'onyx'
  29. core.config['SECURITY_PASSWORD_SALT'] = 'onyx2'
  30. from models import *
  31. if exists(str(onyx.__path__[0]) + "/core/install") == True:
  32. print "Installation en cour :"
  33. if platform.system() == "Linux":
  34. os.system("sudo apt-get install moc mplayer python-dev")
  35. try:
  36. from migrate.versioning import api
  37. from onyx.bddconfig import SQLALCHEMY_DATABASE_URI
  38. from onyx.bddconfig import SQLALCHEMY_MIGRATE_REPO
  39. from onyx.core import db
  40. import os.path
  41. db.create_all()
  42. if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
  43. api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
  44. api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  45. else:
  46. api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO,
  47. api.version(SQLALCHEMY_MIGRATE_REPO))
  48. print "Base de donnée initialisée"
  49. except:
  50. print "Base de donnée déjà initialisée"
  51. else:
  52. try:
  53. from migrate.versioning import api
  54. from onyx.bddconfig import SQLALCHEMY_DATABASE_URI
  55. from onyx.bddconfig import SQLALCHEMY_MIGRATE_REPO
  56. from onyx.core import db
  57. import os.path
  58. db.create_all()
  59. if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
  60. api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
  61. api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
  62. else:
  63. api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO,
  64. api.version(SQLALCHEMY_MIGRATE_REPO))
  65. print "Base de donnée initialisée"
  66. except:
  67. print "Base de donnée déjà initialisée"
  68. from install import *
  69. else:
  70. from controllers import *