Example #1
0
    def test(self):

        rpath = reportdir +str(sep) + "report_" + \
        str(datetime.datetime.now()).replace(' ', '').replace(':', '').\
                replace('-', '').rpartition('.')[0] + ".tsv"
        report = open(rpath, 'w')


        report.write("METADATA QUALITY CONTROL REPORT\n" + \
                        str(datetime.datetime.now()).rpartition('.')[0] + \
                        "\n\nMETADATA RULES USED\n")
        for n in xrange(len(tags)):
            q = tags[n].text() + "\t" + ops[n].currentText() + \
                    "\t"

            try:
                report.write(q)
            except:
                try:
                    report.write(q.decode("utf-8"))
                except:
                    try:
                        report.write(q.encode("utf-8"))
                    except:
                        pass
                    pass

            try:
                report.write(vals[n].text().encode('latin1'))
            except:
                try:
                    report.write(vals[n].text())
                except:
                    pass
                pass

            report.write("\n")

        report.write("\nSCANNING RULES USED\n")
        for n in xrange(len(regexes)):
            r = regexes[n][1]
            if regexes[n][0] == 1:
                report.write(u"Directory begins with " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 2:
                report.write(u"Directory contains " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 3:
                report.write(u"Directory ends with " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 4:
                report.write(u"Filename begins with " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 5:
                report.write("Filename contains " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 6:
                report.write("Filename ends with " + \
                                r.encode("utf-8") + u"\n")
        if len(regexes) == 0:
            report.write("Match all files\n")
        fls = []
        report.write("\nVALIDATION\n")
        for root, subFolders, files in walk(self.d):
            for file in files:
                if len(regexes) == 0:
                    fls.append(path.join(root, file))
                elif all(r[2].search(path.join(root, file)) for r in regexes):
                    fls.append(path.join(root, file))

        if self.toolUsed == 'ef':
            self.te.append("\nTool:: ExifTool \n")
        else:
            self.te.append("\nTool:: MediaInfo \n")

        self.te.append("Found " + str(len(fls)) + " matching files to validate")

        report.write("Files found\t\t" + str(len(fls)) + "\n")
        QCoreApplication.processEvents()
        out = ""
        fails = 0
        logging.basicConfig(filename=reportdir+"mdqc.log", level=logging.INFO)
        # logging.basicConfig(filename="mdqc.log", level=logging.INFO)

        for rf in fls:
            logging.info("Validating " + rf)

            try:

                if self.toolUsed == 'ef':
                    l = qcdict.validate(rf, self.db, isExif)
                else:
                    l = qcdict.validate(rf, self.db, False)


            except Exception, e:
                logging.exception(e)
                continue

            if not ": PASSED" in l[0].decode('utf8'):
                fails += 1

            logging.info("Appending to output..")
            self.te.append(l[0].rstrip())
            logging.info("Encoding to UTF8 and appending...")
            ul = l[1].decode('utf8')
            out += ul
            logging.info("Processing events...")
            QCoreApplication.processEvents()
Example #2
0
    def test(self, useMediaInfoFile = False):
        rpath = reportdir + "\\report_" + \
        str(datetime.datetime.now()).replace(' ', '').replace(':', '').\
                replace('-', '').rpartition('.')[0] + ".tsv"
        report = open(rpath, 'w')

        report.write("METADATA QUALITY CONTROL REPORT\n" + \
                        str(datetime.datetime.now()).rpartition('.')[0] + \
                        "\n\nMETADATA RULES USED\n")
        for n in xrange(len(tags)):
            q = tags[n].text() + "\t" + ops[n].currentText() + \
                    "\t" + vals[n].text()
            report.write(q.encode("utf-8"))
            report.write("\n")

        report.write("\nSCANNING RULES USED\n")
        for n in xrange(len(regexes)):
            r = regexes[n][1]
            if regexes[n][0] == 1:
                report.write(u"Directory begins with " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 2:
                report.write(u"Directory contains " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 3:
                report.write(u"Directory ends with " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 4:
                report.write(u"Filename begins with " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 5:
                report.write("Filename contains " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 6:
                report.write("Filename ends with " + \
                                r.encode("utf-8") + u"\n")
        if len(regexes) == 0:
            report.write("Match all files\n")
        fls = []
        report.write("\nVALIDATION\n")
        if self.csvFile:
            for f in self.csvFile:
                fls.append( path.join(self.d, self.csvFile[f]) )
        else:
            for root, subFolders, files in walk(self.d):
                for file in files:
                    if len(regexes) == 0:
                        fls.append(path.join(root, file))
                    elif all(r[2].search(path.join(root, file)) for r in regexes):
                        fls.append(path.join(root, file))



        if self.toolUsed == 'ef':
            self.te.append("\nTool:: ExifTool \n")
        else:
            self.te.append("\nTool:: MediaInfo \n")

        self.te.append("Found " + str(len(fls)) + " matching files to validate")

        report.write("Files found\t\t" + str(len(fls)) + "\n")
        QCoreApplication.processEvents()
        out = ""
        fails = 0
        for rf in fls:

            if self.toolUsed == 'ef':
                l = qcdict.validate(rf, self.db, isExif)
            else:
                l = qcdict.validate(rf, self.db, False, useMediaInfoFile)

            print l
            if not ": PASSED" in l[0].encode('utf8'):
                fails += 1
            self.te.append(l[0].rstrip())
            ul = l[1].encode('utf8')
            out += ul
            QCoreApplication.processEvents()
        report.write("Files failed\t\t" + str(fails) + "\n\n" + out)
        self.te.append("Wrote report to " + rpath)
        report.close()
Example #3
0
    def test(self, useMediaInfoFile=False):
        documentPath = os.path.expanduser(
            '~/Documents/') + 'MDQC Reports' + str(sep)

        if not os.path.exists(documentPath):
            try:
                os.makedirs(documentPath)
            except Exception as e:
                print(e)
                print "errors creating Directory: " + documentPath
                self.te.append("documentPath: " + documentPath)
                self.te.append("Some error occured while opening the file. " +
                               "\n")

        file_name_of_report =  str(datetime.datetime.now()).replace(' ', '').replace(':', ''). \
                replace('-', '').rpartition('.')[0] + ".tsv"
        rpath = documentPath + "report_" + file_name_of_report

        try:
            report = open(rpath, "w")
        except Exception as e:
            print(e)
            print "errors creating file: " + rpath
            self.te.append("rpath: " + rpath)
            self.te.append("Some error occured while opening the file. " +
                           "\n")


        report.write("METADATA QUALITY CONTROL REPORT\n" + \
                        str(datetime.datetime.now()).rpartition('.')[0] + \
                        "\n\nMETADATA RULES USED\n")
        for n in xrange(len(tags)):
            q = tags[n].text() + "\t" + ops[n].currentText() + \
                    "\t"

            try:
                report.write(q)
            except Exception as e:
                print(e)
                try:
                    report.write(q.decode("utf-8"))
                except:
                    try:
                        report.write(q.encode("utf-8"))
                    except:
                        pass
                    pass

            try:
                report.write(vals[n].text().encode('latin1'))
            except:
                try:
                    report.write(vals[n].text())
                except:
                    pass
                pass

            report.write("\n")

        report.write("\nSCANNING RULES USED\n")
        for n in xrange(len(regexes)):
            r = regexes[n][1]
            if regexes[n][0] == 1:
                report.write(u"Directory begins with " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 2:
                report.write(u"Directory contains " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 3:
                report.write(u"Directory ends with " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 4:
                report.write(u"Filename begins with " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 5:
                report.write("Filename contains " + \
                                r.encode("utf-8") + u"\n")
            if regexes[n][0] == 6:
                report.write("Filename ends with " + \
                                r.encode("utf-8") + u"\n")
        if len(regexes) == 0:
            report.write("Match all files\n")
        fls = []
        report.write("\nVALIDATION\n")
        if self.csvFile:
            for f in self.csvFile:
                print self.csvFile[f]
                fls.append(path.join(self.d, self.csvFile[f]))
        else:
            for root, subFolders, files in walk(self.d):
                for file in files:
                    if len(regexes) == 0:
                        fls.append(path.join(root, file))
                    elif all(r[2].search(path.join(root, file))
                             for r in regexes):
                        fls.append(path.join(root, file))

        if self.toolUsed == 'ef':
            self.te.append("\nTool:: ExifTool \n")
        else:
            self.te.append("\nTool:: MediaInfo \n")

        self.te.append("Found " + str(len(fls)) +
                       " matching files to validate")

        report.write("Files found\t\t" + str(len(fls)) + "\n")
        QCoreApplication.processEvents()
        out = ""
        fails = 0

        logging.basicConfig(filename=reportdir + "mdqc.log",
                            level=logging.INFO)
        # logging.basicConfig(filename="mdqc.log", level=logging.INFO)

        for rf in fls:
            logging.info("Validating " + rf)

            try:

                if self.toolUsed == 'ef':
                    l = qcdict.validate(rf, self.db, isExif)
                else:
                    l = qcdict.validate(rf, self.db, False, useMediaInfoFile)

            except Exception, e:
                logging.exception(e)
                continue

            if not ": PASSED" in l[0].decode('utf8'):
                fails += 1

            logging.info("Appending to output..")
            self.te.append(l[0].rstrip())
            logging.info("Encoding to UTF8 and appending...")
            ul = l[1].decode('utf8')
            out += ul
            logging.info("Processing events...")
            QCoreApplication.processEvents()