Beispiel #1
0
    def test_addrecord(self):
        dumpdir1_name = "/home/peer/backups/testdocs/docs/new folder"
        dumpdir1 = ["Y here is another new file",
                    "Y here is another new file~",
                    "Y oo-maxwell.odt",
                    "Y oo-payment-schedule.ods"
                    ]

        _dumpdirs = [ Dumpdir("Yhere is another new file\0"),
                      Dumpdir("Yhere is another new file~"),
                      Dumpdir("Yoo-maxwell.odt"),
                      Dumpdir("Yoo-payment-schedule.ods")
                    ]

        _rec = ['0', '1232387286', '0', '2055', '90478',
                '/home/peer/backups/testdocs/docs/new folder',
                _dumpdirs
               ]

        datet = datetime.datetime(2007, 1, 19, 15, 29, 27)

        snpf = SnapshotFile(self.snarf_new, writeFlag = True)
        snpf.setHeader(datet)
        snpf.addRecord(_rec)

        del snpf
        # now re-read the created SNAR-file
#        print "\n\n\nnow re-read the created SNAR-file"

        dir_file = []
        snpf = SnapshotFile(self.snarf_new)
        for entr in snpf.parseFormat2():
            dir_file.append(entr)
        self.assertTrue(len(dir_file) == 1)

        entry1 = dir_file[0]

#        print "ENTRY after addrecord:\n%s" % entry1

        # evaluate the results
        self.assertEqual(dumpdir1_name, entry1[SnapshotFile.REC_DIRNAME])
        self.assertEqual(len(dumpdir1), len(entry1[SnapshotFile.REC_CONTENT]))

        dmpd_lst = entry1[SnapshotFile.REC_CONTENT]
        self.assertTrue(isinstance(dmpd_lst, list))

        for _idx in range(0, len(dumpdir1)):
            dmpd = dmpd_lst[_idx]
            self.assertTrue(isinstance(dmpd, Dumpdir))
            dmpd_str = "%s %s" % (dmpd.getControl(), dmpd.getFilename())
            self.assertEqual(dmpd_str, dumpdir1[_idx])
Beispiel #2
0
    def testWriteSNARfile(self):
        " Test the writng of SNARfile functionalities "
        if os.path.exists("test-datas" + os.sep + "test-files.snar"):
            os.remove("test-datas" + os.sep + "test-files.snar")
        snpf = SnapshotFile("test-datas" + os.sep + "test-files.snar", True)
        import datetime
        snpf.setHeader(datetime.datetime.now())
        self.assertEqual(snpf.getFormatVersion(), 2)
        entry = ['0', '1195399253', '1195399253', '2049', '420738', "/home/wattazoum/Images",
            [Dumpdir('%scamescope' % Dumpdir.DIRECTORY),
             Dumpdir('%sarticle.html' % Dumpdir.INCLUDED)]
            ]
        snpf.addRecord(entry)

        snpf2 = ProcSnapshotFile(snpf)
        self.assertTrue(snpf2.hasFile("/home/wattazoum/Images/article.html"))
        self.assertTrue(snpf2.hasPath("/home/wattazoum/Images"))