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