Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
aura-engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Kruse
aura-engine
Commits
c527020c
Commit
c527020c
authored
6 years ago
by
Gottfried Gaisbauer
Browse files
Options
Downloads
Patches
Plain Diff
added comments, docstring, introduced functions
parent
6304d38c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libraries/database/database.py
+50
-23
50 additions, 23 deletions
libraries/database/database.py
with
50 additions
and
23 deletions
libraries/database/database.py
+
50
−
23
View file @
c527020c
from
sqlalchemy.ext.declarative
import
declarative_base
from
modules.base.config
import
ConfigReader
"""
Database conn
"""
from
sqlalchemy.ext.declarative
import
declarative_base
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_babel
import
Babel
#
from flask_babel import Babel
from
flask
import
Flask
Base
=
declarative_base
()
from
modules.base.config
import
ConfigReader
# pylint: disable=import-error
def
create_app
(
install_dir
,
uri
):
"""
creates flask app context
:param install_dir: Installdir of Aura
:param uri: Database connection uri
:return: Flask object
"""
app
=
Flask
(
__name__
,
template_folder
=
install_dir
+
'
/modules/web/templates
'
)
app
.
config
[
"
SQLALCHEMY_DATABASE_URI
"
]
=
uri
app
.
config
[
'
BABEL_DEFAULT_LOCALE
'
]
=
'
de
'
app
.
config
[
'
SQLALCHEMY_TRACK_MODIFICATIONS
'
]
=
False
return
app
def
create_database
():
"""
creates sqlalchemy database connection
:return: SQLAlchemy object
"""
#### load config ####
config
=
ConfigReader
()
config
.
load_config
()
#### load config ####
config
=
ConfigReader
()
config
.
load_config
()
#### read config ####
install_dir
=
config
.
get
(
str
(
"
install_dir
"
))
db_name
=
config
.
get
(
str
(
"
db_name
"
))
db_user
=
config
.
get
(
str
(
"
db_user
"
))
db_pass
=
config
.
get
(
str
(
"
db_pass
"
))
db_host
=
config
.
get
(
str
(
"
db_host
"
))
#### create database conn ####
app
=
Flask
(
__name__
,
template_folder
=
install_dir
+
'
/modules/web/templates
'
)
app
.
config
[
"
SQLALCHEMY_DATABASE_URI
"
]
=
"
mysql://
"
+
db_user
+
"
:
"
+
db_pass
+
"
@
"
+
db_host
+
"
/
"
+
db_name
+
"
?charset=utf8
"
app
.
config
[
'
BABEL_DEFAULT_LOCALE
'
]
=
'
de
'
app
.
config
[
'
SQLALCHEMY_TRACK_MODIFICATIONS
'
]
=
False
db
=
SQLAlchemy
(
app
)
babel
=
Babel
(
app
)
#### read config ####
install_dir
=
config
.
get
(
str
(
"
install_dir
"
))
db_name
=
config
.
get
(
str
(
"
db_name
"
))
db_user
=
config
.
get
(
str
(
"
db_user
"
))
db_pass
=
config
.
get
(
str
(
"
db_pass
"
))
db_host
=
config
.
get
(
str
(
"
db_host
"
))
#### create database conn ####
uri
=
"
mysql://
"
+
db_user
+
"
:
"
+
db_pass
+
"
@
"
+
db_host
+
"
/
"
+
db_name
+
"
?charset=utf8
"
app
=
create_app
(
install_dir
,
uri
)
database
=
SQLAlchemy
(
app
)
# babel = Babel(app)
return
app
,
database
Base
=
declarative_base
()
APP
,
DB
=
create_database
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment