2024-06-22 19:15:37 +00:00
|
|
|
#
|
|
|
|
# Copyright 2024 © AE UTBM
|
|
|
|
# ae@utbm.fr / ae.info@utbm.fr
|
|
|
|
#
|
|
|
|
# This file is part of the website of the UTBM Student Association (AE UTBM),
|
|
|
|
# https://ae.utbm.fr.
|
|
|
|
#
|
2024-09-22 23:37:25 +00:00
|
|
|
# You can find the source code of the website at https://github.com/ae-utbm/sith
|
2024-06-22 19:15:37 +00:00
|
|
|
#
|
|
|
|
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
|
2024-09-23 08:25:27 +00:00
|
|
|
# SEE : https://raw.githubusercontent.com/ae-utbm/sith/master/LICENSE
|
2024-06-22 19:15:37 +00:00
|
|
|
# OR WITHIN THE LOCAL FILE "LICENSE"
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
from pathlib import Path
|
|
|
|
|
2024-06-24 11:07:36 +00:00
|
|
|
import tomli
|
|
|
|
from django.core.management.base import BaseCommand, CommandParser
|
|
|
|
|
2024-06-22 19:15:37 +00:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = "Install xapian"
|
|
|
|
|
|
|
|
def add_arguments(self, parser: CommandParser):
|
|
|
|
parser.add_argument(
|
|
|
|
"-f",
|
|
|
|
"--force",
|
|
|
|
action="store_true",
|
|
|
|
help="Force installation even if already installed",
|
|
|
|
)
|
|
|
|
|
|
|
|
def _current_version(self) -> str | None:
|
|
|
|
try:
|
|
|
|
import xapian
|
|
|
|
except ImportError:
|
|
|
|
return None
|
|
|
|
return xapian.version_string()
|
|
|
|
|
|
|
|
def _desired_version(self) -> str:
|
|
|
|
with open(
|
|
|
|
Path(__file__).parent.parent.parent.parent / "pyproject.toml", "rb"
|
|
|
|
) as f:
|
|
|
|
pyproject = tomli.load(f)
|
|
|
|
return pyproject["tool"]["xapian"]["version"]
|
|
|
|
|
2024-06-27 12:57:40 +00:00
|
|
|
def handle(self, *args, force: bool, **options):
|
2024-06-22 19:15:37 +00:00
|
|
|
if not os.environ.get("VIRTUAL_ENV", None):
|
2024-08-06 09:42:10 +00:00
|
|
|
self.stdout.write(
|
|
|
|
"No virtual environment detected, this command can't be used"
|
|
|
|
)
|
2024-06-22 19:15:37 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
desired = self._desired_version()
|
|
|
|
if desired == self._current_version():
|
|
|
|
if not force:
|
2024-08-06 09:42:10 +00:00
|
|
|
self.stdout.write(
|
2024-06-22 19:15:37 +00:00
|
|
|
f"Version {desired} is already installed, use --force to re-install"
|
|
|
|
)
|
|
|
|
return
|
2024-08-06 09:42:10 +00:00
|
|
|
self.stdout.write(f"Version {desired} is already installed, re-installing")
|
|
|
|
self.stdout.write(
|
|
|
|
f"Installing xapian version {desired} at {os.environ['VIRTUAL_ENV']}"
|
|
|
|
)
|
2024-06-22 19:15:37 +00:00
|
|
|
subprocess.run(
|
|
|
|
[str(Path(__file__).parent / "install_xapian.sh"), desired],
|
|
|
|
env=dict(os.environ),
|
|
|
|
).check_returncode()
|
2024-08-06 09:42:10 +00:00
|
|
|
self.stdout.write("Installation success")
|