From 41fa8846e463d042128f36af70dc548f092a40fd Mon Sep 17 00:00:00 2001 From: Pratikrocks Date: Fri, 13 Mar 2020 00:45:42 +0530 Subject: [PATCH] Added a cli arguments which will be displayed after the deltas are compared Signed-off-by: Pratikrocks --- src/deltacode/__init__.py | 20 ++++++++++++++++++++ src/deltacode/cli.py | 28 ++++++++++++++++++++++++---- src/deltacode/utils.py | 2 +- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/deltacode/__init__.py b/src/deltacode/__init__.py index 4aa06468..b7b86a3a 100644 --- a/src/deltacode/__init__.py +++ b/src/deltacode/__init__.py @@ -345,6 +345,26 @@ def to_dict(self): ('new', new_file), ('old', old_file), ]) + def __str__(self): + + if self.old_file: + old_file_path = self.old_file.original_path + else: + old_file_path = "null" + + if self.new_file: + new_file_path = self.new_file.original_path + else: + new_file_path = "null" + + return (" {\n"+ + " status: " + str(self.status) + "\n" + " factors: [" + ", ".join(self.factors) + "]\n" + + " score: " + str(self.score) + "\n"+ + " new_file: " + new_file_path + "\n"+ + " old_file: " + old_file_path + "\n" + + " }\n" + ) class Stat(object): """ diff --git a/src/deltacode/cli.py b/src/deltacode/cli.py index fc3c0e48..7a993700 100644 --- a/src/deltacode/cli.py +++ b/src/deltacode/cli.py @@ -50,11 +50,31 @@ def write_json(deltacode, outfile, all_delta_types=False): ('deltas_count', len([d for d in deltas(deltacode, all_delta_types)])), ('delta_stats', deltacode.stats.to_dict()), ('deltas', deltas(deltacode, all_delta_types)) - ]) + ]) + + try: + + simplejson.dump(results, outfile, iterable_as_array=True, indent=2) + outfile.write('\n') + if outfile.name != '' : + "This condition arises when we are required to print in the json file and the value of -j in not the console terminal" + click.echo('deltas_count: {}'.format(len([d for d in deltas(deltacode, all_delta_types)]))) + click.echo('delta_stats: ') + for stat in deltacode.stats.to_dict(): + click.echo(""" "{}": {}""".format(str(stat),deltacode.stats.to_dict()[stat])) + # TODO: add toggle for pretty printing + + delta_count = 1 + for delta in deltacode.deltas : + if delta.status != "unmodified": + click.echo("delta {}".format(delta_count)) + click.echo(delta) + delta_count += 1 - # TODO: add toggle for pretty printing - simplejson.dump(results, outfile, iterable_as_array=True, indent=2) - outfile.write('\n') + except Exception as e: + "This exception arises when outfile has no name attribute" + simplejson.dump(results, outfile, iterable_as_array=True, indent=2) + outfile.write('\n') def print_version(ctx, param, value): diff --git a/src/deltacode/utils.py b/src/deltacode/utils.py index de82f07e..6824bfca 100644 --- a/src/deltacode/utils.py +++ b/src/deltacode/utils.py @@ -275,7 +275,7 @@ def get_notice(): delimiter = '\n\n\n' [notice_text, extra_notice_text] = notice_text.split(delimiter, 1) extra_notice_text = delimiter + extra_notice_text - + delimiter = '\n\n ' [notice_text, acknowledgment_text] = notice_text.split(delimiter, 1) acknowledgment_text = delimiter + acknowledgment_text