Skip to content

Commit 579e6a7

Browse files
committed
feat: print output directory path at the end of processing
1 parent 6db4508 commit 579e6a7

File tree

2 files changed

+47
-20
lines changed

2 files changed

+47
-20
lines changed

unblob/cli.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,25 @@ def cli(
322322

323323
logger.info("Start processing file", file=file)
324324
process_results = process_file(config, file, report_file)
325+
325326
if verbose == 0:
326327
if skip_extraction:
327328
print_scan_report(process_results)
328329
else:
329330
print_report(process_results)
331+
print_output_dir(process_results)
330332
return process_results
331333

332334

335+
def print_output_dir(process_results: ProcessResult):
336+
path = process_results.get_output_dir()
337+
338+
if path:
339+
click.echo(f"Find output at {path}")
340+
else:
341+
click.echo("Too bad! Nothing was extracted.")
342+
343+
333344
cli.context_class = UnblobContext
334345

335346

@@ -453,35 +464,36 @@ def print_report(reports: ProcessResult):
453464
valid_size += size
454465
total_size += size
455466

456-
if total_size == 0:
457-
return
467+
console = Console()
458468

459-
summary = Panel(
460-
f"""Extracted files: [#00FFC8]{total_files}[/#00FFC8]
469+
if total_size:
470+
summary = Panel(
471+
f"""Extracted files: [#00FFC8]{total_files}[/#00FFC8]
461472
Extracted directories: [#00FFC8]{total_dirs}[/#00FFC8]
462473
Extracted links: [#00FFC8]{total_links}[/#00FFC8]
463474
Extraction directory size: [#00FFC8]{human_size(extracted_size)}[/#00FFC8]
464475
Chunks identification ratio: [#00FFC8]{(valid_size/total_size) * 100:0.2f}%[/#00FFC8]""",
465-
subtitle="Summary",
466-
title=f"unblob ({get_version()})",
467-
)
476+
subtitle="Summary",
477+
title=f"unblob ({get_version()})",
478+
)
468479

469-
console = Console()
470-
console.print(summary)
480+
console.print(summary)
471481

472-
chunks_table = Table(title="Chunks distribution")
473-
chunks_table.add_column("Chunk type", justify="left", style="#00FFC8", no_wrap=True)
474-
chunks_table.add_column("Size", justify="center", style="#00FFC8", no_wrap=True)
475-
chunks_table.add_column("Ratio", justify="center", style="#00FFC8", no_wrap=True)
482+
# fmt: off
483+
chunks_table = Table(title="Chunks distribution")
484+
chunks_table.add_column("Chunk type", justify="left", style="#00FFC8", no_wrap=True)
485+
chunks_table.add_column("Size", justify="center", style="#00FFC8", no_wrap=True)
486+
chunks_table.add_column("Ratio", justify="center", style="#00FFC8", no_wrap=True)
487+
# fmt: on
476488

477-
for handler, size in sorted(
478-
chunks_distribution.items(), key=lambda item: item[1], reverse=True
479-
):
480-
chunks_table.add_row(
481-
handler.upper(), human_size(size), f"{(size/total_size) * 100:0.2f}%"
482-
)
489+
for handler, size in sorted(
490+
chunks_distribution.items(), key=lambda item: item[1], reverse=True
491+
):
492+
chunks_table.add_row(
493+
handler.upper(), human_size(size), f"{(size/total_size) * 100:0.2f}%"
494+
)
483495

484-
console.print(chunks_table)
496+
console.print(chunks_table)
485497

486498
if len(reports.errors):
487499
errors_table = Table(title="Encountered errors")

unblob/models.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .identifiers import new_id
1414
from .parser import hexstring2regex
1515
from .report import (
16+
CarveDirectoryReport,
1617
ChunkReport,
1718
ErrorReport,
1819
MultiFileReport,
@@ -238,6 +239,20 @@ def register(self, result: TaskResult):
238239
def to_json(self, indent=" "):
239240
return to_json(self.results, indent=indent)
240241

242+
def get_output_dir(self) -> Optional[Path]:
243+
try:
244+
top_result = self.results[0]
245+
if carves := top_result.filter_reports(CarveDirectoryReport):
246+
# we have a top level carve
247+
return carves[0].carve_dir
248+
249+
# we either have an extraction,
250+
# and the extract directory registered as subtask
251+
return top_result.subtasks[0].path
252+
except IndexError:
253+
# or no extraction
254+
return None
255+
241256

242257
class _JSONEncoder(json.JSONEncoder):
243258
def default(self, obj):

0 commit comments

Comments
 (0)