Exemplo n.º 1
0
    def expList(self, dstPathList=None):
        if dstPathList is None:
            dstPathList = []

        if self.__op in [
                "annot-wwpdb-validate-all", "annot-wwpdb-validate-all-v2"
        ]:
            return super(ValidationWrapper, self).expList(dstPathList)

        logger.debug("Intercepting expList")
        # Op should be annot-wwpdb-validate-all-sf - so we will "pull" and interpret

        # Handle the first arguments
        # ofpdf,ofxml,offullpdf,ofpng,ofsvg,ofmtz

        basedst = dstPathList[0:7]
        outfosf = dstPathList[7]
        out2fosf = dstPathList[8]
        mtzfile = os.path.join(self.getWorkingDir(), "mapcoef.mtz")
        basedst.append(mtzfile)
        ret = super(ValidationWrapper, self).expList(basedst)

        logger.debug("expList ret is %s", ret)

        # Need to "produce files" for last arguments if possible
        if not os.path.exists(mtzfile):
            return False

        pdbid = self.__getPDBId()
        logger.info("pdbID %s", pdbid)
        if not pdbid:
            pdbid = "xxxx"

        psm = PdbxSFMapCoefficients(siteid=self.__siteId,
                                    tmppath=self._tmppath)
        ret = psm.read_mtz_sf(mtzfile)
        logger.debug("read_mtz_sf ret %s", ret)

        if ret:
            # Ensure map coefficients produced in conversion - returns True if present
            ret = psm.has_map_coeff()
            logger.debug("Check for map coeffcients returns %s", ret)
            scrpath = self.getWorkingDir()
            fotemp = os.path.join(scrpath, "fotemp.cif")
            twofotemp = os.path.join(scrpath, "twofotemp.cif")

            if ret:
                ret = psm.write_mmcif_coef(fopathout=fotemp,
                                           twofopathout=twofotemp,
                                           entry_id=pdbid.lower())
                df = DataFile(fotemp)
                if df.srcFileExists():
                    df.copy(outfosf)
                df = DataFile(twofotemp)
                if df.srcFileExists():
                    df.copy(out2fosf)

        logger.debug("Returning %s", ret)
        return ret
Exemplo n.º 2
0
 def testFileEMail(self):  # pragma: no cover
     self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name))
     try:
         fPath = os.path.join(self.__testFilePath, self.__testFile)
         f1 = DataFile(fPath)
         f1.eMail("*****@*****.**", "*****@*****.**", "IGNORE THIS TEST MESSAGE")
     except:  # noqa: E722
         traceback.print_exc(file=sys.stdout)
         self.fail()
Exemplo n.º 3
0
 def testPrintInfo(self):
     """"""
     self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name))
     try:
         fPath = os.path.join(self.__testFilePath, self.__testFile)
         f1 = DataFile(fPath)
         f1.pr(self.lfh)
     except:  # noqa: E722  # pragma: no cover
         traceback.print_exc(file=sys.stdout)
         self.fail()
Exemplo n.º 4
0
    def testSymlink(self):
        """Tests symlink creation """
        self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name))
        # Test non existant case

        f1path = os.path.join(TESTOUTPUT, "linkorigin.tst")
        f2path = os.path.join(TESTOUTPUT, "symlinkdst.tst")
        for f in [f1path, f2path]:
            if os.path.exists(f):
                os.remove(f)

        with open(f1path, "w") as f:
            pass

        d1 = DataFile(f1path)
        d1.symLink(f2path)
