mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 07:41:14 +00:00
T2 ruff rule
This commit is contained in:
parent
28d6d8ba96
commit
62bb15317c
@ -20,8 +20,7 @@
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
||||
import sys
|
||||
import logging
|
||||
|
||||
from django.apps import AppConfig
|
||||
from django.core.cache import cache
|
||||
@ -41,7 +40,7 @@ class SithConfig(AppConfig):
|
||||
def clear_cached_memberships(**kwargs):
|
||||
Forum._club_memberships = {}
|
||||
|
||||
print("Connecting signals!", file=sys.stderr)
|
||||
logging.getLogger("django").info("Connecting signals!")
|
||||
request_started.connect(
|
||||
clear_cached_memberships,
|
||||
weak=False,
|
||||
|
@ -48,20 +48,24 @@ class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, force: bool, **options):
|
||||
if not os.environ.get("VIRTUAL_ENV", None):
|
||||
print("No virtual environment detected, this command can't be used")
|
||||
self.stdout.write(
|
||||
"No virtual environment detected, this command can't be used"
|
||||
)
|
||||
return
|
||||
|
||||
desired = self._desired_version()
|
||||
if desired == self._current_version():
|
||||
if not force:
|
||||
print(
|
||||
self.stdout.write(
|
||||
f"Version {desired} is already installed, use --force to re-install"
|
||||
)
|
||||
return
|
||||
print(f"Version {desired} is already installed, re-installing")
|
||||
print(f"Installing xapian version {desired} at {os.environ['VIRTUAL_ENV']}")
|
||||
self.stdout.write(f"Version {desired} is already installed, re-installing")
|
||||
self.stdout.write(
|
||||
f"Installing xapian version {desired} at {os.environ['VIRTUAL_ENV']}"
|
||||
)
|
||||
subprocess.run(
|
||||
[str(Path(__file__).parent / "install_xapian.sh"), desired],
|
||||
env=dict(os.environ),
|
||||
).check_returncode()
|
||||
print("Installation success")
|
||||
self.stdout.write("Installation success")
|
||||
|
@ -35,4 +35,4 @@ class Command(BaseCommand):
|
||||
root_path = settings.BASE_DIR
|
||||
with open(root_path / "core/fixtures/SYNTAX.md", "r") as md:
|
||||
result = markdown(md.read())
|
||||
print(result, end="")
|
||||
self.stdout.write(result)
|
||||
|
@ -24,6 +24,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import logging
|
||||
import os
|
||||
import unicodedata
|
||||
from datetime import date, timedelta
|
||||
@ -1085,19 +1086,15 @@ class SithFile(models.Model):
|
||||
# file storage
|
||||
parent_path = "." + self.parent.get_full_path()
|
||||
parent_full_path = settings.MEDIA_ROOT + parent_path
|
||||
print("Parent full path: %s" % parent_full_path)
|
||||
os.makedirs(parent_full_path, exist_ok=True)
|
||||
old_path = self.file.name # Should be relative: "./users/skia/bleh.jpg"
|
||||
new_path = "." + self.get_full_path()
|
||||
print("Old path: %s " % old_path)
|
||||
print("New path: %s " % new_path)
|
||||
try:
|
||||
# Make this atomic, so that a FS problem rolls back the DB change
|
||||
with transaction.atomic():
|
||||
# Set the new filesystem path
|
||||
self.file.name = new_path
|
||||
self.save()
|
||||
print("New file path: %s " % self.file.path)
|
||||
# Really move at the FS level
|
||||
if os.path.exists(parent_full_path):
|
||||
os.rename(
|
||||
@ -1108,25 +1105,22 @@ class SithFile(models.Model):
|
||||
# problem, and that can be solved with a simple shell
|
||||
# command: `find . -type d -empty -delete`
|
||||
except Exception as e:
|
||||
print("This file likely had a problem. Here is the exception:")
|
||||
print(repr(e))
|
||||
print("-" * 80)
|
||||
logging.error(e)
|
||||
|
||||
def _check_path_consistence(self):
|
||||
file_path = str(self.file)
|
||||
file_full_path = settings.MEDIA_ROOT + file_path
|
||||
db_path = ".%s" % self.get_full_path()
|
||||
if not os.path.exists(file_full_path):
|
||||
print("%s: WARNING: real file does not exists!" % self.id)
|
||||
print("file path: %s" % file_path, end="")
|
||||
print(" db path: %s" % db_path)
|
||||
print("%s: WARNING: real file does not exists!" % self.id) # noqa T201
|
||||
print("file path: %s" % file_path, end="") # noqa T201
|
||||
print(" db path: %s" % db_path) # noqa T201
|
||||
return False
|
||||
if file_path != db_path:
|
||||
print("%s: " % self.id, end="")
|
||||
print("file path: %s" % file_path, end="")
|
||||
print(" db path: %s" % db_path)
|
||||
print("%s: " % self.id, end="") # noqa T201
|
||||
print("file path: %s" % file_path, end="") # noqa T201
|
||||
print(" db path: %s" % db_path) # noqa T201
|
||||
return False
|
||||
print("%s OK (%s)" % (self.id, file_path))
|
||||
return True
|
||||
|
||||
def _check_fs(self):
|
||||
|
@ -22,6 +22,7 @@
|
||||
#
|
||||
#
|
||||
import itertools
|
||||
import logging
|
||||
|
||||
# This file contains all the views that concern the user model
|
||||
from datetime import date, timedelta
|
||||
@ -801,7 +802,7 @@ class UserAccountView(UserAccountBase):
|
||||
product__eticket=None
|
||||
).all()
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
logging.error(e)
|
||||
return kwargs
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
import logging
|
||||
import math
|
||||
from functools import partial
|
||||
|
||||
@ -424,7 +425,7 @@ class ForumMessageCreateView(CanCreateMixin, CreateView):
|
||||
)
|
||||
init["message"] += "\n\n"
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
logging.error(e)
|
||||
return init
|
||||
|
||||
def form_valid(self, form):
|
||||
|
@ -36,11 +36,7 @@ def remove_multiples_comments_from_same_user(apps, schema_editor):
|
||||
.order_by("-publish_date")
|
||||
.first()
|
||||
)
|
||||
for comment in (
|
||||
user.uv_comments.filter(uv__id=uv["uv"]).exclude(pk=last.pk).all()
|
||||
):
|
||||
print("removing : %s" % (comment,))
|
||||
comment.delete()
|
||||
user.uv_comments.filter(uv__id=uv["uv"]).exclude(pk=last.pk).delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -103,6 +103,7 @@ select = [
|
||||
"FBT", # boolean trap
|
||||
"UP008", # Use super() instead of super(__class__, self)
|
||||
"UP009", # utf-8 encoding declaration is unnecessary
|
||||
"T2", # print statements
|
||||
]
|
||||
|
||||
ignore = [
|
||||
|
@ -40,7 +40,7 @@ class Command(BaseCommand):
|
||||
user = User.objects.filter(id=options["user_id"]).first()
|
||||
|
||||
if user is None:
|
||||
print("User with ID %s not found" % (options["user_id"],))
|
||||
self.stderr.write("User with ID %s not found" % (options["user_id"],))
|
||||
exit(1)
|
||||
|
||||
confirm = input(
|
||||
@ -49,7 +49,7 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
if not confirm.lower().startswith("y"):
|
||||
print("Operation aborted")
|
||||
self.stderr.write("Operation aborted")
|
||||
exit(1)
|
||||
|
||||
delete_all_forum_user_messages(user, User.objects.get(id=0), verbose=True)
|
||||
|
@ -21,6 +21,7 @@
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
import logging
|
||||
|
||||
from ajax_select.fields import AutoCompleteSelectField
|
||||
from django import forms
|
||||
@ -146,7 +147,7 @@ def delete_all_forum_user_messages(user, moderator, *, verbose=False):
|
||||
continue
|
||||
|
||||
if verbose:
|
||||
print(message)
|
||||
logging.getLogger("django").info(message)
|
||||
ForumMessageMeta(message=message, user=moderator, action="DELETE").save()
|
||||
|
||||
|
||||
|
@ -34,6 +34,7 @@ https://docs.djangoproject.com/en/1.8/ref/settings/
|
||||
"""
|
||||
|
||||
import binascii
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@ -680,9 +681,9 @@ TOXIC_DOMAINS_PROVIDERS = [
|
||||
try:
|
||||
from .settings_custom import *
|
||||
|
||||
print("Custom settings imported", file=sys.stderr)
|
||||
logging.getLogger("django").info("Custom settings imported")
|
||||
except:
|
||||
print("Custom settings failed", file=sys.stderr)
|
||||
logging.getLogger("django").warning("Custom settings failed")
|
||||
|
||||
if DEBUG:
|
||||
INSTALLED_APPS += ("debug_toolbar",)
|
||||
|
Loading…
Reference in New Issue
Block a user