2020-10-15 10:40:53 +00:00
|
|
|
# Flaschengeist
|
2021-05-20 15:37:17 +00:00
|
|
|
This is the backend of the Flaschengeist.
|
2020-10-15 10:40:53 +00:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
### Requirements
|
|
|
|
- mysql or mariadb
|
2021-05-20 15:37:17 +00:00
|
|
|
- including development files libmariadb-dev
|
2020-10-28 13:21:54 +00:00
|
|
|
- python 3.6+
|
2020-10-15 10:40:53 +00:00
|
|
|
### Install python files
|
|
|
|
pip3 install --user .
|
|
|
|
or with ldap support
|
|
|
|
|
|
|
|
pip3 install --user ".[ldap]"
|
2021-01-24 15:19:46 +00:00
|
|
|
or if you want to also run the tests:
|
2020-10-28 13:21:54 +00:00
|
|
|
|
2021-01-24 15:19:46 +00:00
|
|
|
pip3 install --user ".[ldap,test]"
|
2020-10-28 13:21:54 +00:00
|
|
|
|
2021-01-25 12:09:20 +00:00
|
|
|
You will also need a MySQL driver, recommended drivers are
|
|
|
|
- `mysqlclient`
|
|
|
|
- `PyMySQL`
|
|
|
|
|
2021-03-18 13:05:28 +00:00
|
|
|
`setup.py` will try to install a matching driver.
|
|
|
|
|
2020-10-27 12:43:01 +00:00
|
|
|
#### Windows
|
2021-03-18 13:05:28 +00:00
|
|
|
Same as above, but if you want to use `mysqlclient` instead of `PyMySQL` (performance?) you have to follow this guide:
|
2020-10-27 12:43:01 +00:00
|
|
|
|
|
|
|
https://www.radishlogic.com/coding/python-3/installing-mysqldb-for-python-3-in-windows/
|
2020-10-15 10:40:53 +00:00
|
|
|
|
|
|
|
### Configuration
|
2021-01-25 12:09:20 +00:00
|
|
|
Configuration is done within the a `flaschengeist.toml`file, you can copy the one located inside the module path
|
|
|
|
(where flaschegeist is installed) or create an empty one and place it inside either:
|
|
|
|
1. `~/.config/`
|
|
|
|
2. A custom path and set environment variable `FLASCHENGEIST_CONF`
|
|
|
|
|
2021-05-20 15:37:17 +00:00
|
|
|
Uncomment and change at least all the database parameters!
|
2020-10-15 10:40:53 +00:00
|
|
|
|
|
|
|
### Database installation
|
2021-05-20 15:37:17 +00:00
|
|
|
The user needs to have full permissions to the database.
|
|
|
|
If not you need to create user and database manually do (or similar on Windows):
|
|
|
|
|
|
|
|
(
|
|
|
|
echo "CREATE DATABASE flaschengeist;"
|
|
|
|
echo "CREATE USER 'flaschengeist'@'localhost' IDENTIFIED BY 'flaschengeist';"
|
|
|
|
echo "GRANT ALL PRIVILEGES ON 'flaschengeist'.* TO 'flaschengeist'@'localhost';"
|
|
|
|
echo "FLUSH PRIVILEGES;"
|
|
|
|
) | sudo mysql
|
|
|
|
|
|
|
|
Then you can install the database tables and initial entries:
|
|
|
|
|
2021-01-24 15:19:46 +00:00
|
|
|
run_flaschengeist install
|
2020-10-15 10:40:53 +00:00
|
|
|
|
|
|
|
### Run
|
2021-01-24 15:19:46 +00:00
|
|
|
run_flaschengeist run
|
2020-10-15 10:40:53 +00:00
|
|
|
or with debug messages:
|
|
|
|
|
2021-01-24 15:19:46 +00:00
|
|
|
run_flaschengeist run --debug
|
|
|
|
|
2021-05-20 15:37:17 +00:00
|
|
|
This will run the backend on http://localhost:5000
|
|
|
|
|
2021-01-24 15:19:46 +00:00
|
|
|
## Tests
|
|
|
|
$ pip install '.[test]'
|
|
|
|
$ pytest
|
|
|
|
Run with coverage report:
|
|
|
|
|
|
|
|
$ coverage run -m pytest
|
|
|
|
$ coverage report
|
|
|
|
Or with html output (open `htmlcov/index.html` in a browser):
|
|
|
|
|
|
|
|
$ coverage html
|
2020-10-15 12:44:58 +00:00
|
|
|
|
2020-10-15 20:16:26 +00:00
|
|
|
## Development
|
2020-10-15 22:37:57 +00:00
|
|
|
### Code Style
|
|
|
|
We enforce you to use PEP 8 code style with a line length of 120 as used by Black.
|
2021-05-20 15:37:17 +00:00
|
|
|
See also [Black Code Style](https://github.com/psf/black/blob/main/docs/the_black_code_style/current_style.md).
|
2020-10-15 22:37:57 +00:00
|
|
|
|
|
|
|
#### Code formatting
|
|
|
|
We use [Black](https://github.com/psf/black) as the code formatter.
|
|
|
|
|
|
|
|
Installation:
|
|
|
|
|
|
|
|
pip install black
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
black -l 120 DIRECTORY_OR_FILE
|
|
|
|
|
2020-10-15 20:16:26 +00:00
|
|
|
### Misc
|
2020-10-15 22:37:57 +00:00
|
|
|
#### Git blame
|
2020-10-15 20:16:26 +00:00
|
|
|
When using `git blame` use this to ignore the code formatting commits:
|
|
|
|
|
|
|
|
$ git blame FILE.py --ignore-revs-file .git-blame-ignore-revs
|
|
|
|
Or if you just want to use `git blame`, configure git like this:
|
|
|
|
|
|
|
|
$ git config blame.ignoreRevsFile .git-blame-ignore-revs
|
|
|
|
|
2021-01-29 18:00:32 +00:00
|
|
|
#### Ignore changes on config
|
|
|
|
git update-index --assume-unchanged flaschengeist/flaschengeist.toml
|
2020-10-15 20:16:26 +00:00
|
|
|
|
2020-10-15 12:44:58 +00:00
|
|
|
## Plugin Development
|
|
|
|
### File Structure
|
|
|
|
flaschengeist-example-plugin
|
|
|
|
|> __init__.py
|
|
|
|
|> model.py
|
|
|
|
|> setup.py
|
|
|
|
|
|
|
|
### Files
|
|
|
|
#### \_\_init\_\_.py
|
|
|
|
from flask import Blueprint
|
|
|
|
from flaschengeist.modules import Plugin
|
|
|
|
|
|
|
|
|
|
|
|
example_bp = Blueprint("example", __name__, url_prefix="/example")
|
2021-01-24 15:19:46 +00:00
|
|
|
permissions = ["example_hello"]
|
2020-10-15 12:44:58 +00:00
|
|
|
|
2020-10-19 11:16:23 +00:00
|
|
|
class PluginExample(Plugin):
|
|
|
|
def __init__(self, conf):
|
|
|
|
super().__init__(blueprint=example_bp, permissions=permissions)
|
|
|
|
|
|
|
|
def install(self):
|
|
|
|
from flaschengeist.system.database import db
|
|
|
|
import .model
|
|
|
|
db.create_all()
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
@example_bp.route("/hello", methods=['GET'])
|
2020-10-15 12:44:58 +00:00
|
|
|
@login_required(roles=['example_hello'])
|
|
|
|
def __hello(id, **kwargs):
|
|
|
|
return "Hello"
|
|
|
|
|
|
|
|
#### model.py
|
|
|
|
Optional, only needed if you need your own models (database)
|
|
|
|
|
|
|
|
from flaschengeist.system.database import db
|
|
|
|
|
|
|
|
|
|
|
|
class ExampleModel(db.Model):
|
|
|
|
"""Example Model"""
|
|
|
|
__tablename__ = 'example'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
description = db.Column(db.String(240))
|
|
|
|
|
|
|
|
#### setup.py
|
|
|
|
from setuptools import setup, find_packages
|
|
|
|
|
|
|
|
setup(
|
|
|
|
name="flaschengeist-example-plugin",
|
|
|
|
version="0.0.0-dev",
|
|
|
|
packages=find_packages(),
|
|
|
|
install_requires=[
|
|
|
|
"flaschengeist >= 2",
|
|
|
|
],
|
|
|
|
entry_points={
|
|
|
|
"flaschengeist.plugin": [
|
2020-10-19 11:16:23 +00:00
|
|
|
"example = flaschengeist-example-plugin:ExampleModel"
|
2020-10-15 12:44:58 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|