post_worker.py 1.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import tarfile
import os
import shutil

full_path = os.path.realpath(__file__)
source_dir = full_path.replace("scripts/post_worker.py", "reports/")
output_filename = full_path.replace("post_worker.py", "reports.tar.gz")

print "source dir:", source_dir

count = 0

# walk through every subdirectory & add the folder if it is not empty
with tarfile.open(output_filename, "w:gz") as tar:
    for (path, dirs, files) in os.walk(source_dir):
        if len(files) > 0:
            print "tarring:", path
            tar.add(path, arcname=os.path.basename(path))
            count += 1

tar.close()

Minh Tue Vo committed
23 24 25 26 27 28 29
session_path = os.path.join(
    os.environ['HOME'],
    'results',
    os.environ['TDDIUM_SESSION_ID'],
    'session')

file_dest = os.path.join(session_path, 'reports.tar.gz')
30 31 32

# if the tar file is not empty, copy it to the proper place
if count > 0:
Minh Tue Vo committed
33
    print 'copying tar file to:', file_dest
34
    shutil.copyfile(output_filename, file_dest)
Minh Tue Vo committed
35 36 37 38 39 40

# finding if there is any screenshot or log file
print 'attaching failed screenshots and logs (if any)'
for (path, dirs, files) in os.walk('test_root/log'):
    for filename in files:
        if filename.find('png') != -1 or filename.find('log') != -1:
Minh Tue Vo committed
41
            filepath = os.path.join(path, filename)
Minh Tue Vo committed
42
            print 'copying file:', filepath
Minh Tue Vo committed
43 44
            destpath = os.path.join(session_path, filename)
            print 'destination:', destpath
Minh Tue Vo committed
45 46
            shutil.copyfile(filepath, destpath)

47
print 'TDDIUM_SESSION_ID:', os.environ['TDDIUM_SESSION_ID']