feat(check): vérifie la cohérence de la description de la base de donnée de drupal

wip_revisions
François Poulain 2 years ago
parent 65fef05364
commit c5e369e873
  1. 3
      drupal2spip_lal/base/apps.py
  2. 61
      drupal2spip_lal/base/checks.py

@ -4,3 +4,6 @@ from django.apps import AppConfig
class BaseConfig(AppConfig):
name = 'drupal2spip_lal.base'
verbose_name = "Base"
def ready(self):
from . import checks # noqa

@ -0,0 +1,61 @@
import io
from difflib import unified_diff
from django.core.checks import Error, Warning, register
from django.core.management import call_command
no_models = Warning(
"Unable to import drupal2spip_lal/drupal/models.py",
hint='Verify your database settings and that your DB has been '
'inspected.',
obj='drupal2spip_lal.base',
id='drupal2spip_lal.W003',
)
@register()
def check_inspected_database(app_configs, **kwargs):
buf = io.StringIO()
rc = call_command('inspectdb', '--database=drupal', stdout=buf)
if rc is not None:
return [
Error(
"Command inspectdb failed.",
hint='Try to launch "./manage.py inspectdb --database=drupal" '
'and report an issue to <tech@cliss21.org>.',
obj='drupal2spip_lal.base',
id='drupal2spip_lal.E001',
)
]
buf.seek(0)
inspected_db = buf.read()
buf.close()
try:
with open('drupal2spip_lal/drupal/models.py', 'r') as f:
if f.read() != inspected_db:
f.seek(0)
for line in unified_diff(
f.read().split('\n'), inspected_db.split('\n')
):
print(line)
return [
Warning(
"Outdated drupal2spip_lal/drupal/models.py",
hint='Refresh it using "make inspectdb" '
'and then run migrations.',
obj='drupal2spip_lal.base',
id='drupal2spip_lal.W002',
)
]
except Exception:
return [
Warning(
"Missing drupal2spip_lal/drupal/models.py",
hint='Create it using "make inspectdb" '
'and then run migrations.',
obj='drupal2spip_lal.base',
id='drupal2spip_lal.W001',
)
]
return []
Loading…
Cancel
Save