feat(check): vérifie la cohérence de la description des bases de données drupal et spip
This commit is contained in:
parent
19ba4772fb
commit
b0a5d0d02f
|
@ -4,25 +4,21 @@ from difflib import unified_diff
|
||||||
from django.core.checks import Error, Warning, register
|
from django.core.checks import Error, Warning, register
|
||||||
from django.core.management import call_command
|
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()
|
@register()
|
||||||
def check_inspected_database(app_configs, **kwargs):
|
def check_inspected_databases(app_configs, **kwargs):
|
||||||
|
return check_inspected_db('drupal') + check_inspected_db('spip')
|
||||||
|
|
||||||
|
|
||||||
|
def check_inspected_db(dbname):
|
||||||
buf = io.StringIO()
|
buf = io.StringIO()
|
||||||
rc = call_command('inspectdb', '--database=drupal', stdout=buf)
|
rc = call_command('inspectdb', '--database', dbname, stdout=buf)
|
||||||
if rc is not None:
|
if rc is not None:
|
||||||
return [
|
return [
|
||||||
Error(
|
Error(
|
||||||
"Command inspectdb failed.",
|
"Command inspectdb failed.",
|
||||||
hint='Try to launch "./manage.py inspectdb --database=drupal" '
|
hint='Try to launch "./manage.py inspectdb --database={}" '
|
||||||
'and report an issue to <tech@cliss21.org>.',
|
'and report an issue.'.format(dbname),
|
||||||
obj='drupal2spip_lal.base',
|
obj='drupal2spip_lal.base',
|
||||||
id='drupal2spip_lal.E001',
|
id='drupal2spip_lal.E001',
|
||||||
)
|
)
|
||||||
|
@ -32,7 +28,7 @@ def check_inspected_database(app_configs, **kwargs):
|
||||||
inspected_db = buf.read()
|
inspected_db = buf.read()
|
||||||
buf.close()
|
buf.close()
|
||||||
try:
|
try:
|
||||||
with open('drupal2spip_lal/drupal/models.py', 'r') as f:
|
with open('drupal2spip_lal/{}/models.py'.format(dbname), 'r') as f:
|
||||||
if f.read() != inspected_db:
|
if f.read() != inspected_db:
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
for line in unified_diff(
|
for line in unified_diff(
|
||||||
|
@ -41,9 +37,8 @@ def check_inspected_database(app_configs, **kwargs):
|
||||||
print(line)
|
print(line)
|
||||||
return [
|
return [
|
||||||
Warning(
|
Warning(
|
||||||
"Outdated drupal2spip_lal/drupal/models.py",
|
"Outdated drupal2spip_lal/{}/models.py".format(dbname),
|
||||||
hint='Refresh it using "make inspectdb" '
|
hint='Refresh it using "make inspectdb".',
|
||||||
'and then run migrations.',
|
|
||||||
obj='drupal2spip_lal.base',
|
obj='drupal2spip_lal.base',
|
||||||
id='drupal2spip_lal.W002',
|
id='drupal2spip_lal.W002',
|
||||||
)
|
)
|
||||||
|
@ -51,9 +46,8 @@ def check_inspected_database(app_configs, **kwargs):
|
||||||
except Exception:
|
except Exception:
|
||||||
return [
|
return [
|
||||||
Warning(
|
Warning(
|
||||||
"Missing drupal2spip_lal/drupal/models.py",
|
"Missing drupal2spip_lal/{}/models.py".format(dbname),
|
||||||
hint='Create it using "make inspectdb" '
|
hint='Create it using "make inspectdb".',
|
||||||
'and then run migrations.',
|
|
||||||
obj='drupal2spip_lal.base',
|
obj='drupal2spip_lal.base',
|
||||||
id='drupal2spip_lal.W001',
|
id='drupal2spip_lal.W001',
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue