Пример #1
0
    def backup_directory(self, path, destination_path, indent):
        back_dirs, back_files = self.get_directory_content(path)
        dest_dirs, dest_files = self.get_directory_content(destination_path)
        indented = indent * 4 * '.'
        # Files
        for key, bfile in back_files.items():
            if key not in dest_files:
                self.queue.put('{}FC: {}'.format(indented, key))
                bfile.copy(destination_path)
            else:
                if not bfile == dest_files[key]:
                    self.queue.put('{}FU: {}'.format(indented, key))
                    bfile.copy(destination_path)
                del dest_files[key]

        for key, dfile in dest_files.items():
            self.queue.put('{}FD: {}'.format(indented, key))
            dfile.delete()

        # Directories
        ddir = None
        for key, bdir in back_dirs.items():
            if key not in dest_dirs:
                self.queue.put('{}DC: {}'.format(indented,
                                                                 key))
                ddir = Directory(bdir.name, destination_path)
                ddir.create()
            else:
                ddir = dest_dirs[key]
                del dest_dirs[key]
            self.queue.put('{}DP: {}'.format(indented, key))
            self.backup_directory(bdir.full_path(),
                                    ddir.full_path(),
                                    indent + 1)

        for key, ddir in dest_dirs.items():
            self.queue.put('{}DD: {}'.format(indented, key))
            ddir.delete()
Пример #2
0
 def test_full_path(self):
     d = Directory(self.dir_test, self.path)
     self.assertEqual(d.full_path(), self.full_path)