Exemple #1
0
def test_directory(tmpdir):
    os.makedirs(f"{tmpdir.dirname}/dummy_directory", exist_ok=True)

    backup = Backup(f"{tmpdir.dirname}/dummy_directory")
    backup.create()

    assert not os.path.exists(backup.local_path)
    assert os.path.exists(backup.backup_path_full)

    backup.restore()
    assert os.path.exists(backup.local_path)

    backup.cleanup()
    assert not os.path.exists(backup.backup_path_full)
Exemple #2
0
def test_file(tmpdir):
    with open(f"{tmpdir.dirname}/dummy_file", "w") as dummy:
        dummy.write("")

    backup = Backup(f"{tmpdir.dirname}/dummy_file")
    backup.create()

    assert not os.path.exists(backup.local_path)
    assert os.path.exists(backup.backup_path_full)

    backup.restore()
    assert os.path.exists(backup.local_path)

    backup.cleanup()
    assert not os.path.exists(backup.backup_path_full)
Exemple #3
0
async def install_repository(repository):
    """Common installation steps of the repository."""
    persistent_directory = None
    await repository.update_repository()
    if repository.content.path.local is None:
        raise HacsException("repository.content.path.local is None")
    repository.validate.errors = []

    if not repository.can_install:
        raise HacsException(
            "The version of Home Assistant is not compatible with this version"
        )

    version = version_to_install(repository)
    if version == repository.data.default_branch:
        repository.ref = version
    else:
        repository.ref = f"tags/{version}"

    if repository.data.installed and repository.data.category == "netdaemon":
        persistent_directory = BackupNetDaemon(repository)
        persistent_directory.create()

    elif repository.data.persistent_directory:
        if os.path.exists(
                f"{repository.content.path.local}/{repository.data.persistent_directory}"
        ):
            persistent_directory = Backup(
                f"{repository.content.path.local}/{repository.data.persistent_directory}",
                tempfile.gettempdir() + "/hacs_persistent_directory/",
            )
            persistent_directory.create()

    if repository.data.installed and not repository.content.single:
        backup = Backup(repository.content.path.local)
        backup.create()

    if repository.data.zip_release and version != repository.data.default_branch:
        await repository.download_zip(repository)
    else:
        await download_content(repository)

    if repository.validate.errors:
        for error in repository.validate.errors:
            repository.logger.error(error)
        if repository.data.installed and not repository.content.single:
            backup.restore()

    if repository.data.installed and not repository.content.single:
        backup.cleanup()

    if persistent_directory is not None:
        persistent_directory.restore()
        persistent_directory.cleanup()

    if repository.validate.success:
        if repository.data.full_name not in repository.hacs.common.installed:
            if repository.data.full_name == "hacs/integration":
                repository.hacs.common.installed.append(
                    repository.data.full_name)
        repository.data.installed = True
        repository.data.installed_commit = repository.data.last_commit

        if version == repository.data.default_branch:
            repository.data.installed_version = None
        else:
            repository.data.installed_version = version

        await reload_after_install(repository)
        installation_complete(repository)
Exemple #4
0
async def install_repository(repository):
    """Common installation steps of the repository."""
    persistent_directory = None
    await repository.update_repository()

    if not repository.can_install:
        raise HacsException(
            "The version of Home Assistant is not compatible with this version"
        )

    version = version_to_install(repository)
    if version == repository.information.default_branch:
        repository.ref = version
    else:
        repository.ref = f"tags/{version}"

    if repository.repository_manifest:
        if repository.repository_manifest.persistent_directory:
            if os.path.exists(
                    f"{repository.content.path.local}/{repository.repository_manifest.persistent_directory}"
            ):
                persistent_directory = Backup(
                    f"{repository.content.path.local}/{repository.repository_manifest.persistent_directory}",
                    tempfile.gettempdir() + "/hacs_persistent_directory/",
                )
                persistent_directory.create()

    if repository.status.installed and not repository.content.single:
        backup = Backup(repository.content.path.local)
        backup.create()

    if (repository.repository_manifest.zip_release
            and version != repository.information.default_branch):
        validate = await repository.download_zip(repository.validate)
    else:
        validate = await repository.download_content(
            repository.validate,
            repository.content.path.remote,
            repository.content.path.local,
            repository.ref,
        )

    if validate.errors:
        for error in validate.errors:
            repository.logger.error(error)
        if repository.status.installed and not repository.content.single:
            backup.restore()

    if repository.status.installed and not repository.content.single:
        backup.cleanup()

    if persistent_directory is not None:
        persistent_directory.restore()
        persistent_directory.cleanup()

    if validate.success:
        if repository.information.full_name not in repository.common.installed:
            if repository.information.full_name == "hacs/integration":
                repository.common.installed.append(
                    repository.information.full_name)
        repository.status.installed = True
        repository.versions.installed_commit = repository.versions.available_commit

        if version == repository.information.default_branch:
            repository.versions.installed = None
        else:
            repository.versions.installed = version

        await reload_after_install(repository)
        installation_complete(repository)
Exemple #5
0
def test_muilti(tmpdir):
    backup = Backup(f"{tmpdir.dirname}/dummy_directory")
    backup.create()
    backup.create()