Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display progress when using extractor CLI #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from importlib import import_module, reload
from tempfile import TemporaryDirectory
from inspect import getmembers, isclass
from sys import platform, path as PATH
from sys import platform, path as PATH, stdout
from os import environ, makedirs, sep
from importlib.util import find_spec
from argparse import ArgumentParser
Expand Down Expand Up @@ -258,6 +258,19 @@ def extractor_main(extractor):
parser.add_argument('output_dir', type=Path, default='.', nargs='?')
args = parser.parse_args()

nb_written, wrote_endpoints = extractor_save(args.output_dir, '', extractor['func'](args.input_))
output = []
last_info = None
# Extractor is runned here
for name, contents in extractor['func'](args.input_):
if name == '_progress':
info, progress = contents
if last_info == info:
stdout.write('\r%s\t%2d%%' % (info, progress*100))
else:
stdout.write("\n" + info)
last_info = info
else:
output.append((name, contents))
nb_written, wrote_endpoints = extractor_save(args.output_dir, '', output)
if nb_written:
print('\n[+] Wrote %s .proto files to "%s".\n' % (nb_written, args.output_dir))