Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PythonLibs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TheCodeLabs
PythonLibs
Commits
9808c29e
Commit
9808c29e
authored
May 2, 2020
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
Added FlaskBaseApp
parent
9a44fcc4
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
PythonLibs/FlaskBaseApp.py
+94
-0
94 additions, 0 deletions
PythonLibs/FlaskBaseApp.py
PythonLibs/__init__.py
+1
-0
1 addition, 0 deletions
PythonLibs/__init__.py
setup.py
+3
-1
3 additions, 1 deletion
setup.py
with
98 additions
and
1 deletion
PythonLibs/FlaskBaseApp.py
0 → 100644
+
94
−
0
View file @
9808c29e
import
abc
import
json
import
logging
import
os
from
abc
import
ABC
from
typing
import
Dict
from
flask
import
Flask
,
send_from_directory
from
flask
import
jsonify
from
gevent.pywsgi
import
WSGIServer
class
FlaskBaseApp
(
ABC
):
def
__init__
(
self
,
appName
:
str
,
rootDir
:
str
,
logger
:
logging
.
Logger
,
versionPath
=
'
version.json
'
,
settingsPath
=
'
../settings.json
'
,
serveFavicon
=
True
,
serveRobotsTxt
=
False
):
self
.
_appName
=
appName
self
.
_rootDir
=
rootDir
self
.
_logger
=
logger
self
.
_serveFavicon
=
serveFavicon
self
.
_serveRobotsTxt
=
serveRobotsTxt
self
.
_version
=
self
.
__parse_version
(
versionPath
)
self
.
_settings
=
self
.
__parse_settings
(
settingsPath
)
self
.
_serverSettings
=
self
.
_settings
[
'
server
'
]
self
.
_app
=
None
@staticmethod
def
__parse_version
(
versionPath
:
str
)
->
Dict
:
with
open
(
versionPath
,
'
r
'
,
encoding
=
'
UTF-8
'
)
as
f
:
version
=
json
.
load
(
f
)
return
version
[
'
version
'
]
@staticmethod
def
__parse_settings
(
settingsPath
:
str
)
->
Dict
:
with
open
(
settingsPath
,
'
r
'
,
encoding
=
'
UTF-8
'
)
as
f
:
return
json
.
load
(
f
)
def
__init_app
(
self
):
app
=
Flask
(
self
.
_rootDir
)
app
.
secret_key
=
self
.
_serverSettings
[
'
secret
'
]
self
.
register_blueprints
(
app
)
@app.route
(
'
/version
'
,
methods
=
[
'
GET
'
])
def
version
():
return
jsonify
(
self
.
_version
)
if
self
.
_serveFavicon
:
@app.route
(
'
/favicon.ico
'
,
methods
=
[
'
GET
'
])
def
favicon
():
return
send_from_directory
(
os
.
path
.
join
(
app
.
root_path
,
'
static
'
),
'
../static/favicon.ico
'
,
mimetype
=
'
image/vnd.microsoft.icon
'
)
if
self
.
_serveRobotsTxt
:
@app.route
(
'
/robots.txt
'
,
methods
=
[
'
GET
'
])
def
robots
():
return
send_from_directory
(
os
.
path
.
join
(
app
.
root_path
,
'
static
'
),
'
../static/robots.txt
'
)
return
app
@abc.abstractmethod
def
register_blueprints
(
self
,
app
):
pass
def
start_server
(
self
):
self
.
_app
=
self
.
__init_app
()
if
self
.
_serverSettings
[
'
useSSL
'
]:
protocol
=
'
https
'
http_server
=
WSGIServer
((
self
.
_serverSettings
[
'
listen
'
],
self
.
_serverSettings
[
'
port
'
]),
self
.
_app
,
keyfile
=
self
.
_serverSettings
[
'
keyfile
'
],
certfile
=
self
.
_serverSettings
[
'
certfile
'
],
log
=
self
.
_logger
)
else
:
protocol
=
'
http
'
http_server
=
WSGIServer
((
self
.
_serverSettings
[
'
listen
'
],
self
.
_serverSettings
[
'
port
'
]),
self
.
_app
,
log
=
self
.
_logger
)
self
.
_logger
.
info
(
'
{name} {versionName}({versionCode}) -
'
'
Listening on {protocol}://{listen}:{port}...
'
.
format
(
name
=
self
.
_appName
,
versionName
=
self
.
_version
[
'
name
'
],
versionCode
=
self
.
_version
[
'
code
'
],
protocol
=
protocol
,
listen
=
self
.
_serverSettings
[
'
listen
'
],
port
=
self
.
_serverSettings
[
'
port
'
]))
http_server
.
serve_forever
()
This diff is collapsed.
Click to expand it.
PythonLibs/__init__.py
+
1
−
0
View file @
9808c29e
from
PythonLibs.DefaultLogger
import
DefaultLogger
from
PythonLibs.DefaultLogger
import
DefaultLogger
from
PythonLibs.MailHandler
import
MailHandler
from
PythonLibs.MailHandler
import
MailHandler
from
PythonLibs.CachedService
import
CachedService
from
PythonLibs.CachedService
import
CachedService
from
PythonLibs.FlaskBaseApp
import
FlaskBaseApp
This diff is collapsed.
Click to expand it.
setup.py
+
3
−
1
View file @
9808c29e
...
@@ -13,7 +13,9 @@ setup(
...
@@ -13,7 +13,9 @@ setup(
install_requires
=
[
install_requires
=
[
],
],
setup_requires
=
[
setup_requires
=
[
'
wheel
'
'
wheel
'
,
'
flask
'
,
'
gevent
'
],
],
classifiers
=
[
classifiers
=
[
'
Development Status :: 5 - Production/Stable
'
,
'
Development Status :: 5 - Production/Stable
'
,
...
...
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