Reverting addition of output argument; added a pause after the Java runs.

This commit is contained in:
dhurd 2012-08-28 10:12:58 -04:00
parent 721d44c11f
commit eca3aff89e

View File

@ -11,6 +11,7 @@ import datetime
import xml import xml
import re import re
import socket import socket
import time
from xml.dom.minidom import parse, parseString from xml.dom.minidom import parse, parseString
from sys import platform as _platform from sys import platform as _platform
@ -54,8 +55,6 @@ class Args:
self.verbose = False self.verbose = False
self.exception = False self.exception = False
self.exception_string = "" self.exception_string = ""
self.output = False
self.output_dir = ""
def parse(self): def parse(self):
sys.argv.pop(0) sys.argv.pop(0)
@ -101,22 +100,11 @@ class Args:
try: try:
arg = sys.argv.pop(0) arg = sys.argv.pop(0)
printout("Running in exception mode: ") printout("Running in exception mode: ")
printout("Printing all exceptions with the string '" + arg + "'.\n") printout("Printing all exceptions with the string '" + arg + "'\n")
self.exception = True self.exception = True
self.exception_string = arg self.exception_string = arg
except: except:
printerror("Error: No exception string given.") printerror("Error: No exception string given.")
elif(arg == "-o" or arg == "--output"):
try:
arg = sys.argv.pop(0)
if dir_exists(arg):
printout("Running with output directory set to " + arg + ".\n")
self.output = True
self.output_dir = arg
else:
printerror("Error: Given output directory for -o doesn't exist.")
except:
printerror("Error: No output directory given.\n")
elif arg == "-h" or arg == "--help": elif arg == "-h" or arg == "--help":
printout(usage()) printout(usage())
return False return False
@ -379,12 +367,13 @@ def run_test(image_file):
# Set the case to work for this test # Set the case to work for this test
case.image_file = image_file case.image_file = image_file
case.image_name = case.get_image_name(image_file) case.image_name = case.get_image_name(image_file)
case.antlog_dir = make_path(case.output_dir, case.image_name, "antlog.txt") case.antlog_dir = make_local_path(case.output_dir, case.image_name, "antlog.txt")
case.known_bad_path = make_path(case.input_dir, "notablehashes.txt-md5.idx") case.known_bad_path = make_path(case.input_dir, "notablehashes.txt-md5.idx")
case.keyword_path = make_path(case.input_dir, "notablekeywords.xml") case.keyword_path = make_path(case.input_dir, "notablekeywords.xml")
case.nsrl_path = make_path(case.input_dir, "nsrl.txt-md5.idx") case.nsrl_path = make_path(case.input_dir, "nsrl.txt-md5.idx")
run_ant() run_ant()
time.sleep(2) # Give everything a second to process
# After the java has ran: # After the java has ran:
copy_logs() copy_logs()
@ -400,7 +389,7 @@ def run_test(image_file):
rebuild() rebuild()
# If NOT keeping Solr index (-k) # If NOT keeping Solr index (-k)
if not args.keep: if not args.keep:
solr_index = make_path(case.output_dir, case.image_name, "AutopsyTestCase", "KeywordSearch") solr_index = make_local_path(case.output_dir, case.image_name, "AutopsyTestCase", "KeywordSearch")
if clear_dir(solr_index): if clear_dir(solr_index):
print_report([], "DELETE SOLR INDEX", "Solr index deleted.") print_report([], "DELETE SOLR INDEX", "Solr index deleted.")
elif args.keep: elif args.keep:
@ -453,7 +442,7 @@ def run_ant():
case.ant.append("-Dkeyword_path=" + case.keyword_path) case.ant.append("-Dkeyword_path=" + case.keyword_path)
case.ant.append("-Dnsrl_path=" + case.nsrl_path) case.ant.append("-Dnsrl_path=" + case.nsrl_path)
case.ant.append("-Dgold_path=" + make_local_path(case.gold)) case.ant.append("-Dgold_path=" + make_local_path(case.gold))
case.ant.append("-Dout_path=" + make_path(case.output_dir, case.image_name)) case.ant.append("-Dout_path=" + make_local_path(case.output_dir, case.image_name))
case.ant.append("-Dignore_unalloc=" + "%s" % args.unallocated) case.ant.append("-Dignore_unalloc=" + "%s" % args.unallocated)
case.ant.append("-Dtest.timeout=" + str(case.timeout)) case.ant.append("-Dtest.timeout=" + str(case.timeout))
@ -500,9 +489,9 @@ def rebuild():
clear_dir(gold_dir) clear_dir(gold_dir)
# Rebuild the database # Rebuild the database
gold_from = make_path(case.output_dir, case.image_name, gold_from = make_local_path(case.output_dir, case.image_name,
"AutopsyTestCase", "autopsy.db") "AutopsyTestCase", "autopsy.db")
gold_to = make_path(case.gold, case.image_name, "standard.db") gold_to = make_local_path(case.gold, case.image_name, "standard.db")
try: try:
copy_file(gold_from, gold_to) copy_file(gold_from, gold_to)
except FileNotFoundException as e: except FileNotFoundException as e:
@ -512,7 +501,7 @@ def rebuild():
errors.append(str(e) + "\n") errors.append(str(e) + "\n")
# Rebuild the HTML report # Rebuild the HTML report
html_path = make_path(case.output_dir, case.image_name, html_path = make_local_path(case.output_dir, case.image_name,
"AutopsyTestCase", "Reports") "AutopsyTestCase", "Reports")
try: try:
html_from = get_file_in_dir(html_path, ".html") html_from = get_file_in_dir(html_path, ".html")
@ -589,7 +578,7 @@ def compare_to_gold_db():
# the regression test against the gold standard html report # the regression test against the gold standard html report
def compare_to_gold_html(): def compare_to_gold_html():
gold_html_file = make_local_path(case.gold, case.image_name, "standard.html") gold_html_file = make_local_path(case.gold, case.image_name, "standard.html")
autopsy_html_path = make_path(case.output_dir, case.image_name, autopsy_html_path = make_local_path(case.output_dir, case.image_name,
"AutopsyTestCase", "Reports") "AutopsyTestCase", "Reports")
try: try:
autopsy_html_file = get_file_in_dir(autopsy_html_path, ".html") autopsy_html_file = get_file_in_dir(autopsy_html_path, ".html")
@ -672,7 +661,7 @@ def compare_tsk_objects():
# from each log file generated by Autopsy # from each log file generated by Autopsy
def generate_common_log(): def generate_common_log():
try: try:
logs_path = make_path(case.output_dir, case.image_name, "logs") logs_path = make_local_path(case.output_dir, case.image_name, "logs")
common_log = open(case.common_log, "a") common_log = open(case.common_log, "a")
common_log.write("--------------------------------------------------\n") common_log.write("--------------------------------------------------\n")
common_log.write(case.image_name + "\n") common_log.write(case.image_name + "\n")
@ -698,7 +687,7 @@ def generate_common_log():
def fill_case_data(): def fill_case_data():
try: try:
# Open autopsy.log.0 # Open autopsy.log.0
log_path = make_path(case.output_dir, case.image_name, "logs", "autopsy.log.0") log_path = make_local_path(case.output_dir, case.image_name, "logs", "autopsy.log.0")
log = open(log_path) log = open(log_path)
# Set the case starting time based off the first line of autopsy.log.0 # Set the case starting time based off the first line of autopsy.log.0
@ -858,7 +847,7 @@ def csv_header(csv_path):
# Returns a list of all the exceptions listed in all the autopsy logs # Returns a list of all the exceptions listed in all the autopsy logs
def get_exceptions(): def get_exceptions():
exceptions = [] exceptions = []
logs_path = make_path(case.output_dir, case.image_name, "logs") logs_path = make_local_path(case.output_dir, case.image_name, "logs")
results = [] results = []
for file in os.listdir(logs_path): for file in os.listdir(logs_path):
if "autopsy" in file: if "autopsy" in file:
@ -894,7 +883,7 @@ def report_all_errors():
# Searched all the known logs for the given regex # Searched all the known logs for the given regex
# The function expects regex = re.compile(...) # The function expects regex = re.compile(...)
def regex_search_logs(regex): def regex_search_logs(regex):
logs_path = make_path(case.output_dir, case.image_name, "logs") logs_path = make_local_path(case.output_dir, case.image_name, "logs")
results = [] results = []
for file in os.listdir(logs_path): for file in os.listdir(logs_path):
log = open(make_path(logs_path, file), "r") log = open(make_path(logs_path, file), "r")
@ -909,7 +898,7 @@ def regex_search_logs(regex):
# Search through all the known log files for a specific string. # Search through all the known log files for a specific string.
# Returns a list of all lines with that string # Returns a list of all lines with that string
def search_logs(string): def search_logs(string):
logs_path = make_path(case.output_dir, case.image_name, "logs") logs_path = make_local_path(case.output_dir, case.image_name, "logs")
results = [] results = []
for file in os.listdir(logs_path): for file in os.listdir(logs_path):
log = open(make_path(logs_path, file), "r") log = open(make_path(logs_path, file), "r")
@ -934,7 +923,7 @@ def search_common_log(string):
# Searches the given log for the given string # Searches the given log for the given string
# Returns a list of all lines with that string # Returns a list of all lines with that string
def search_log(log, string): def search_log(log, string):
logs_path = make_path(case.output_dir, case.image_name, "logs", log) logs_path = make_local_path(case.output_dir, case.image_name, "logs", log)
try: try:
results = [] results = []
log = open(logs_path, "r") log = open(logs_path, "r")
@ -951,7 +940,7 @@ def search_log(log, string):
# Search through all the the logs of the given type # Search through all the the logs of the given type
# Types include autopsy, tika, and solr # Types include autopsy, tika, and solr
def search_log_set(type, string): def search_log_set(type, string):
logs_path = make_path(case.output_dir, case.image_name, "logs") logs_path = make_local_path(case.output_dir, case.image_name, "logs")
results = [] results = []
for file in os.listdir(logs_path): for file in os.listdir(logs_path):
if type in file: if type in file:
@ -1027,7 +1016,7 @@ def generate_html():
logs = "<div id='logs'>\ logs = "<div id='logs'>\
<h2><a name='" + case.image_name + "-logs'>Logs</a></h2>\ <h2><a name='" + case.image_name + "-logs'>Logs</a></h2>\
<hr color='#00a00f'>" <hr color='#00a00f'>"
logs_path = make_path(case.output_dir, case.image_name, "logs") logs_path = make_local_path(case.output_dir, case.image_name, "logs")
for file in os.listdir(logs_path): for file in os.listdir(logs_path):
logs += "<p><a href='file:\\" + make_path(logs_path, file) + "' target='_blank'>" + file + "</a></p>" logs += "<p><a href='file:\\" + make_path(logs_path, file) + "' target='_blank'>" + file + "</a></p>"
logs += "</div>" logs += "</div>"
@ -1208,7 +1197,7 @@ def wgetcwd():
def copy_logs(): def copy_logs():
try: try:
log_dir = os.path.join("..","build","test","qa-functional","work","userdir0","var","log") log_dir = os.path.join("..","build","test","qa-functional","work","userdir0","var","log")
shutil.copytree(log_dir, make_path(case.output_dir, case.image_name, "logs")) shutil.copytree(log_dir, make_local_path(case.output_dir, case.image_name, "logs"))
except Exception as e: except Exception as e:
printerror("Error: Failed to copy the logs.") printerror("Error: Failed to copy the logs.")
printerror(str(e) + "\n") printerror(str(e) + "\n")
@ -1315,7 +1304,6 @@ Options:
-v Verbose mode; prints all errors to the screen. -v Verbose mode; prints all errors to the screen.
-e ex Prints out all errors containing ex. -e ex Prints out all errors containing ex.
-l cfg Runs from configuration file cfg. -l cfg Runs from configuration file cfg.
-o dir Uses dir as the output directory. Must be a full path.
""" """
@ -1378,14 +1366,11 @@ def main():
pass pass
# Otherwise test away! # Otherwise test away!
else: else:
if not args.output: case.output_dir = make_path("output", time.strftime("%Y.%m.%d-%H.%M.%S"))
case.output_dir = make_local_path("output", time.strftime("%Y.%m.%d-%H.%M.%S"))
else:
case.output_dir = make_path(args.output_dir, time.strftime("%Y.%m.%d-%H.%M.%S"))
os.makedirs(case.output_dir) os.makedirs(case.output_dir)
case.common_log = make_path(case.output_dir, "AutopsyErrors.txt") case.common_log = make_local_path(case.output_dir, "AutopsyErrors.txt")
case.csv = make_path(case.output_dir, "CSV.txt") case.csv = make_local_path(case.output_dir, "CSV.txt")
case.html_log = make_path(case.output_dir, "AutopsyTestCase.html") case.html_log = make_local_path(case.output_dir, "AutopsyTestCase.html")
# If user wants to do a single file and a list (contradictory?) # If user wants to do a single file and a list (contradictory?)
if args.single and args.list: if args.single and args.list: