test-bugzilla-files/test-bugzilla-files.py | 63 +++++++++++++++++++---------- 1 file changed, 43 insertions(+), 20 deletions(-)
New commits: commit cd10db7159587868ff0bf9a63d9f22020a8c92a2 Author: Gülşah Köse <gulsah.k...@collabora.com> AuthorDate: Wed Aug 25 10:50:49 2021 +0300 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Aug 26 11:30:54 2021 +0200 Create previous directory to compare Change-Id: Iae9d9e7e24f262a05ddbfc7ec0180784e311efae Reviewed-on: https://gerrit.libreoffice.org/c/dev-tools/+/121011 Tested-by: Miklos Vajna <vmik...@collabora.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/test-bugzilla-files/test-bugzilla-files.py b/test-bugzilla-files/test-bugzilla-files.py index 5a05878..9d712c6 100644 --- a/test-bugzilla-files/test-bugzilla-files.py +++ b/test-bugzilla-files/test-bugzilla-files.py @@ -33,6 +33,7 @@ import sys import time import uuid import datetime +from shutil import copyfile, rmtree import signal import threading @@ -347,7 +348,7 @@ def writeExportCrash(fileName): exportCrash.write(fileName + '\n') exportCrash.close() -def exportDoc(xDoc, filterName, validationCommand, odfundiffCommand, filename, connection, timer): +def exportDoc(xDoc, filterName, validationCommand, filename, connection, timer): props = [ ("FilterName", filterName) ] saveProps = tuple([mkPropertyValue(name, value) for (name, value) in props]) # note: avoid empty path segments in the url! @@ -356,7 +357,7 @@ def exportDoc(xDoc, filterName, validationCommand, odfundiffCommand, filename, c try: args = [connection] t = threading.Timer(timer.getExportTime(), alarm_handler, args) - t.start() + t.start() xDoc.storeToURL(fileURL, saveProps) except pyuno.getClass("com.sun.star.beans.UnknownPropertyException"): print("caught UnknownPropertyException " + filename + " timedOut: " + str(connection.suicided())) @@ -393,18 +394,26 @@ def exportDoc(xDoc, filterName, validationCommand, odfundiffCommand, filename, c except subprocess.CalledProcessError: pass # ignore that exception - if odfundiffCommand: - odfundiffCommandWithURL = odfundiffCommand + " " + filename + " /srv/crashtestdata/current" + filename - print(odfundiffCommandWithURL) - try: - output = str(subprocess.check_output(odfundiffCommandWithURL, shell=True, timeout=600), encoding='utf-8') - if "number of differences found" in output: - validLog = open(fileURL[7:]+".log.odfundiff", "w") - validLog.write(output) - validLog.close() - handleODFunDiff(filename) - except subprocess.CalledProcessError: - pass +def isPreviousExist(): + previous_path = "/srv/crashtestdata/previous" + if os.path.exists(previous_path): + return True + return False + +def saveAsPreviousState(exported_files): + odf_file_ext = ['odt', 'ods', 'odp', 'odb'] + previous_path = "/srv/crashtestdata/previous/srv/crashtestdata/files/odt" + if os.path.exists(previous_path): + rmtree("/srv/crashtestdata/previous") + os.makedirs(previous_path) + + for file in exportedFiles: + ext = file[-3:] + if ext in odf_file_ext: + copyfile("/srv/crashtestdata/current"+file, "/srv/crashtestdata/previous"+file) + +def getODFunDiffCommand(): + return os.environ["HOME"] + "/source/bin/odfundiff-exe" class ExportFileTest: def __init__(self, xDoc, filename, enable_validation, timer): @@ -434,7 +443,6 @@ class ExportFileTest: for format in formats: filterName = self.getFilterName(format) validation = self.getValidationCommand(filterName) - odfundiff = self.getODFunDiffCommand(filterName) print(format) print(filterName) if filterName: @@ -442,7 +450,8 @@ class ExportFileTest: filename = base + extensions[filterName] self.exportedFiles.append(filename) - xExportedDoc = exportDoc(self.xDoc, filterName, validation, odfundiff, filename, connection, self.timer) + xExportedDoc = exportDoc(self.xDoc, filterName, validation, filename, connection, self.timer) + if xExportedDoc: xExportedDoc.close(True) @@ -493,10 +502,6 @@ class ExportFileTest: return None return validationCommand[filterName] - def getODFunDiffCommand(self, filterName): - if filterName == "writer8": - return os.environ["HOME"] + "/source/bin/odfundiff-exe" - return None def getFilterName(self, format): filterNames = { "ods": "calc8", @@ -668,6 +673,24 @@ if __name__ == "__main__": # Check the roundtripped files doesn't crash at import time runLoadFileTests(opts, exportedFiles, False) + + if not isPreviousExist(): + saveAsPreviousState(exportedFiles) + else: + for filename in exportedFiles: + if filename[-3:] == 'odt': + odfundiffCommandWithURL = getODFunDiffCommand() + " /srv/crashtestdata/previous" + filename + " /srv/crashtestdata/current" + filename + print(odfundiffCommandWithURL) + try: + output = str(subprocess.check_output(odfundiffCommandWithURL, shell=True, timeout=600), encoding='utf-8') + if not "Diff finished, number of differences found: 0" in output: + validLog = open("/srv/crashtestdata/current" + filename + ".log.odfundiff", "w") + validLog.write(output) + validLog.close() + handleODFunDiff(filename) + except subprocess.CalledProcessError: + pass + saveAsPreviousState(exportedFiles) else: usage() sys.exit(1)