Restructure code for pluginify

This commit is contained in:
Ferdinand Thiessen 2020-08-13 19:48:26 +02:00
parent fac8afab03
commit 246bd90ebd
60 changed files with 113 additions and 64 deletions

BIN
flaschengeist/.app.py.swp Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
""" Server-package
"""
from pathlib import Path
_modpath = Path(__file__).parent

View File

@ -4,8 +4,8 @@
Initialize also a singelton for the AccesTokenControler and start the Thread.
"""
from .logger import getDebugLogger
from geruecht.controller import dbConfig, ldapConfig
from .system.logger import getDebugLogger
from .system.controller import dbConfig, ldapConfig
from flask_mysqldb import MySQL
from flask_ldapconn import LDAPConn
import ssl
@ -19,6 +19,7 @@ from flask_cors import CORS
DEBUG.info("Build APP")
app = Flask(__name__)
CORS(app)
app.config['SECRET_KEY'] = '0a657b97ef546da90b2db91862ad4e29'
app.config['MYSQL_HOST'] = dbConfig['URL']
app.config['MYSQL_USER'] = dbConfig['user']
@ -42,18 +43,30 @@ app.config['FORCE_ATTRIBUTE_VALUE_AS_LIST'] = True
ldap = LDAPConn(app)
db = MySQL(app)
from geruecht import routes
from geruecht.baruser.routes import baruser
from geruecht.finanzer.routes import finanzer
from geruecht.user.routes import user
from geruecht.vorstand.routes import vorstand
from geruecht.gastro.routes import gastrouser
from geruecht.registration_route import registration
import pkg_resources
discovered_plugins = {
entry_point.name: entry_point.load()
for entry_point
in pkg_resources.iter_entry_points('geruecht.plugins')
}
#from geruecht import routes
#from geruecht.baruser.routes import baruser
#from geruecht.finanzer.routes import finanzer
#from geruecht.user.routes import user
#from geruecht.vorstand.routes import vorstand
#from geruecht.gastro.routes import gastrouser
#from geruecht.registration_route import registration
DEBUG.info("Registrate bluebrints")
app.register_blueprint(baruser)
app.register_blueprint(finanzer)
app.register_blueprint(user)
app.register_blueprint(vorstand)
app.register_blueprint(gastrouser)
app.register_blueprint(registration)
for k, v in discovered_plugins:
DEBUG("Register %s" % k)
app.register_blueprint(v())
#app.register_blueprint(baruser)
#app.register_blueprint(finanzer)
#app.register_blueprint(user)
#app.register_blueprint(vorstand)
#app.register_blueprint(gastrouser)
#app.register_blueprint(registration)

Binary file not shown.

View File

Binary file not shown.

View File

@ -1,10 +1,9 @@
from geruecht.logger import getDebugLogger
from geruecht.configparser import ConifgParser
from ..logger import getDebugLogger
from ..configparser import ConifgParser
from flaschengeist import _modpath
import os
print(os.getcwd())
config = ConifgParser('geruecht/config.yml')
config = ConifgParser(_modpath/'config.yml')
LOGGER = getDebugLogger()

View File

@ -5,7 +5,7 @@ from geruecht.model import MONEY, USER, GASTRO, BAR, VORSTAND, EXTERN
from geruecht.exceptions import PermissionDenied
from . import Singleton
from geruecht.exceptions import UsernameExistLDAP, LDAPExcetpion
from geruecht import ldapConfig
from . import ldapConfig
from geruecht.logger import getDebugLogger
debug = getDebugLogger()

View File

@ -2,6 +2,9 @@ import logging
import logging.config
import yaml
from os import path, makedirs, getcwd
from .. import _modpath
fname = _modpath/'logging.yml'
if not path.exists("geruecht/log/debug"):
a = path.join(path.curdir, "geruecht", "log", "debug")
@ -12,7 +15,7 @@ if not path.exists("geruecht/log/info"):
makedirs(b)
with open("geruecht/logging.yml", 'rb') as file:
with fname.open(mode='rb') as file:
config = yaml.safe_load(file.read())
logging.config.dictConfig(config)

View File

View File

@ -1,5 +1,5 @@
from datetime import datetime
from geruecht.logger import getDebugLogger
from ..logger import getDebugLogger
debug = getDebugLogger()

View File

@ -0,0 +1,49 @@
from ..logger import getDebugLogger
from datetime import datetime
debug = getDebugLogger()
class User():
""" Database Object for User
Table for all safed User
Attributes:
id: Id in Database as Primary Key.
username: Username of the User to Login
firstname: Firstname of the User
lastname: Lastname of the User
mail: mail address of the User
"""
def __init__(self, data):
debug.info("init user")
if 'id' in data:
self.id = int(data['id'])
self.firstname = data['firstname']
self.lastname = data['lastname']
if 'mail' in data:
self.mail = data['mail']
else:
self.mail = ''
if 'username' in data:
self.username = data['username']
else:
self.username = None
debug.debug("user is {{ {} }}".format(self))
def updateData(self, data):
debug.info("update data of user")
if 'firstname' in data:
self.firstname = data['firstname']
if 'lastname' in data:
self.lastname = data['lastname']
if 'mail' in data:
self.mail = data['mail']
if 'username' in data:
self.username = data['username']
def __repr__(self):
return "User({}, {})".format(self.uid, self.username)
# TODO: user attributes (uid|key|value), getter, setter, has

View File

@ -1,6 +0,0 @@
MONEY = "moneymaster"
VORSTAND = "vorstand"
EXTERN = "extern"
GASTRO = "gastro"
USER = "user"
BAR = "bar"

View File

@ -1,20 +0,0 @@
bcrypt==3.1.6
cffi==1.12.3
Click==7.0
entrypoints==0.3
flake8==3.7.7
Flask==1.0.2
Flask-Bcrypt==0.7.1
Flask-Cors==3.0.7
Flask-SQLAlchemy==2.4.0
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
mccabe==0.6.1
pkg-resources==0.0.0
pycodestyle==2.5.0
pycparser==2.19
pyflakes==2.1.1
six==1.12.0
SQLAlchemy==1.3.3
Werkzeug==0.15.2

View File

@ -1,14 +0,0 @@
click==7.1.2
Flask==1.1.2
Flask-Cors==3.0.8
Flask-LDAPConn==0.10.1
Flask-MySQLdb==0.2.0
itsdangerous==1.1.0
Jinja2==2.11.2
ldap3==2.7
MarkupSafe==1.1.1
mysqlclient==1.4.6
pyasn1==0.4.8
PyYAML==5.3.1
six==1.15.0
Werkzeug==1.0.1

View File

@ -1,4 +1,5 @@
from geruecht import app
#!/usr/bin/python3
from flaschengeist.app import app
""" Main

19
setup.py Normal file
View File

@ -0,0 +1,19 @@
from setuptools import setup, find_packages
setup(
name='flaschengeist',
version='0.0.1',
url='https://wu5.de/redmine/projects/geruecht',
author='WU5 + Friends',
author_email='tim@groeger-clan.de',
description='Does things',
packages=find_packages(),
package_data={'': ['*.yml']},
scripts=['run_flaschengeist'],
install_requires=['Flask >= 1.0.2', 'PyYAML>=5.3.1', "flask_mysqldb", "flask_ldapconn", "flask_cors"],
entry_points = {
'flaschengeist.plugins': [
'users = flaschengeist.system.user:register'
]
}
)