From b0a5d0d02f449bcd9d60a15e05ce018b02d2d1b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Poulain?= Date: Sat, 1 Aug 2020 14:31:45 +0200 Subject: [PATCH] =?UTF-8?q?feat(check):=20v=C3=A9rifie=20la=20coh=C3=A9ren?= =?UTF-8?q?ce=20de=20la=20description=20des=20bases=20de=20donn=C3=A9es=20?= =?UTF-8?q?drupal=20et=20spip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drupal2spip_lal/base/checks.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/drupal2spip_lal/base/checks.py b/drupal2spip_lal/base/checks.py index 6752d12..da8c546 100644 --- a/drupal2spip_lal/base/checks.py +++ b/drupal2spip_lal/base/checks.py @@ -4,25 +4,21 @@ 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): +def check_inspected_databases(app_configs, **kwargs): + return check_inspected_db('drupal') + check_inspected_db('spip') + + +def check_inspected_db(dbname): buf = io.StringIO() - rc = call_command('inspectdb', '--database=drupal', stdout=buf) + rc = call_command('inspectdb', '--database', dbname, 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 .', + hint='Try to launch "./manage.py inspectdb --database={}" ' + 'and report an issue.'.format(dbname), obj='drupal2spip_lal.base', id='drupal2spip_lal.E001', ) @@ -32,7 +28,7 @@ def check_inspected_database(app_configs, **kwargs): inspected_db = buf.read() buf.close() 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: f.seek(0) for line in unified_diff( @@ -41,9 +37,8 @@ def check_inspected_database(app_configs, **kwargs): print(line) return [ Warning( - "Outdated drupal2spip_lal/drupal/models.py", - hint='Refresh it using "make inspectdb" ' - 'and then run migrations.', + "Outdated drupal2spip_lal/{}/models.py".format(dbname), + hint='Refresh it using "make inspectdb".', obj='drupal2spip_lal.base', id='drupal2spip_lal.W002', ) @@ -51,9 +46,8 @@ def check_inspected_database(app_configs, **kwargs): except Exception: return [ Warning( - "Missing drupal2spip_lal/drupal/models.py", - hint='Create it using "make inspectdb" ' - 'and then run migrations.', + "Missing drupal2spip_lal/{}/models.py".format(dbname), + hint='Create it using "make inspectdb".', obj='drupal2spip_lal.base', id='drupal2spip_lal.W001', )