Skip to content

Commit 2edd57b

Browse files
committed
added the CLI
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
1 parent 6778882 commit 2edd57b

6 files changed

Lines changed: 3642 additions & 3603 deletions

File tree

src/deltacode/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,25 @@ def to_dict(self):
345345
('new', new_file),
346346
('old', old_file),
347347
])
348+
def __str__(self):
349+
350+
if self.old_file:
351+
old_file_path = self.old_file.original_path
352+
else:
353+
old_file_path = "null"
354+
355+
if self.new_file:
356+
new_file_path = self.new_file.original_path
357+
else:
358+
new_file_path = "null"
359+
360+
return (
361+
" status: " + str(self.status) + "\n"
362+
" factors: [" + ", ".join(self.factors) + "]\n" +
363+
" score: " + str(self.score) + "\n"+
364+
" new_file: " + new_file_path + "\n"+
365+
" old_file: " + old_file_path + "\n"
366+
)
348367

349368
class Stat(object):
350369
"""

src/deltacode/cli.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,31 @@ def write_json(deltacode, outfile, all_delta_types=False):
5050
('deltas_count', len([d for d in deltas(deltacode, all_delta_types)])),
5151
('delta_stats', deltacode.stats.to_dict()),
5252
('deltas', deltas(deltacode, all_delta_types))
53-
])
53+
])
54+
55+
try:
56+
57+
simplejson.dump(results, outfile, iterable_as_array=True, indent=2)
58+
outfile.write('\n')
59+
if outfile.name != '<stdout>' :
60+
"This condition arises when we are required to print in the json file and the value of -j in not the console terminal"
61+
click.echo('deltas_count: {}'.format(len([d for d in deltas(deltacode, all_delta_types)])))
62+
click.echo('delta_stats: ')
63+
for stat in deltacode.stats.to_dict():
64+
click.echo(""" "{}": {}""".format(str(stat),deltacode.stats.to_dict()[stat]))
65+
# TODO: add toggle for pretty printing
66+
67+
delta_count = 1
68+
for delta in deltacode.deltas :
69+
if delta.status != "unmodified":
70+
click.echo("delta {}".format(delta_count))
71+
click.echo(delta)
72+
delta_count += 1
5473

55-
# TODO: add toggle for pretty printing
56-
simplejson.dump(results, outfile, iterable_as_array=True, indent=2)
57-
outfile.write('\n')
74+
except Exception as e:
75+
"This exception arises when outfile has no name attribute"
76+
simplejson.dump(results, outfile, iterable_as_array=True, indent=2)
77+
outfile.write('\n')
5878

5979

6080
def print_version(ctx, param, value):

src/deltacode/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def index_files(self, index_key='path'):
155155
keyed by the File object's 'path' variable. This function does not
156156
currently catch the AttributeError exception.
157157
"""
158-
index = {}
158+
index = OrderedDict()
159159

160160
for f in self.files:
161161
key = getattr(f, index_key)

0 commit comments

Comments
 (0)