Skip to content

Commit

Permalink
added the cli by providing delta facttors, status , score and new and…
Browse files Browse the repository at this point in the history
… old file name

Signed-off-by: Pratikrocks <[email protected]>
  • Loading branch information
Pratikrocks committed Mar 22, 2020
1 parent e0f6000 commit 9c39ef0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 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_name = self.old_file.name
else:
old_file_name = "null"

if self.new_file:
new_file_name = self.new_file.name
else:
new_file_name = "null"

return (" {\n"+
" new file: " + new_file_name + "\n"+
" old file: " + old_file_name + "\n" +
" factors: [" + " ".join(self.factors) + "]\n" +
" status: " + str(self.status) + "\n"
" score: " + str(self.score) + "\n"+
" }\n"
)

class Stat(object):
"""
Expand Down
13 changes: 11 additions & 2 deletions src/deltacode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from deltacode import DeltaCode
from deltacode import __version__
from deltacode.utils import deltas, get_notice, collect_errors
from deltacode.utils import deltas, get_notice, collect_errors,get_notice_for_cli


def write_json(deltacode, outfile, all_delta_types=False):
Expand All @@ -51,12 +51,21 @@ def write_json(deltacode, outfile, all_delta_types=False):
('delta_stats', deltacode.stats.to_dict()),
('deltas', deltas(deltacode, all_delta_types))
])
click.secho(get_notice(),fg="green")

click.secho(get_notice_for_cli(),fg="green")
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.secho("Delta {}".format(delta_count),fg="blue")
click.echo(delta)
delta_count += 1
click.secho("--------------------ALL DELTAS GENERATED--------------------",fg="yellow")
simplejson.dump(results, outfile, iterable_as_array=True, indent=2)
outfile.write('\n')

Expand Down
18 changes: 18 additions & 0 deletions src/deltacode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ def check_moved(added_sha1, added_deltas, removed_sha1, removed_deltas):
if added_deltas[0].new_file.name == removed_deltas[0].old_file.name:
return True

def get_notice_for_cli():
"""
Retrieve the notice text from the NOTICE file for display in the Command Line .
"""
notice_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'NOTICE')
notice_text = open(notice_path).read()

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

notice = acknowledgment_text.strip().replace('\n', '')

return notice

def get_notice():
"""
Expand Down

0 comments on commit 9c39ef0

Please sign in to comment.