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