コード例 #1
0
ファイル: snapfiletest.py プロジェクト: JuanCarlosM/snap
    def testCompressSnapFile(self):
        snapdir = os.path.join(os.path.dirname(__file__), "data")
        snapfile = SnapFile(os.path.join(snapdir, "test-snapfile.tgz"), snapdir)
        snapfile.compress()

        tarball = tarfile.open(os.path.join(snapdir, "test-snapfile.tgz"), "r:gz")
        files = []
        for tarinfo in tarball:
            files.append(tarinfo.name)
        self.assertIn(os.path.join("tmp", "file1"), files)
        self.assertIn(os.path.join("tmp", "subdir", "file2"), files)
コード例 #2
0
ファイル: snapfiletest.py プロジェクト: JuanCarlosM/snap
    def testExtractSnapFile(self):
        snap_file_path = os.path.join(os.path.dirname(__file__), "data/existing-snapfile.tgz")
        snapdir = os.path.join(os.path.dirname(__file__), "data/new-snapdir/")
        os.makedirs(snapdir)
        snapfile = SnapFile(snap_file_path, snapdir)
        snapfile.extract()

        self.assertTrue(os.path.exists(snapdir + "packagefile.xml"))
        self.assertTrue(os.path.exists(snapdir + "recordfile.xml"))

        os.remove(snapdir + "packagefile.xml")
        os.remove(snapdir + "recordfile.xml")
        os.removedirs(snapdir)
コード例 #3
0
ファイル: snapfiletest.py プロジェクト: russellb/snap
    def testCompressSnapFile(self):
        snapdir = os.path.join(os.path.dirname(__file__), "data")
        snapfile = SnapFile(os.path.join(snapdir, "test-snapfile.tgz"),
                            snapdir)
        snapfile.compress()

        tarball = tarfile.open(os.path.join(snapdir, "test-snapfile.tgz"),
                               "r:gz")
        files = []
        for tarinfo in tarball:
            files.append(tarinfo.name)
        self.assertIn(os.path.join("tmp", "file1"), files)
        self.assertIn(os.path.join("tmp", "subdir", "file2"), files)
コード例 #4
0
ファイル: snapfiletest.py プロジェクト: russellb/snap
    def testExtractSnapFile(self):
        snap_file_path = os.path.join(os.path.dirname(__file__),
                                      "data/existing-snapfile.tgz")
        snapdir = os.path.join(os.path.dirname(__file__), "data/new-snapdir/")
        os.makedirs(snapdir)
        snapfile = SnapFile(snap_file_path, snapdir)
        snapfile.extract()

        self.assertTrue(os.path.exists(snapdir + "packagefile.xml"))
        self.assertTrue(os.path.exists(snapdir + "recordfile.xml"))

        os.remove(snapdir + "packagefile.xml")
        os.remove(snapdir + "recordfile.xml")
        os.removedirs(snapdir)
コード例 #5
0
    def backup(self):
        '''
        peform the backup operation, recording installed packages and copying new/modified files
        '''
        if config.options.log_level_at_least('normal'):
            callback.snapcallback.message("Creating snapshot")

        self.check_permission()

        # temp directory used to construct tarball
        construct_dir = tempfile.mkdtemp()
        FileManager.make_dir(construct_dir)

        backends = self.load_backends()
        configured_targets = backends.keys()
        for target in SnapshotTarget.BACKENDS:  # load from SnapshotTarget to preserve order
            if target in configured_targets:
                backend = backends[target]
                includes = config.options.target_includes[target]
                excludes = config.options.target_excludes[target]
                backend.backup(construct_dir,
                               include=includes,
                               exclude=excludes)

        SnapFile(
            snapfile=config.options.snapfile,
            snapdirectory=construct_dir,
            encryption_password=config.options.encryption_password).compress()
        if config.options.log_level_at_least('normal'):
            callback.snapcallback.message("Snapshot completed")

        FileManager.rm_dir(construct_dir)
コード例 #6
0
    def restore(self):
        '''
        perform the restore operation, restoring packages and files recorded
        '''
        if config.options.log_level_at_least('normal'):
            callback.snapcallback.message("Restoring Snapshot")

        self.check_permission()

        # temp directory used to extract tarball
        construct_dir = tempfile.mkdtemp()
        FileManager.make_dir(construct_dir)

        SnapFile(
            snapfile=config.options.snapfile,
            snapdirectory=construct_dir,
            encryption_password=config.options.encryption_password).extract()

        backends = self.load_backends()
        configured_targets = backends.keys()
        for target in SnapshotTarget.BACKENDS:  # load from SnapShotTarget to preserve order
            if target in configured_targets:
                backend = backends[target]
                backend.restore(construct_dir)

        if config.options.log_level_at_least('normal'):
            callback.snapcallback.message("Restore completed")

        FileManager.rm_dir(construct_dir)
コード例 #7
0
ファイル: snapfiletest.py プロジェクト: russellb/snap
 def testInvalidSnapdirectoryShouldRaiseError(self):
     with self.assertRaises(MissingDirError) as context:
         SnapFile('foo', '/invalid/dir')
     self.assertEqual(context.exception.message,
                      '/invalid/dir is an invalid snap working directory ')