Skip to content

Commit

Permalink
Added a cli arguments which will be displayed after the deltas are co…
Browse files Browse the repository at this point in the history
…mpared

Signed-off-by: Pratikrocks <[email protected]>
  • Loading branch information
Pratikrocks committed Apr 15, 2020
1 parent 6778882 commit 41fa884
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/deltacode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
28 changes: 24 additions & 4 deletions src/deltacode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 != '<stdout>' :
"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):
Expand Down
2 changes: 1 addition & 1 deletion src/deltacode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41fa884

Please sign in to comment.