use new izzylib and async http module
This commit is contained in:
parent
59b825dca8
commit
4bb7d69f8c
|
@ -1,5 +1,5 @@
|
|||
from izzylib.http_server_async import View
|
||||
from izzylib.http_server_async.error import InternalServerError, Found, NotFound
|
||||
from barkshark_http_async import View
|
||||
from barkshark_http_async.server import error as Error
|
||||
|
||||
|
||||
class Service(View):
|
||||
|
@ -30,7 +30,7 @@ class Service(View):
|
|||
except Exception as e:
|
||||
error = f'{e.__class__.__name__}: {e}'
|
||||
|
||||
if 'json' in request.headers.get('accept', '').lower():
|
||||
if 'json' in request.headers.get('accept', '').one().lower():
|
||||
if error:
|
||||
return response.set_json({'error': error})
|
||||
|
||||
|
@ -40,13 +40,13 @@ class Service(View):
|
|||
return response.set_json(func(proc) or {'result': 'ok'})
|
||||
|
||||
if error:
|
||||
raise InternalServerError(error)
|
||||
raise Error.InternalServerError(error)
|
||||
|
||||
if not func:
|
||||
raise NotFound(f'Invalid action: {action}')
|
||||
raise Error.NotFound(f'Invalid action: {action}')
|
||||
|
||||
func(proc)
|
||||
raise Found('/')
|
||||
raise Error.Found('/')
|
||||
|
||||
|
||||
async def post(self, request, response, name=None, action=None):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
|
||||
from izzylib import Config, DotDict, Path, logging, random_gen
|
||||
from izzylib import JsonConfig, DotDict, Path, logging, random_gen
|
||||
|
||||
|
||||
logging.set_config('level', os.environ.get('LOG_LEVEL', 'INFO'))
|
||||
|
@ -18,7 +18,7 @@ path = DotDict(
|
|||
)
|
||||
|
||||
|
||||
config = Config(datapath.join('config.json'),
|
||||
config = JsonConfig(datapath.join('config.json'),
|
||||
host = '0.0.0.0' if development else 'localhost',
|
||||
port = 8080,
|
||||
pass_protect = False
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import shlex, subprocess, sys, time, traceback
|
||||
|
||||
from datetime import datetime
|
||||
from izzylib import Config, DotDict, Path, boolean, logging
|
||||
from izzylib import JsonConfig, DotDict, Path, boolean, logging
|
||||
from threading import Thread
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import PatternMatchingEventHandler
|
||||
|
@ -64,10 +64,10 @@ class Processes(DotDict):
|
|||
|
||||
def load_service(self, name, filename):
|
||||
try:
|
||||
if self.get(name):
|
||||
try:
|
||||
self[name].reload_config()
|
||||
|
||||
else:
|
||||
except KeyError:
|
||||
self[name] = Process(filename)
|
||||
|
||||
return True
|
||||
|
@ -109,7 +109,7 @@ class Process:
|
|||
|
||||
|
||||
def __init__(self, filename):
|
||||
self.config = Config(filename,
|
||||
self.config = JsonConfig(filename,
|
||||
name = 'noname',
|
||||
fullname = 'no name',
|
||||
description = 'No description',
|
||||
|
@ -124,11 +124,15 @@ class Process:
|
|||
log_keep = 5
|
||||
)
|
||||
|
||||
if not self.config.load():
|
||||
raise FileNotFoundError(f'Not a valid service: {name}')
|
||||
try:
|
||||
self.config.load()
|
||||
|
||||
except FileNotFoundError:
|
||||
raise FileNotFoundError(f'Not a valid service: {self.name}')
|
||||
|
||||
self.log = path.log.join(f'{self.name}.log')
|
||||
self.proc = None
|
||||
self._autostart = None
|
||||
self._stdout = None
|
||||
self._running = False
|
||||
|
||||
|
@ -238,6 +242,8 @@ class Process:
|
|||
stderr = self._stdout
|
||||
)
|
||||
|
||||
self._running = True
|
||||
|
||||
if self['autorestart'] and first_start:
|
||||
Thread(target=self.handle_restart).start()
|
||||
|
||||
|
@ -269,7 +275,6 @@ class Process:
|
|||
|
||||
|
||||
def handle_restart(self):
|
||||
self._running = True
|
||||
retries = 0
|
||||
|
||||
while self._running:
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from izzylib.http_client import HttpClient
|
||||
from barkshark_http_async import Client
|
||||
|
||||
from . import info
|
||||
|
||||
|
||||
client = HttpClient(
|
||||
client = Client(
|
||||
appagent = f'{info["name"]}/{info["version_str"]}'
|
||||
)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from datetime import timedelta
|
||||
from izzylib.http_server_async import error
|
||||
from barkshark_http_async.server import error
|
||||
|
||||
from .config import password
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import asyncio, platform
|
||||
|
||||
from barkshark_http_async.server import Application
|
||||
from izzylib import logging
|
||||
from izzylib.http_server_async import Application
|
||||
|
||||
from . import web, api, middleware
|
||||
from .config import config, path, password
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import shlex
|
||||
|
||||
from barkshark_http_async import View
|
||||
from barkshark_http_async.server import error
|
||||
from datetime import timedelta
|
||||
from izzylib import boolean
|
||||
from izzylib.http_server_async import View, error
|
||||
|
||||
from .config import password
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"bin": "~/.local/share/venv/pypanel/bin/python",
|
||||
"bin": "~/.local/share/python-env/pypanel/bin/python",
|
||||
"args": ["-m", "pypanel"],
|
||||
"env": {"LOG_LEVEL": "DEBUG", "GUI": "true"},
|
||||
"path": "./pypanel",
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
izzylib[http_server_async,template] @ git+https://git.barkshark.xyz/izaliamae/izzylib@7023f4fa40323f33b1ccebcb2b46ff1b6fae12cd
|
||||
watchdog
|
||||
izzylib @ git+https://git.barkshark.xyz/izaliamae/izzylib
|
||||
barkshark-http-async @ git+https://git.barkshark.xyz/izaliamae/barkshark-http-async
|
||||
watchdog==2.1.6
|
||||
|
|
|
@ -28,7 +28,8 @@ python_requires = >= 3.8
|
|||
packages =
|
||||
pypanel
|
||||
install_requires =
|
||||
izzylib[http_server_async,template] @ git+https://git.barkshark.xyz/izaliamae/izzylib@7023f4fa40323f33b1ccebcb2b46ff1b6fae12cd
|
||||
izzylib @ git+https://git.barkshark.xyz/izaliamae/izzylib
|
||||
barkshark-http-async @ git+https://git.barkshark.xyz/izaliamae/barkshark-http-async
|
||||
watchdog
|
||||
setup_requires =
|
||||
setuptools >= 38.3.0
|
||||
|
|
Loading…
Reference in a new issue