Beispiel #1
0
    def test_restore_config_zip(self):
        """
        Test restore_config_zip
        """
        here = os.path.dirname(__file__)
        files = [
            os.path.join(here, f) for f in os.listdir(here)
            if f[-3:] in [".db", ".py"]
        ]
        zip_path = os.path.join(here, "_backup_test.zip")

        helpers.backup_config_zip(files, zip_path, here)
        restore_container = os.path.join(here, "_restore_tests")
        os.path.exists(restore_container) or os.mkdir(restore_container)
        restore_path = os.path.join(restore_container, "test")
        assert not helpers.restore_config_zip(files[1],
                                              restore_path)  # test invalid zip
        assert helpers.restore_config_zip(zip_path, restore_path)
        assert helpers.restore_config_zip(
            zip_path, restore_path)  # test extractDir exists

        if os.path.isfile(zip_path):
            os.remove(zip_path)
        if os.path.isdir(restore_container):
            rmtree(restore_container)
Beispiel #2
0
    def test_restore_config_zip(self):
        """
        Test restore_config_zip
        """
        here = os.path.dirname(__file__)
        files = [
            os.path.join(here, f) for f in os.listdir(here)
            if f[-3:] in [".db", ".py"]
        ]
        zip_path = os.path.join(here, '_backup_test.zip')

        helpers.backup_config_zip(files, zip_path, here)
        restore_container = os.path.join(here, '_restore_tests')
        os.mkdir(restore_container)
        restore_path = os.path.join(restore_container, 'test')
        self.assertFalse(helpers.restore_config_zip(
            files[1], restore_path))  # test invalid zip
        self.assertTrue(helpers.restore_config_zip(zip_path, restore_path))
        self.assertTrue(helpers.restore_config_zip(
            zip_path, restore_path))  # test extractDir exists

        if os.path.isfile(zip_path):
            os.remove(zip_path)
        if os.path.isdir(restore_container):
            rmtree(restore_container)
Beispiel #3
0
    def test_backup_config_zip(self):
        """
        Test backup_config_zip
        """
        here = os.path.dirname(__file__)
        files = [
            os.path.join(here, f) for f in os.listdir(here)
            if f[-3:] in [".db", ".py"]
        ]
        zip_path = os.path.join(here, "_backup_test.zip")

        assert helpers.backup_config_zip(files, zip_path, here)
        assert not helpers.backup_config_zip(files, "/:/_backup_test.zip")

        if os.path.isfile(zip_path):
            os.remove(zip_path)
Beispiel #4
0
    def backup(backupDir=None):

        finalResult = ""

        if backupDir:
            source = [
                os.path.join(settings.DATA_DIR, "sickchill.db"),
                settings.CONFIG_FILE,
                os.path.join(settings.DATA_DIR, "failed.db"),
                os.path.join(settings.DATA_DIR, "cache.db"),
            ]
            target = os.path.join(
                backupDir,
                "sickchill-" + time.strftime("%Y%m%d%H%M%S") + ".zip")

            for (path, dirs, files) in os.walk(settings.CACHE_DIR,
                                               topdown=True):
                for dirname in dirs:
                    if path == settings.CACHE_DIR and dirname not in [
                            "images"
                    ]:
                        dirs.remove(dirname)
                for filename in files:
                    source.append(os.path.join(path, filename))

            if helpers.backup_config_zip(source, target, settings.DATA_DIR):
                finalResult += "Successful backup to " + target
            else:
                finalResult += "Backup FAILED"
        else:
            finalResult += "You need to choose a folder to save your backup to!"

        finalResult += "<br>\n"

        return finalResult
Beispiel #5
0
    def test_backup_config_zip(self):
        """
        Test backup_config_zip
        """
        here = os.path.dirname(__file__)
        files = [
            os.path.join(here, f) for f in os.listdir(here)
            if f[-3:] in [".db", ".py"]
        ]
        zip_path = os.path.join(here, '_backup_test.zip')

        self.assertTrue(helpers.backup_config_zip(files, zip_path, here))
        self.assertFalse(
            helpers.backup_config_zip(files, '/:/_backup_test.zip'))

        if os.path.isfile(zip_path):
            os.remove(zip_path)
Beispiel #6
0
    def _backup(backup_dir=None):
        if not backup_dir:
            return False
        source = [
            os.path.join(settings.DATA_DIR, 'sickchill.db'),
            settings.CONFIG_FILE,
            os.path.join(settings.DATA_DIR, 'failed.db'),
            os.path.join(settings.DATA_DIR, 'cache.db')
        ]
        target = os.path.join(
            backup_dir, 'sickchill-' + time.strftime('%Y%m%d%H%M%S') + '.zip')

        for (path, dirs, files) in os.walk(settings.CACHE_DIR):
            for dirname in dirs:
                if path == settings.CACHE_DIR and dirname not in ['images']:
                    dirs.remove(dirname)
            for filename in files:
                source.append(os.path.join(path, filename))

        return helpers.backup_config_zip(source, target, settings.DATA_DIR)