__init__.py
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'eduardo'
import os
import ConfigParser
import logging
import logging.config
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
def load_config(environment='development'):
config = ConfigParser.ConfigParser()
here = os.path.abspath(os.path.dirname(__file__))
config_file = os.path.join(here, '../' + environment + '.ini')
config.read(config_file)
# Logging
logging.config.fileConfig(config_file)
return config
class Cocar(object):
"""
Classe global com as configurações
"""
def __init__(self,
environment='development'
):
"""
Parâmetro construtor
"""
self.config = load_config(environment)
cocar_data_dir = self.config.get('cocar', 'data_dir')
if os.path.isdir(cocar_data_dir):
self.cocar_data_dir = cocar_data_dir
else:
os.mkdir(cocar_data_dir)
self.cocar_data_dir = cocar_data_dir
# SQLAlchemy
sqlalchemy_url = self.config.get('sqlalchemy', 'url')
self.engine = create_engine(sqlalchemy_url, echo=True)
self.Session = scoped_session(
sessionmaker(bind=self.engine,
autocommit=True
)
)