lint: various non-semantic fixes
bumping fail-under for pylint to 9.72
This commit is contained in:
parent
7a54e4ea96
commit
f6452cb4fa
14 changed files with 47 additions and 29 deletions
|
@ -1,7 +1,7 @@
|
||||||
[MASTER]
|
[MASTER]
|
||||||
disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
disable=missing-module-docstring,missing-class-docstring,missing-function-docstring
|
||||||
extension-pkg-whitelist=pydantic
|
extension-pkg-whitelist=pydantic
|
||||||
fail-under=9.5
|
fail-under=9.72
|
||||||
ignored-classes=Column
|
ignored-classes=Column
|
||||||
load-plugins=pylint_flask,pylint_flask_sqlalchemy,pylint_pydantic
|
load-plugins=pylint_flask,pylint_flask_sqlalchemy,pylint_pydantic
|
||||||
max-line-length=120
|
max-line-length=120
|
||||||
|
|
|
@ -39,8 +39,8 @@ def mirror_mapping() -> Dict[str, Union[str, Dict[str, str]]]:
|
||||||
d.url.lstrip("https://"): MMMirror(
|
d.url.lstrip("https://"): MMMirror(
|
||||||
origin_domain=d.origin.description[len("proxy:"):] if d.origin.description.startswith(
|
origin_domain=d.origin.description[len("proxy:"):] if d.origin.description.startswith(
|
||||||
"proxy:") else d.origin.domain_name,
|
"proxy:") else d.origin.domain_name,
|
||||||
origin_domain_normalized=d.origin.description[len("proxy:"):].replace("www.",
|
origin_domain_normalized=d.origin.description[
|
||||||
"") if d.origin.description.startswith(
|
len("proxy:"):].replace("www.", "") if d.origin.description.startswith(
|
||||||
"proxy:") else d.origin.domain_name.replace("www.", ""),
|
"proxy:") else d.origin.domain_name.replace("www.", ""),
|
||||||
origin_domain_root=extract(d.origin.description[len("proxy:"):] if d.origin.description.startswith(
|
origin_domain_root=extract(d.origin.description[len("proxy:"):] if d.origin.description.startswith(
|
||||||
"proxy:") else d.origin.domain_name).registered_domain
|
"proxy:") else d.origin.domain_name).registered_domain
|
||||||
|
|
|
@ -86,9 +86,8 @@ class AbstractResource(db.Model): # type: ignore
|
||||||
self.deprecation_reason = reason
|
self.deprecation_reason = reason
|
||||||
self.updated = datetime.utcnow()
|
self.updated = datetime.utcnow()
|
||||||
return True
|
return True
|
||||||
else:
|
logging.info("Not deprecating %s (reason=%s) because it's already deprecated", self.brn, reason)
|
||||||
logging.info("Not deprecating %s (reason=%s) because it's already deprecated", self.brn, reason)
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
def destroy(self) -> None:
|
def destroy(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -3,6 +3,7 @@ from typing import Any, Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from app.brm.brn import BRN
|
||||||
from app.models import AbstractConfiguration
|
from app.models import AbstractConfiguration
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
|
||||||
|
@ -49,6 +50,16 @@ class Webhook(AbstractConfiguration):
|
||||||
format = db.Column(db.String(20))
|
format = db.Column(db.String(20))
|
||||||
url = db.Column(db.String(255))
|
url = db.Column(db.String(255))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def brn(self) -> BRN:
|
||||||
|
return BRN(
|
||||||
|
group_id=0,
|
||||||
|
product="notify",
|
||||||
|
provider=self.format,
|
||||||
|
resource_type="conf",
|
||||||
|
resource_id=self.id
|
||||||
|
)
|
||||||
|
|
||||||
def send(self, text: str) -> None:
|
def send(self, text: str) -> None:
|
||||||
if self.format == "telegram":
|
if self.format == "telegram":
|
||||||
data = {"text": text}
|
data = {"text": text}
|
||||||
|
|
|
@ -3,6 +3,7 @@ from datetime import datetime
|
||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
|
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
from app.models.activity import Activity
|
||||||
|
|
||||||
|
|
||||||
class AlarmState(enum.Enum):
|
class AlarmState(enum.Enum):
|
||||||
|
@ -29,8 +30,6 @@ class Alarm(db.Model): # type: ignore
|
||||||
return [getattr(self, x) for x in self.csv_header()]
|
return [getattr(self, x) for x in self.csv_header()]
|
||||||
|
|
||||||
def update_state(self, state: AlarmState, text: str) -> None:
|
def update_state(self, state: AlarmState, text: str) -> None:
|
||||||
from app.models.activity import Activity
|
|
||||||
|
|
||||||
if self.alarm_state is None:
|
if self.alarm_state is None:
|
||||||
self.alarm_state = AlarmState.UNKNOWN
|
self.alarm_state = AlarmState.UNKNOWN
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
from app.brm.brn import BRN
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.models import AbstractConfiguration, AbstractResource
|
from app.models import AbstractConfiguration, AbstractResource
|
||||||
|
|
||||||
|
@ -15,6 +16,16 @@ class BridgeConf(AbstractConfiguration):
|
||||||
group = db.relationship("Group", back_populates="bridgeconfs")
|
group = db.relationship("Group", back_populates="bridgeconfs")
|
||||||
bridges = db.relationship("Bridge", back_populates="conf")
|
bridges = db.relationship("Bridge", back_populates="conf")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def brn(self) -> BRN:
|
||||||
|
return BRN(
|
||||||
|
group_id=self.group_id,
|
||||||
|
product="bridge",
|
||||||
|
provider="",
|
||||||
|
resource_type="bridgeconf",
|
||||||
|
resource_id=str(self.id)
|
||||||
|
)
|
||||||
|
|
||||||
def destroy(self) -> None:
|
def destroy(self) -> None:
|
||||||
self.destroyed = datetime.utcnow()
|
self.destroyed = datetime.utcnow()
|
||||||
self.updated = datetime.utcnow()
|
self.updated = datetime.utcnow()
|
||||||
|
|
|
@ -74,8 +74,7 @@ def bridgeconf_new(group_id: Optional[int] = None) -> ResponseReturnValue:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash(f"Created new bridge configuration {bridge_conf.id}.", "success")
|
flash(f"Created new bridge configuration {bridge_conf.id}.", "success")
|
||||||
return redirect(url_for("portal.bridgeconf.bridgeconf_list"))
|
return redirect(url_for("portal.bridgeconf.bridgeconf_list"))
|
||||||
except exc.SQLAlchemyError as e:
|
except exc.SQLAlchemyError:
|
||||||
print(e)
|
|
||||||
flash("Failed to create new bridge configuration.", "danger")
|
flash("Failed to create new bridge configuration.", "danger")
|
||||||
return redirect(url_for("portal.bridgeconf.bridgeconf_list"))
|
return redirect(url_for("portal.bridgeconf.bridgeconf_list"))
|
||||||
if group_id:
|
if group_id:
|
||||||
|
|
|
@ -105,8 +105,7 @@ def list_new(group_id: Optional[int] = None) -> ResponseReturnValue:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("Created new mirror list.", "success")
|
flash("Created new mirror list.", "success")
|
||||||
return redirect(url_for("portal.list.list_list"))
|
return redirect(url_for("portal.list.list_list"))
|
||||||
except exc.SQLAlchemyError as e:
|
except exc.SQLAlchemyError:
|
||||||
print(e)
|
|
||||||
flash("Failed to create new mirror list.", "danger")
|
flash("Failed to create new mirror list.", "danger")
|
||||||
return redirect(url_for("portal.list.list_list"))
|
return redirect(url_for("portal.list.list_list"))
|
||||||
if group_id:
|
if group_id:
|
||||||
|
|
|
@ -49,8 +49,7 @@ def onion_new(group_id: Optional[int] = None) -> ResponseReturnValue:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash(f"Created new onion {onion.onion_name}.", "success")
|
flash(f"Created new onion {onion.onion_name}.", "success")
|
||||||
return redirect(url_for("portal.onion.onion_edit", onion_id=onion.id))
|
return redirect(url_for("portal.onion.onion_edit", onion_id=onion.id))
|
||||||
except exc.SQLAlchemyError as e:
|
except exc.SQLAlchemyError:
|
||||||
print(e)
|
|
||||||
flash("Failed to create new onion.", "danger")
|
flash("Failed to create new onion.", "danger")
|
||||||
return redirect(url_for("portal.onion.onion_list"))
|
return redirect(url_for("portal.onion.onion_list"))
|
||||||
if group_id:
|
if group_id:
|
||||||
|
|
|
@ -55,8 +55,7 @@ def origin_new(group_id: Optional[int] = None) -> ResponseReturnValue:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash(f"Created new origin {origin.domain_name}.", "success")
|
flash(f"Created new origin {origin.domain_name}.", "success")
|
||||||
return redirect(url_for("portal.origin.origin_edit", origin_id=origin.id))
|
return redirect(url_for("portal.origin.origin_edit", origin_id=origin.id))
|
||||||
except exc.SQLAlchemyError as e:
|
except exc.SQLAlchemyError:
|
||||||
print(e)
|
|
||||||
flash("Failed to create new origin.", "danger")
|
flash("Failed to create new origin.", "danger")
|
||||||
return redirect(url_for("portal.origin.origin_list"))
|
return redirect(url_for("portal.origin.origin_list"))
|
||||||
if group_id:
|
if group_id:
|
||||||
|
|
|
@ -16,10 +16,10 @@ bp = Blueprint("webhook", __name__)
|
||||||
|
|
||||||
|
|
||||||
@bp.app_template_filter("webhook_format_name")
|
@bp.app_template_filter("webhook_format_name")
|
||||||
def webhook_format_name(format: str) -> str:
|
def webhook_format_name(key: str) -> str:
|
||||||
if format == "telegram":
|
if key == "telegram":
|
||||||
return "Telegram"
|
return "Telegram"
|
||||||
if format == "matrix":
|
if key == "matrix":
|
||||||
return "Matrix"
|
return "Matrix"
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
|
|
||||||
|
|
|
@ -47,5 +47,5 @@ class BaseAutomation(metaclass=ABCMeta):
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
tmpl = jinja2.Template(template)
|
tmpl = jinja2.Template(template)
|
||||||
with open(self.working_directory(filename), 'w', encoding="utf-8") as tf:
|
with open(self.working_directory(filename), 'w', encoding="utf-8") as tfconf:
|
||||||
tf.write(tmpl.render(**kwargs))
|
tfconf.write(tmpl.render(**kwargs))
|
||||||
|
|
|
@ -56,7 +56,7 @@ class BridgeAutomation(TerraformAutomation):
|
||||||
bridge.destroy()
|
bridge.destroy()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def tf_prehook(self) -> Optional[Any]:
|
def tf_prehook(self) -> Optional[Any]: # pylint: disable=useless-return
|
||||||
self.create_missing()
|
self.create_missing()
|
||||||
self.destroy_expired()
|
self.destroy_expired()
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -21,8 +21,8 @@ def obfuscator(obj: Any) -> Any:
|
||||||
def json_encode(obj: Any, obfuscate: bool) -> str:
|
def json_encode(obj: Any, obfuscate: bool) -> str:
|
||||||
if obfuscate:
|
if obfuscate:
|
||||||
obj = obfuscator(obj)
|
obj = obfuscator(obj)
|
||||||
s = json.dumps(obj).replace("!AAA!", "\\u")
|
result = json.dumps(obj, sort_keys=True).replace("!AAA!", "\\u")
|
||||||
return s
|
return result
|
||||||
return json.dumps(obj, indent=2, sort_keys=True)
|
return json.dumps(obj, indent=2, sort_keys=True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,9 +55,11 @@ class ListAutomation(TerraformAutomation):
|
||||||
for k in self.template_parameters
|
for k in self.template_parameters
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
for format_ in lists:
|
for key, formatter in lists.items():
|
||||||
for obfuscate in [True, False]:
|
for obfuscate in [True, False]:
|
||||||
with open(self.working_directory(f"{format_}{'.jsno' if obfuscate else '.json'}"), 'w') as out:
|
with open(self.working_directory(f"{key}{'.jsno' if obfuscate else '.json'}"),
|
||||||
out.write(json_encode(lists[format_](), obfuscate))
|
'w', encoding="utf-8") as out:
|
||||||
with open(self.working_directory(f"{format_}{'.jso' if obfuscate else '.js'}"), 'w') as out:
|
out.write(json_encode(formatter(), obfuscate))
|
||||||
out.write(javascript_encode(lists[format_](), obfuscate))
|
with open(self.working_directory(f"{key}{'.jso' if obfuscate else '.js'}"),
|
||||||
|
'w', encoding="utf-8") as out:
|
||||||
|
out.write(javascript_encode(formatter(), obfuscate))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue