reformatted: black

This commit is contained in:
boyska 2020-08-04 10:16:24 +02:00
parent ef38515559
commit c3c837b7f4
3 changed files with 54 additions and 42 deletions

View file

@ -4,30 +4,22 @@ This module contains a flask blueprint for db administration stuff
Templates are self-contained in this directory
"""
from __future__ import print_function
import os
from datetime import datetime, timedelta, time
from collections import defaultdict
import mimetypes
import os
from collections import defaultdict
from datetime import datetime, time, timedelta
from flask import (
current_app,
Blueprint,
Response,
render_template,
jsonify,
abort,
request,
redirect,
url_for,
flash,
)
from flask import (Blueprint, Response, abort, current_app, flash, jsonify,
redirect, render_template, request, url_for)
from larigira.entrypoints_utils import get_avail_entrypoints
from larigira.audiogen import get_audiogenerator
from larigira.timegen_every import FrequencyAlarm
from larigira.timegen import get_timegenerator, timegenerate
from larigira import forms
from larigira.audiogen import get_audiogenerator
from larigira.config import get_conf
from larigira.entrypoints_utils import get_avail_entrypoints
from larigira.timegen import get_timegenerator, timegenerate
from larigira.timegen_every import FrequencyAlarm
from .suggestions import get_suggestions
db = Blueprint(
@ -39,10 +31,13 @@ db = Blueprint(
def request_wants_json():
best = request.accept_mimetypes.best_match(["application/json", "text/html"])
best = request.accept_mimetypes.best_match(
["application/json", "text/html"]
)
return (
best == "application/json"
and request.accept_mimetypes[best] > request.accept_mimetypes["text/html"]
and request.accept_mimetypes[best]
> request.accept_mimetypes["text/html"]
)
@ -68,19 +63,21 @@ def events_calendar():
model = current_app.larigira.controller.monitor.model
today = datetime.now().date()
max_days = 30
max_occurrences = get_conf()["UI_CALENDAR_OCCURRENCIES_THRESHOLD"]
max_occurrences = get_conf()["UI_CALENDAR_OCCURRENCIES_THRESHOLD"]
# {date: {datetime: [(alarm1,actions1), (alarm2,actions2)]}}
days = defaultdict(lambda: defaultdict(list))
show_all = (request.args.get('all', '0') == '1')
show_all = request.args.get("all", "0") == "1"
for alarm in model.get_all_alarms():
actions = tuple(model.get_actions_by_alarm(alarm))
if not actions:
continue
t = datetime.fromtimestamp(int(today.strftime("%s")))
occurrences = [ t for t in timegenerate(alarm, now=t, howmany=max_occurrences +
1) if t is not None and t <= datetime.combine(
today + timedelta(days=max_days), time()
)]
occurrences = [
t
for t in timegenerate(alarm, now=t, howmany=max_occurrences + 1)
if t is not None
and t <= datetime.combine(today + timedelta(days=max_days), time())
]
if not occurrences:
continue
if not show_all and len(occurrences) > max_occurrences:
@ -93,8 +90,9 @@ def events_calendar():
for d in sorted(days.keys()):
weeks[d.isocalendar()[:2]].append(d)
return render_template("calendar.html", days=days, weeks=weeks,
show_all=show_all)
return render_template(
"calendar.html", days=days, weeks=weeks, show_all=show_all
)
@db.route("/add/time")
@ -121,9 +119,15 @@ def edit_time(alarmid):
data = receiver(form)
model.update_alarm(alarmid, data)
model.reload()
return redirect(url_for("db.events_calendar", highlight="%d" % alarmid))
return redirect(
url_for("db.events_calendar", highlight="%d" % alarmid)
)
return render_template(
"add_time_kind.html", form=form, kind=kind, mode="edit", alarmid=alarmid
"add_time_kind.html",
form=form,
kind=kind,
mode="edit",
alarmid=alarmid,
)
@ -150,7 +154,9 @@ def addtime_kind(kind):
resp.status_code = 400
return resp
return render_template("add_time_kind.html", form=form, kind=kind, mode="add")
return render_template(
"add_time_kind.html", form=form, kind=kind, mode="add"
)
@db.route("/add/audio")
@ -180,7 +186,10 @@ def addaudio_kind(kind):
return resp
return render_template(
"add_audio_kind.html", form=form, kind=kind, suggestions=get_suggestions()
"add_audio_kind.html",
form=form,
kind=kind,
suggestions=get_suggestions(),
)

View file

@ -15,7 +15,6 @@ from .timegen import timegenerate
monkey.patch_all(subprocess=True)
logging.getLogger("mpd").setLevel(logging.WARNING)
@ -54,6 +53,7 @@ class Monitor(ParentedLet):
logging.exception(
"Could not generate " "an alarm from timespec %s", timespec
)
return None
if when is None:
# expired
return None
@ -109,7 +109,9 @@ class Monitor(ParentedLet):
if delta is None:
delta = self._alarm_missing_time(timespec)
audiogen = gevent.spawn_later(delta, self.process_action, timespec, audiospecs)
audiogen = gevent.spawn_later(
delta, self.process_action, timespec, audiospecs
)
audiogen.parent_greenlet = self
audiogen.doc = 'Will wait {} seconds, then generate audio "{}"'.format(
delta, ",".join(aspec.get("nick", "") for aspec in audiospecs)

View file

@ -16,9 +16,9 @@ import gevent
from gevent import monkey
from gevent.pywsgi import WSGIServer
from .config import get_conf
from .mpc import Controller, get_mpd_client
from .rpc import create_app
from larigira.config import get_conf
from larigira.mpc import Controller, get_mpd_client
from larigira.rpc import create_app
monkey.patch_all(subprocess=True)
@ -28,8 +28,6 @@ def on_main_crash(*args, **kwargs):
sys.exit(1)
class Larigira(object):
def __init__(self):
@ -38,7 +36,8 @@ class Larigira(object):
self.controller = Controller(self.conf)
self.controller.link_exception(on_main_crash)
self.http_server = WSGIServer(
("", int(self.conf["HTTP_PORT"])), create_app(self.controller.q, self)
("", int(self.conf["HTTP_PORT"])),
create_app(self.controller.q, self),
)
def start(self):
@ -71,7 +70,9 @@ def main():
get_conf()["LOG_CONFIG"], disable_existing_loggers=True
)
else:
log_format = "%(asctime)s|%(levelname)s[%(name)s:%(lineno)d] %(message)s"
log_format = (
"%(asctime)s|%(levelname)s[%(name)s:%(lineno)d] %(message)s"
)
logging.basicConfig(
level=logging.DEBUG if get_conf()["DEBUG"] else logging.INFO,
format=log_format,