Skip to content

Commit

Permalink
Adds file stats
Browse files Browse the repository at this point in the history
  • Loading branch information
pythad committed Aug 30, 2021
1 parent 8073c83 commit 79e44c7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,3 @@ docker rm harnic
- Query params compare only keys
- modal with size too big
- Show first bytes of too big content
- Eeturn files info to stats (bytes, num lines)
6 changes: 5 additions & 1 deletion harnic/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import argparse
import logging
import os
import shutil
import sys
from distutils.dir_util import copy_tree

from termcolor import colored

from harnic.compare import har_compare
from harnic.har import HAR
from harnic.render import render_diff_to_json
Expand Down Expand Up @@ -45,4 +46,7 @@
file_js.write(diffjson)
file_js.write(';')
logger.info('Comparison artifacts generated: %r', out_dir)
logger.info(f'\n')
logger.info(h1.pretty_repr())
logger.info(h2.pretty_repr())
logger.info(f'\n\nComparison stats:\n{format_diff_stats(diff.stats)}')
14 changes: 14 additions & 0 deletions harnic/har.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from pathlib import Path

from termcolor import colored

from harnic.reader import load
from harnic.utils import sizeof_fmt


class HAR:
Expand All @@ -16,3 +21,12 @@ def _sort(self, by='ts'):
self.entries.sort(key=lambda e: e.request.get('_ts'))
else:
raise NotImplementedError()

@property
def size(self):
return Path(self.path).stat().st_size

def pretty_repr(self):
name = colored(self.path, "yellow")
num_entries = len(self.entries)
return f'{name}: {num_entries} entries, {sizeof_fmt(self.size)}'
2 changes: 2 additions & 0 deletions harnic/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import unittest

from termcolor import colored

from harnic.compare import har_compare
from harnic.compare.har import create_compact_records_index
from harnic.har import HAR
Expand Down
8 changes: 8 additions & 0 deletions harnic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ def get_match_ratio(ratio):
)
headers = ["", "Strict order", "With Reorders"]
return tabulate(table, headers=headers, tablefmt='github')


def sizeof_fmt(num, suffix='b'):
for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ python-dateutil==2.8.2
six==1.16.0
tabulate==0.8.9
tqdm==4.62.1
termcolor==1.1.0

0 comments on commit 79e44c7

Please sign in to comment.