Exemplo n.º 5
0
    def testCreateHistory(self):
        """Read existing entry and create initial status records as required -"""
        startTime = time.time()
        self.__lfh.write("\n\n========================================================================================================\n")
        self.__lfh.write("Starting StatusHistoryTests testCreateHistory at %s\n" % time.strftime("%Y %m %d %H:%M:%S", time.localtime()))
        try:
            # Read model file and return status dictionary -
            ei = PdbxEntryInfoIo(verbose=self.__verbose, log=self.__lfh)
            ei.setFilePath(filePath=self.__testFile2)
            sD = ei.getInfoD(contextType="history")
            (
                _entryId,
                _pdbId,
                statusCode,
                _authReleaseCode,
                annotatorInitials,
                initialDepositionDate,
                beginProcessingDate,
                authorApprovalDate,
                releaseDate,
            ) = ei.getCurrentStatusDetails()
            self.__lfh.write("+StatusHistoryTests.testReadWriteHistory() status dictionary %r\n" % sD.items())
            #
            # Get the modification date for the model file -
            df = DataFile(fPath=self.__testFile2)
            currentModelTimeStamp = df.srcModTimeStamp()
            self.__lfh.write("+StatusHistoryTests.testCreateHistory() model file modification time %r\n" % currentModelTimeStamp)
            #
            #
            sH = StatusHistory(siteId=self.__siteId, fileSource="archive", sessionPath=self.__sessionPath, verbose=self.__verbose, log=self.__lfh)
            numHist = sH.setEntryId(entryId=sD["entry_id"], pdbId=sD["pdb_id"])
            self.__lfh.write("Status history count %r\n" % numHist)
            #
            # New status history?  The first record of a new file will mark the PROC->AUTH transition with at one
            #                      additional record depending on the current status state.
            #
            if (numHist < 1) and (statusCode not in ["PROC"]):

                sH.add(
                    statusCodeBegin="PROC",
                    dateBegin=initialDepositionDate,
                    statusCodeEnd="AUTH",
                    dateEnd=beginProcessingDate,
                    annotator=annotatorInitials,
                    details="Automated entry",
                )

                if statusCode in ["REL"]:
                    sH.add(
                        statusCodeBegin="AUTH", dateBegin=beginProcessingDate, statusCodeEnd=statusCode, dateEnd=releaseDate, annotator=annotatorInitials, details="Automated entry"
                    )

                elif statusCode in ["HOLD", "HPUB"]:
                    sH.add(
                        statusCodeBegin="AUTH",
                        dateBegin=beginProcessingDate,
                        statusCodeEnd=statusCode,
                        dateEnd=authorApprovalDate,
                        annotator=annotatorInitials,
                        details="Automated entry",
                    )

                elif statusCode in ["AUCO", "REPL"]:
                    sH.add(
                        statusCodeBegin="AUTH",
                        dateBegin=beginProcessingDate,
                        statusCodeEnd=statusCode,
                        dateEnd=currentModelTimeStamp,
                        annotator=annotatorInitials,
                        details="Automated entry",
                    )
                else:
                    pass
            #
            (lastStatus, lastDate) = sH.getLastStatusAndDate()
            self.__lfh.write("+StatusHistoryTests.testCreateHistory() last values %r %r\n" % (lastStatus, lastDate))
            #
            #  Save the current status history file --
            ok = sH.store(entryId=sD["entry_id"])
            #
            #
            # Recover the contents of the current history file -
            #
            sH = StatusHistory(siteId=self.__siteId, fileSource="archive", sessionPath=self.__sessionPath, verbose=self.__verbose, log=self.__lfh)
            ok = sH.setEntryId(entryId=sD["entry_id"], pdbId=sD["pdb_id"])
            self.__lfh.write("Status is %r\n" % ok)
            dList = sH.get()
            for ii, d in enumerate(dList):
                self.__lfh.write("Row %r  : %r\n" % (ii, d.items()))

        except:  # noqa: E722  pylint: disable=bare-except
            traceback.print_exc(file=self.__lfh)
            self.fail()

        endTime = time.time()
        self.__lfh.write("\nCompleted StatusHistoryTests testCreateHistory at %s (%.2f seconds)\n" % (time.strftime("%Y %m %d %H:%M:%S", time.localtime()), endTime - startTime))
Exemplo n.º 6
0
 def testInstantiate(self):
     _vc = DataFile()
     _vc = mmCIFUtil()  # noqa: F841
Exemplo n.º 7
0
 def testCopyTimeModeToday(self):
     self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name))
     try:
         fPath = os.path.join(self.__testFilePath, self.__testFile)
         f1 = DataFile(fPath)
         f1.pr(self.lfh)
         #
         f1.timeMode("today")
         for fn in self.__outFileList:
             fp = os.path.join(self.__outPath, fn)
             f1.copy(fp)
             f1.pr(self.lfh)
             self.lfh.write("Files are the same  = %s\n" % str(f1.compare()))
             self.lfh.write("Source newer than %s\n" % f1.newerThan(fp))
             f2 = DataFile(fp)
             if f2.srcFileExists():
                 f2.remove()
     except:  # noqa: E722  # pragma: no cover
         traceback.print_exc(file=sys.stdout)
         self.fail()
