ci: add flake8
This commit is contained in:
parent
014596d271
commit
dd501a6e4e
32 changed files with 170 additions and 171 deletions
|
@ -10,7 +10,6 @@ from app.models.alarms import Alarm, AlarmState
|
|||
from app.models.bridges import Bridge
|
||||
from app.models.mirrors import Origin, Proxy
|
||||
from app.models.base import Group
|
||||
from app.portal.list import NewMirrorListForm
|
||||
from app.portal.automation import bp as automation
|
||||
from app.portal.bridgeconf import bp as bridgeconf
|
||||
from app.portal.bridge import bp as bridge
|
||||
|
@ -53,7 +52,7 @@ def format_datetime(s: Optional[datetime]) -> str:
|
|||
|
||||
def total_origins_blocked() -> int:
|
||||
count = 0
|
||||
for o in Origin.query.filter(Origin.destroyed == None).all():
|
||||
for o in Origin.query.filter(Origin.destroyed.is_(None)).all():
|
||||
for a in o.alarms:
|
||||
if a.alarm_type.startswith("origin-block-ooni-"):
|
||||
if a.alarm_state == AlarmState.WARNING:
|
||||
|
@ -66,7 +65,7 @@ def total_origins_blocked() -> int:
|
|||
def portal_home() -> ResponseReturnValue:
|
||||
groups = Group.query.order_by(Group.group_name).all()
|
||||
now = datetime.now(timezone.utc)
|
||||
proxies = Proxy.query.filter(Proxy.destroyed == None).all()
|
||||
proxies = Proxy.query.filter(Proxy.destroyed.is_(None)).all()
|
||||
last24 = len(Proxy.query.filter(Proxy.deprecated > (now - timedelta(days=1))).all())
|
||||
last72 = len(Proxy.query.filter(Proxy.deprecated > (now - timedelta(days=3))).all())
|
||||
lastweek = len(Proxy.query.filter(Proxy.deprecated > (now - timedelta(days=7))).all())
|
||||
|
@ -74,15 +73,15 @@ def portal_home() -> ResponseReturnValue:
|
|||
s: len(Alarm.query.filter(Alarm.alarm_state == s.upper(), Alarm.last_updated > (now - timedelta(days=1))).all())
|
||||
for s in ["critical", "warning", "ok", "unknown"]
|
||||
}
|
||||
bridges = Bridge.query.filter(Bridge.destroyed == None).all()
|
||||
bridges = Bridge.query.filter(Bridge.destroyed.is_(None)).all()
|
||||
br_last = {
|
||||
d: len(Bridge.query.filter(Bridge.deprecated > (now - timedelta(days=d))).all())
|
||||
for d in [1, 3, 7]
|
||||
}
|
||||
activity = Activity.query.filter(Activity.added > (now - timedelta(days=2))).order_by(desc(Activity.added)).all()
|
||||
onionified = len([o for o in Origin.query.filter(Origin.destroyed == None).all() if o.onion() != None])
|
||||
onionified = len([o for o in Origin.query.filter(Origin.destroyed.is_(None)).all() if o.onion() is not None])
|
||||
ooni_blocked = total_origins_blocked()
|
||||
total_origins = len(Origin.query.filter(Origin.destroyed == None).all())
|
||||
total_origins = len(Origin.query.filter(Origin.destroyed.is_(None)).all())
|
||||
return render_template("home.html.j2", section="home", groups=groups, last24=last24, last72=last72,
|
||||
lastweek=lastweek, proxies=proxies, **alarms, activity=activity, total_origins=total_origins,
|
||||
onionified=onionified, br_last=br_last, ooni_blocked=ooni_blocked, bridges=bridges)
|
||||
|
@ -91,7 +90,7 @@ def portal_home() -> ResponseReturnValue:
|
|||
@portal.route("/search")
|
||||
def search() -> ResponseReturnValue:
|
||||
query = request.args.get("query")
|
||||
proxies = Proxy.query.filter(or_(Proxy.url.contains(query)), Proxy.destroyed == None).all()
|
||||
proxies = Proxy.query.filter(or_(Proxy.url.contains(query)), Proxy.destroyed.is_(None)).all()
|
||||
origins = Origin.query.filter(or_(Origin.description.contains(query), Origin.domain_name.contains(query))).all()
|
||||
return render_template("search.html.j2", section="home", proxies=proxies, origins=origins)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class EditAutomationForm(FlaskForm): # type: ignore
|
|||
@bp.route("/list")
|
||||
def automation_list() -> ResponseReturnValue:
|
||||
automations = Automation.query.filter(
|
||||
Automation.destroyed == None).order_by(Automation.description).all()
|
||||
Automation.destroyed.is_(None)).order_by(Automation.description).all()
|
||||
return render_template("list.html.j2",
|
||||
section="automation",
|
||||
title="Automation Jobs",
|
||||
|
@ -57,11 +57,11 @@ def automation_edit(automation_id: int) -> ResponseReturnValue:
|
|||
def automation_kick(automation_id: int) -> ResponseReturnValue:
|
||||
automation = Automation.query.filter(
|
||||
Automation.id == automation_id,
|
||||
Automation.destroyed == None).first()
|
||||
Automation.destroyed.is_(None)).first()
|
||||
if automation is None:
|
||||
return response_404("The requested bridge configuration could not be found.")
|
||||
return view_lifecycle(
|
||||
header=f"Kick automation timer?",
|
||||
header="Kick automation timer?",
|
||||
message=automation.description,
|
||||
success_view="portal.automation.automation_list",
|
||||
success_message="This automation job will next run within 1 minute.",
|
||||
|
|
|
@ -12,7 +12,7 @@ bp = Blueprint("bridge", __name__)
|
|||
|
||||
@bp.route("/list")
|
||||
def bridge_list() -> ResponseReturnValue:
|
||||
bridges = Bridge.query.filter(Bridge.destroyed == None).all()
|
||||
bridges = Bridge.query.filter(Bridge.destroyed.is_(None)).all()
|
||||
return render_template("list.html.j2",
|
||||
section="bridge",
|
||||
title="Tor Bridges",
|
||||
|
@ -22,7 +22,7 @@ def bridge_list() -> ResponseReturnValue:
|
|||
|
||||
@bp.route("/block/<bridge_id>", methods=['GET', 'POST'])
|
||||
def bridge_blocked(bridge_id: int) -> ResponseReturnValue:
|
||||
bridge: Optional[Bridge] = Bridge.query.filter(Bridge.id == bridge_id, Bridge.destroyed == None).first()
|
||||
bridge: Optional[Bridge] = Bridge.query.filter(Bridge.id == bridge_id, Bridge.destroyed.is_(None)).first()
|
||||
if bridge is None:
|
||||
return Response(render_template("error.html.j2",
|
||||
header="404 Proxy Not Found",
|
||||
|
|
|
@ -33,7 +33,7 @@ class EditBridgeConfForm(FlaskForm): # type: ignore
|
|||
|
||||
@bp.route("/list")
|
||||
def bridgeconf_list() -> ResponseReturnValue:
|
||||
bridgeconfs: List[BridgeConf] = BridgeConf.query.filter(BridgeConf.destroyed == None).all()
|
||||
bridgeconfs: List[BridgeConf] = BridgeConf.query.filter(BridgeConf.destroyed.is_(None)).all()
|
||||
return render_template("list.html.j2",
|
||||
section="bridgeconf",
|
||||
title="Tor Bridge Configurations",
|
||||
|
@ -110,11 +110,11 @@ def bridgeconf_edit(bridgeconf_id: int) -> ResponseReturnValue:
|
|||
|
||||
@bp.route("/destroy/<bridgeconf_id>", methods=['GET', 'POST'])
|
||||
def bridgeconf_destroy(bridgeconf_id: int) -> ResponseReturnValue:
|
||||
bridgeconf = BridgeConf.query.filter(BridgeConf.id == bridgeconf_id, BridgeConf.destroyed == None).first()
|
||||
bridgeconf = BridgeConf.query.filter(BridgeConf.id == bridgeconf_id, BridgeConf.destroyed.is_(None)).first()
|
||||
if bridgeconf is None:
|
||||
return response_404("The requested bridge configuration could not be found.")
|
||||
return view_lifecycle(
|
||||
header=f"Destroy bridge configuration?",
|
||||
header="Destroy bridge configuration?",
|
||||
message=bridgeconf.description,
|
||||
success_view="portal.bridgeconf.bridgeconf_list",
|
||||
success_message="All bridges from the destroyed configuration will shortly be destroyed at their providers.",
|
||||
|
|
|
@ -10,7 +10,7 @@ bp = Blueprint("eotk", __name__)
|
|||
|
||||
@bp.route("/list")
|
||||
def eotk_list() -> ResponseReturnValue:
|
||||
instances = Eotk.query.filter(Eotk.destroyed == None).order_by(desc(Eotk.added)).all()
|
||||
instances = Eotk.query.filter(Eotk.destroyed.is_(None)).order_by(desc(Eotk.added)).all()
|
||||
return render_template("list.html.j2",
|
||||
section="eotk",
|
||||
title="EOTK Instances",
|
||||
|
|
|
@ -31,7 +31,7 @@ def list_format_name(s: str) -> str:
|
|||
|
||||
@bp.route('/list')
|
||||
def list_list() -> ResponseReturnValue:
|
||||
lists = MirrorList.query.filter(MirrorList.destroyed == None).all()
|
||||
lists = MirrorList.query.filter(MirrorList.destroyed.is_(None)).all()
|
||||
return render_template("list.html.j2",
|
||||
section="list",
|
||||
title="Mirror Lists",
|
||||
|
@ -62,11 +62,11 @@ def list_preview(format_: str) -> ResponseReturnValue:
|
|||
|
||||
@bp.route("/destroy/<list_id>", methods=['GET', 'POST'])
|
||||
def list_destroy(list_id: int) -> ResponseReturnValue:
|
||||
list_ = MirrorList.query.filter(MirrorList.id == list_id, MirrorList.destroyed == None).first()
|
||||
list_ = MirrorList.query.filter(MirrorList.id == list_id, MirrorList.destroyed.is_(None)).first()
|
||||
if list_ is None:
|
||||
return response_404("The requested bridge configuration could not be found.")
|
||||
return view_lifecycle(
|
||||
header=f"Destroy mirror list?",
|
||||
header="Destroy mirror list?",
|
||||
message=list_.description,
|
||||
success_view="portal.list.list_list",
|
||||
success_message="This list will no longer be updated and may be deleted depending on the provider.",
|
||||
|
@ -96,7 +96,7 @@ def list_new(group_id: Optional[int] = None) -> ResponseReturnValue:
|
|||
try:
|
||||
db.session.add(list_)
|
||||
db.session.commit()
|
||||
flash(f"Created new mirror list.", "success")
|
||||
flash("Created new mirror list.", "success")
|
||||
return redirect(url_for("portal.list.list_list"))
|
||||
except exc.SQLAlchemyError as e:
|
||||
print(e)
|
||||
|
|
|
@ -97,7 +97,7 @@ def onion_list() -> ResponseReturnValue:
|
|||
|
||||
@bp.route("/destroy/<onion_id>", methods=['GET', 'POST'])
|
||||
def onion_destroy(onion_id: int) -> ResponseReturnValue:
|
||||
onion = Onion.query.filter(Onion.id == onion_id, Onion.destroyed == None).first()
|
||||
onion = Onion.query.filter(Onion.id == onion_id, Onion.destroyed.is_(None)).first()
|
||||
if onion is None:
|
||||
return response_404("The requested onion service could not be found.")
|
||||
return view_lifecycle(
|
||||
|
|
|
@ -115,7 +115,7 @@ def origin_onion() -> ResponseReturnValue:
|
|||
|
||||
@bp.route("/destroy/<origin_id>", methods=['GET', 'POST'])
|
||||
def origin_destroy(origin_id: int) -> ResponseReturnValue:
|
||||
origin = Origin.query.filter(Origin.id == origin_id, Origin.destroyed == None).first()
|
||||
origin = Origin.query.filter(Origin.id == origin_id, Origin.destroyed.is_(None)).first()
|
||||
if origin is None:
|
||||
return response_404("The requested origin could not be found.")
|
||||
return view_lifecycle(
|
||||
|
|
|
@ -11,7 +11,7 @@ bp = Blueprint("proxy", __name__)
|
|||
|
||||
@bp.route("/list")
|
||||
def proxy_list() -> ResponseReturnValue:
|
||||
proxies = Proxy.query.filter(Proxy.destroyed == None).order_by(desc(Proxy.added)).all()
|
||||
proxies = Proxy.query.filter(Proxy.destroyed.is_(None)).order_by(desc(Proxy.added)).all()
|
||||
return render_template("list.html.j2",
|
||||
section="proxy",
|
||||
title="Proxies",
|
||||
|
@ -21,7 +21,7 @@ def proxy_list() -> ResponseReturnValue:
|
|||
|
||||
@bp.route("/block/<proxy_id>", methods=['GET', 'POST'])
|
||||
def proxy_block(proxy_id: int) -> ResponseReturnValue:
|
||||
proxy = Proxy.query.filter(Proxy.id == proxy_id, Proxy.destroyed == None).first()
|
||||
proxy = Proxy.query.filter(Proxy.id == proxy_id, Proxy.destroyed.is_(None)).first()
|
||||
if proxy is None:
|
||||
return Response(render_template("error.html.j2",
|
||||
header="404 Proxy Not Found",
|
||||
|
|
|
@ -48,7 +48,7 @@ def webhook_new() -> ResponseReturnValue:
|
|||
db.session.commit()
|
||||
flash(f"Created new webhook {webhook.url}.", "success")
|
||||
return redirect(url_for("portal.webhook.webhook_edit", webhook_id=webhook.id))
|
||||
except exc.SQLAlchemyError as e:
|
||||
except exc.SQLAlchemyError:
|
||||
flash("Failed to create new webhook.", "danger")
|
||||
return redirect(url_for("portal.webhook.webhook_list"))
|
||||
return render_template("new.html.j2", section="webhook", form=form)
|
||||
|
@ -95,7 +95,7 @@ def webhook_list() -> ResponseReturnValue:
|
|||
|
||||
@bp.route("/destroy/<webhook_id>", methods=['GET', 'POST'])
|
||||
def webhook_destroy(webhook_id: int) -> ResponseReturnValue:
|
||||
webhook: Optional[Webhook] = Webhook.query.filter(Webhook.id == webhook_id, Webhook.destroyed == None).first()
|
||||
webhook: Optional[Webhook] = Webhook.query.filter(Webhook.id == webhook_id, Webhook.destroyed.is_(None)).first()
|
||||
if webhook is None:
|
||||
return response_404("The requested webhook could not be found.")
|
||||
return view_lifecycle(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue