Convertisseur Drupal 6 vers SPIP pour le site web libre à lire
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
drupal2spip_lal/drupal2spip_lal/base/checks.py

59 lines
1.9 KiB

import io
from difflib import unified_diff
from django.conf import settings
from django.core.checks import Error, Warning, register
from django.core.management import call_command
@register()
def check_inspected_databases(app_configs, **kwargs):
r = []
r += check_inspected_db('drupal')
r += check_inspected_db('spip', tables_prefix=settings.SPIP_TABLES_PREFIX)
return r
def check_inspected_db(dbname, **kwargs):
buf = io.StringIO()
rc = call_command('inspectdb', '--database', dbname, stdout=buf, **kwargs)
if rc is not None:
return [
Error(
"Command inspectdb failed.",
hint='Try to launch "./manage.py inspectdb --database={}" '
'and report an issue.'.format(dbname),
obj='drupal2spip_lal.base',
id='drupal2spip_lal.E001',
)
]
buf.seek(0)
inspected_db = buf.read()
buf.close()
try:
with open('drupal2spip_lal/{}/models.py'.format(dbname), '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/{}/models.py".format(dbname),
hint='Refresh it using "make inspectdb".',
obj='drupal2spip_lal.base',
id='drupal2spip_lal.W002',
)
]
except Exception:
return [
Warning(
"Missing drupal2spip_lal/{}/models.py".format(dbname),
hint='Create it using "make inspectdb".',
obj='drupal2spip_lal.base',
id='drupal2spip_lal.W001',
)
]
return []