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', )