Support beerxml and kbh database upload

This commit is contained in:
avollkopf 2021-05-22 18:25:57 +02:00
parent 16bfa84841
commit 5669bb900e
101 changed files with 94 additions and 1 deletions

View file

@ -63,6 +63,7 @@ def create_home_folder_structure():
pathlib.Path(os.path.join(".", 'config/dashboard')).mkdir(parents=True, exist_ok=True) pathlib.Path(os.path.join(".", 'config/dashboard')).mkdir(parents=True, exist_ok=True)
pathlib.Path(os.path.join(".", 'config/dashboard/widgets')).mkdir(parents=True, exist_ok=True) pathlib.Path(os.path.join(".", 'config/dashboard/widgets')).mkdir(parents=True, exist_ok=True)
pathlib.Path(os.path.join(".", 'config/recipes')).mkdir(parents=True, exist_ok=True) pathlib.Path(os.path.join(".", 'config/recipes')).mkdir(parents=True, exist_ok=True)
pathlib.Path(os.path.join(".", 'config/upload')).mkdir(parents=True, exist_ok=True)
print("Folder created") print("Folder created")
@ -104,6 +105,12 @@ def check_for_setup():
print("Please run 'cbpi setup' before starting the server ") print("Please run 'cbpi setup' before starting the server ")
print("***************************************************") print("***************************************************")
return False return False
if os.path.exists(os.path.join(".", "config", "upload")) is False:
print("***************************************************")
print("CraftBeerPi upload folder not found: %s" % os.path.join(".", "config/upload"))
print("Please run 'cbpi setup' before starting the server ")
print("***************************************************")
return False
else: else:
return True return True

View file

@ -123,6 +123,7 @@ class CraftBeerPi:
self.http_system = SystemHttpEndpoints(self) self.http_system = SystemHttpEndpoints(self)
self.http_log = LogHttpEndpoints(self) self.http_log = LogHttpEndpoints(self)
self.http_notification = NotificationHttpEndpoints(self) self.http_notification = NotificationHttpEndpoints(self)
self.login = Login(self) self.login = Login(self)
def _setup_shutdownhook(self): def _setup_shutdownhook(self):
@ -162,7 +163,6 @@ class CraftBeerPi:
logger.debug( logger.debug(
"URL Prefix is None for %s. No endpoints will be registered. Please set / explicit if you want to add it to the root path" % obj) "URL Prefix is None for %s. No endpoints will be registered. Please set / explicit if you want to add it to the root path" % obj)
return return
routes = [] routes = []
for method in [getattr(obj, f) for f in dir(obj) if for method in [getattr(obj, f) for f in dir(obj) if
callable(getattr(obj, f)) and hasattr(getattr(obj, f), "route")]: callable(getattr(obj, f)) and hasattr(getattr(obj, f), "route")]:

View file

@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
import os
import pathlib
import aiohttp
from aiohttp import web
import logging
from unittest.mock import MagicMock, patch
import asyncio
from cbpi.api import *
from voluptuous.schema_builder import message
from cbpi.api.dataclasses import NotificationAction, NotificationType
from cbpi.controller.kettle_controller import KettleController
from cbpi.api.base import CBPiBase
from cbpi.api.config import ConfigType
import json
import webbrowser
logger = logging.getLogger(__name__)
class RecipeUpload(CBPiExtension):
def __init__(self, cbpi):
self.cbpi = cbpi
self.cbpi.register(self, "/upload")
def allowed_file(self, filename, extension):
return '.' in filename and filename.rsplit('.', 1)[1] in set([extension])
@request_mapping(path='/', method="POST", auth_required=False)
async def RecipeUpload(self, request):
data = await request.post()
fileData = data['File']
logging.info(fileData)
if fileData.content_type == 'text/xml':
logging.info(fileData.content_type)
try:
filename = fileData.filename
beerxml_file = fileData.file
content = beerxml_file.read().decode()
if beerxml_file and self.allowed_file(filename, 'xml'):
self.path = os.path.join(".", 'config', "upload", "beer.xml")
f = open(self.path, "w")
f.write(content)
f.close()
self.cbpi.notify("Success", "XML Recipe {} has been uploaded".format(filename), NotificationType.SUCCESS)
except:
self.cbpi.notify("Error" "XML Recipe upload failed", NotificationType.ERROR)
pass
elif fileData.content_type == 'application/octet-stream':
try:
filename = fileData.filename
logger.info(filename)
kbh_file = fileData.file
content = kbh_file.read()
if kbh_file and self.allowed_file(filename, 'sqlite'):
self.path = os.path.join(".", 'config', "upload", "kbh.db")
f=open(self.path, "wb")
f.write(content)
f.close()
self.cbpi.notify("Success", "Kleiner Brauhelfer database has been uploaded", NotificationType.SUCCESS)
except:
self.cbpi.notify("Error", "Kleiner Brauhelfer database upload failed", NotificationType.ERROR)
pass
else:
self.cbpi.notify("Error", "Wrong content type. Upload failed", NotificationType.ERROR)
return web.Response(status=200)
def setup(cbpi):
'''
This method is called by the server during startup
Here you need to register your plugins at the server
:param cbpi: the cbpi core
:return:
'''
cbpi.plugin.register("RecipeUpload", RecipeUpload)

View file

@ -0,0 +1,3 @@
name: RecipeUpload
version: 4
active: true

0
venv3/bin/autopep8 Executable file → Normal file
View file

0
venv3/bin/cbpi Executable file → Normal file
View file

0
venv3/bin/chardetect Executable file → Normal file
View file

0
venv3/bin/easy_install Executable file → Normal file
View file

0
venv3/bin/easy_install-3.7 Executable file → Normal file
View file

0
venv3/bin/f2py Executable file → Normal file
View file

0
venv3/bin/f2py3 Executable file → Normal file
View file

0
venv3/bin/f2py3.7 Executable file → Normal file
View file

0
venv3/bin/pip Executable file → Normal file
View file

0
venv3/bin/pip3 Executable file → Normal file
View file

0
venv3/bin/pip3.7 Executable file → Normal file
View file

0
venv3/bin/pycodestyle Executable file → Normal file
View file

0
venv3/bin/pyfiglet Executable file → Normal file
View file

0
venv3/bin/tabulate Executable file → Normal file
View file

View file

View file

Before

Width:  |  Height:  |  Size: 445 B

After

Width:  |  Height:  |  Size: 445 B

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View file

View file

View file

View file

View file

View file

View file

View file

Some files were not shown because too many files have changed in this diff Show more