Commit dbd5e235 authored by Luciano Cauzzi's avatar Luciano Cauzzi

Initial commit

parents
Pipeline #65 canceled with stages
# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# IPython Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# dotenv
.env
# virtualenv
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
### VirtualEnv template
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
.venv
pip-selfcheck.json
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
.idea/
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
from .container import MongoManager
from dependency_injector import containers, providers
from database.mongo_manager import AppMongoManager
class MongoManager(containers.DeclarativeContainer):
config = providers.Configuration('config')
manager = providers.Singleton(AppMongoManager, app=config.mongo.app, url=config.mongo.url, db_name=config.mongo.database, username=config.mongo.username, password=config.mongo.password)
from flask_mongoalchemy import MongoAlchemy
from logger_library import Logger
logger = Logger.app_logger().get_logger()
class AppMongoManager:
def __init__(self, app, url, db_name, username=None, password=None):
self.app = app
self.url = url
self.db_name = db_name
self.username = username
self.password = password
self.__load_engine__()
def __load_engine__(self):
self.app.config['MONGOALCHEMY_SERVER'] = self.url
self.app.config['MONGOALCHEMY_DATABASE'] = self.db_name
self.app.config['MONGOALCHEMY_SERVER_AUTH'] = False
if self.username:
self.app.config['MONGOALCHEMY_USER'] = self.username
if self.password:
self.app.config['MONGOALCHEMY_PASSWORD'] = self.password
self.__start_engine__()
def __start_engine__(self):
try:
self.__db__ = MongoAlchemy(self.app)
except Exception as e:
logger.error("[DB]: database init failed -> terminating app. Bye\n{}".format(e))
exit(-1)
def get_engine(self):
return self.__db__
from setuptools import setup
import setuptools
setup(
name='mongo_db_library',
version='0.1',
packages=setuptools.find_packages(),
dependency_links=['http://github.comune.brescia.it/innovation-that-excites/logger_library#egg=logger_library'],
install_requires=['logger_library', 'dependency_injector', 'flask_mongoalchemy'],
url='http://github/innovation-that-excites/mongo_db_library',
license='MIT',
author='Luciano Cauzzi',
author_email='lcauzzi@comune.brescia.it',
description=''
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment