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

WIP: Optimize ID breakdown functions #78

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ tests/fixtures
*.sf
sqlitefid/*
pathlesstaken/*
queries
28 changes: 19 additions & 9 deletions demystify.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def handle_output(analysis_results, txtout=False, rogues=False, heroes=False):
"Please report any feedback you have around its accuracy and helpfulness. "
"The feedback received will help improve the feature."
)

if txtout is True:
logging.info("Outputting text report")
textoutput = FormatAnalysisTextOutput(analysis_results)
Expand All @@ -133,7 +132,9 @@ def handle_output(analysis_results, txtout=False, rogues=False, heroes=False):
print(htmloutput.printHTMLResults().encode("utf8"))


def analysis_from_database(database_path, denylist=None, rogues=False, heroes=False):
def analysis_from_database(
database_path, denylist=None, rogues=False, heroes=False, audit=False
):
"""Analysis of format identification report from existing database.

:param database_path: path to sqlite database containing analysis
Expand All @@ -145,7 +146,7 @@ def analysis_from_database(database_path, denylist=None, rogues=False, heroes=Fa
"""
logging.info("Analysis from database: %s", database_path)
try:
analysis = DemystifyAnalysis(database_path, get_config(), denylist)
analysis = DemystifyAnalysis(database_path, get_config(), denylist, audit)
except AnalysisError as err:
raise AnalysisError(err)
rogue_analysis = False
Expand All @@ -155,7 +156,9 @@ def analysis_from_database(database_path, denylist=None, rogues=False, heroes=Fa
return analysis


def analysis_from_csv(format_report, analyze, denylist=None, rogues=None, heroes=None):
def analysis_from_csv(
format_report, analyze, denylist=None, rogues=None, heroes=None, audit=False
):
"""Analysis of format identification report from raw data, i.e.
DROID CSV, SF YAML etc.

Expand All @@ -176,7 +179,7 @@ def analysis_from_csv(format_report, analyze, denylist=None, rogues=None, heroes
if analyze is not True:
logging.error("Analysis is not set: %s", analyze)
return
analysis = analysis_from_database(database_path, denylist, rogues, heroes)
analysis = analysis_from_database(database_path, denylist, rogues, heroes, audit)
return analysis


Expand Down Expand Up @@ -221,6 +224,11 @@ def main():
help="Output 'Heroes Gallery' listing",
action="store_true",
)
parser.add_argument(
"--audit",
help="Output a listing of all database queries used for a report",
action="store_true",
)
start_time = time.time()
if len(sys.argv) == 1:
parser.print_help()
Expand All @@ -233,16 +241,18 @@ def main():
if args.export:
args.db = False
analysis = analysis_from_csv(
args.export, True, denylist, args.rogues, args.heroes
args.export, True, denylist, args.rogues, args.heroes, args.audit
)
if args.db:
if not IdentifyDB().identify_export(args.db):
logging.error("Not a recognized sqlite database: %s", args.db)
sys.exit(1)
analysis = analysis_from_database(args.db, denylist, args.rogues, args.heroes)
if analysis:
analysis = analysis_from_database(
args.db, denylist, args.rogues, args.heroes, args.audit
)
if analysis and not args.audit:
handle_output(analysis.analysis_results, args.txt, args.rogues, args.heroes)
output_time(start_time)
output_time(start_time)
logging.info("Demystify: ...analysis complete")


Expand Down
Loading