Skip to content

Commit

Permalink
Merge pull request #131 from paulocheque/better-report
Browse files Browse the repository at this point in the history
Better compatibility check report
  • Loading branch information
paulocheque committed Mar 29, 2020
2 parents bc354a0 + aa34933 commit 6252f9e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
39 changes: 28 additions & 11 deletions django_dynamic_fixture/script_ddf_checkings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ def red(string):
def green(string):
return color('92', string)

def yellow(string):
return color('93', string)

def ddf_check_models(application_labels=[], exclude_application_labels=[], csv_filename='ddf_compatibility_report.csv'):

def ddf_check_models(application_labels=[], exclude_application_labels=[], print_csv=False, csv_filename=None):
from django_dynamic_fixture import get

succeeded = {}
Expand All @@ -35,8 +38,14 @@ def ddf_check_models(application_labels=[], exclude_application_labels=[], csv_f
errors[ref] = '[{}] {}'.format(type(e), str(e))

console_report(succeeded, errors)
if csv_filename:
csv_report(succeeded, errors, filename=csv_filename)
if print_csv or csv_filename:
content = csv_report(succeeded, errors)
if print_csv:
print(yellow('\nCSV Report.\n'))
print(content)
if csv_filename:
print(yellow('\nCSV Report file created: {}.\n'.format(csv_filename)))
save_csv(content, filename=csv_filename)
return succeeded, errors


Expand All @@ -52,12 +61,20 @@ def console_report(succeeded, errors):
print(white('{}. {}: '.format(i, ref)) + red(error))


def csv_report(succeeded, errors, filename):
with open(filename, 'w') as f:
f.write(','.join(['#', 'Model', 'Succeeded', '\n']))
for i, (ref, _) in enumerate(succeeded.items(), start=1):
f.write(','.join([str(i), ref, 'succeeded', '\n']))
def csv_report(succeeded, errors):
SEP = '\t'
LN = '\n'
lines = []
lines.append(SEP.join(['#', 'Model', 'Succeeded']))
for i, (ref, _) in enumerate(succeeded.items(), start=1):
lines.append(SEP.join([str(i), ref, 'succeeded']))

f.write(','.join(['#', 'Model', 'Error', '\n']))
for i, (ref, error) in enumerate(errors.items(), start=1):
f.write(','.join([str(i), ref, error, '\n']))
lines.append(SEP.join(['#', 'Model', 'Error']))
for i, (ref, error) in enumerate(errors.items(), start=1):
lines.append(SEP.join([str(i), ref, error]))
return LN.join(lines)


def save_csv(content, filename):
with open(filename, 'w') as f:
f.write(content)
10 changes: 9 additions & 1 deletion docs/source/more.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ DDF has a simple script that will look for all Django models of all installed Dj
from ddf import ddf_check_models
succeeded, errors = ddf_check_models()

It will also generate a **ddf_compatibility_report.csv** file so you can use it better in a CSV editor.
You can also print in CSV format (using Tabs for separators)::

succeeded, errors = ddf_check_models(print_csv=True)

Or even save the report directly to a CSV file::

succeeded, errors = ddf_check_models(csv_filename='ddf_compatibility_report.csv')

Check for a **ddf_compatibility_report.csv** file in the current directory, so you can use it better in a CSV editor.


Debug Mode (New in 1.6.2)
Expand Down

0 comments on commit 6252f9e

Please sign in to comment.