mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
T2 ruff rule
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user