Exemplo n.º 8
0
    def testMove(self):
        """Tests moving file -- and timemodes"""
        self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name))

        f1path = os.path.join(TESTOUTPUT, "startfile.tst")
        f2path = os.path.join(TESTOUTPUT, "movedest.tst")
        f3path = os.path.join(TESTOUTPUT, "appendest.tst")
        if os.path.exists(f3path):
            os.remove(f3path)

        f1 = DataFile(os.path.join(TESTOUTPUT, "nonexistant"))
        self.assertEqual(f1.srcFileSize(), 0)
        # For test coverage
        f1.src(f1path)

        f3len = 0
        for tmode in ["preserve", "today", "yesterday", "tomorrow", "lastweek"]:
            for f in [f1path, f2path]:
                if os.path.exists(f):
                    os.remove(f)

            with open(f1path, "w") as f:
                f.write(tmode)
                pass

            d1 = DataFile(f1path)
            d1.timeMode(tmode)
            self.assertTrue(d1.setSrcFileMode(0o644))

            self.assertEqual(d1.srcFileSize(), len(tmode))
            # Pre copy - no dst set
            self.assertEqual(d1.dstFileSize(), 0)

            # Test append
            d1.append(f3path)
            f3len += len(tmode)
            d3 = DataFile(f3path)
            self.assertEqual(d3.srcFileSize(), f3len)

            d1.move(f2path)
            self.assertTrue(d1.setDstFileMode(0o644))
            self.assertEqual(d1.dstFileSize(), len(tmode))
Exemplo n.º 9
0
    def testTimes(self):
        """Tests accessing times"""
        self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name))
        fList = [self.__testFile, self.__testFileGzip, self.__testFileZlib, self.__testFileBzip]
        for fn in fList:
            fPath = os.path.join(self.__testFilePath, fn)
            f1 = DataFile(fPath)
            self.assertIsNotNone(f1.srcModTimeStamp())

        # Test non existant case
        f1 = DataFile(os.path.join(TESTOUTPUT, "nonexistant"))
        self.assertIsNone(f1.srcModTimeStamp())

        # newerThan testing
        f1path = os.path.join(TESTOUTPUT, "file1.tst")
        f2path = os.path.join(TESTOUTPUT, "file2.tst")
        for f in [f1path, f2path]:
            if os.path.exists(f):
                os.remove(f)
            # touch file
            with open(f, "w") as f:
                pass
            # So timestamp not same
            time.sleep(1.2)

        d1 = DataFile(f1path)
        self.assertIsNone(d1.newerThan(None))
        self.assertIsNone(d1.newerThan(os.path.join(TESTOUTPUT, "nonexistant")))
        self.assertFalse(d1.newerThan(f2path))
        d2 = DataFile(f2path)
        self.assertTrue(d2.newerThan(f1path))

        # Compare same times
        self.assertFalse(d1.newerThan(f1path))

        # f1 is still nonexistant
        self.assertIsNone(f1.newerThan(f2path))
Exemplo n.º 10
0
 def testSymbolicLinks(self):
     self.lfh.write("\nStarting %s %s\n" % (self.__class__.__name__, sys._getframe().f_code.co_name))
     try:
         fList = [self.__testFile, self.__testFileGzip, self.__testFileZlib, self.__testFileBzip]
         for fn in fList:
             fPath = os.path.join(self.__testFilePath, fn)
             f1 = DataFile(fPath)
             fp = os.path.join(self.__outPath, fn)
             f1.symLinkRelative(fp)
             f1.pr()
             self.lfh.write("Files are the same  = %s\n" % str(f1.compare()))
             self.lfh.write("Source newer than %s\n" % str(f1.newerThan(fp)))
             f2 = DataFile(fp)
             if f2.srcFileExists():
                 f2.remove()
     except:  # noqa: E722  # pragma: no cover
         traceback.print_exc(file=sys.stdout)
         self.fail()