def install_language(env_manager, language_version, sudo_password=""):
    if env_manager == LanguageManager.PYENV:
        check_command = f"pyenv versions"
        check_response = run_command(check_command)

        if language_version in check_response:
            logger.info(
                f"Language Environment Manager: Already installed language version [language=python, version={language_version}]"
            )
            return

        logger.info(
            f"Language Environment Manager: Installing language version (this might take a bit, ~2 min) [language=python, version={language_version}]"
        )

        command = f"pyenv install {language_version}"
        run_command(command)

        logger.info(
            f"Language Environment Manager: Successfully installed language version [language=python, version={language_version}]"
        )
    elif env_manager == LanguageManager.JENV:
        host_system = OS.get_host_system()
        package_manager = OS.get_package_manager(host_system)

        if package_manager == PackageManager.BREW:
            install_java_version_via_homebrew(language_version, sudo_password)
        else:
            raise NotImplementedError(
                f"Language Environment Manager: Sorry, the requested package manager is not currently supported [package_manager={package_manager}]"
            )
    else:
        raise NotImplementedError(
            "Language Environment Manager: Sorry, the requested language manager is not currently supported (feel free to open an issue at https://github.com/JasonYao/pydotfiles/issues/new)"
        )
def uninstall_java_version_via_homebrew(language_version, sudo_password=""):
    logger.info(
        f"Language Environment Manager: Uninstalling language version [language=java, version={language_version}]"
    )

    if language_version != "8" and language_version != LATEST_CURRENT_JAVA_VERSION_IN_HOMEBREW and language_version != "latest":
        raise ValueError(
            f"Language Environment Manager: Due to a limitation in Homebrew, we are unable to uninstall any Java versions besides Java 8 and the latest Java (currently version {LATEST_CURRENT_JAVA_VERSION_IN_HOMEBREW})"
        )

    if language_version == LATEST_CURRENT_JAVA_VERSION_IN_HOMEBREW or language_version == "latest":
        command = f"brew cask uninstall java"
        run_command_with_communication(command, sudo_password)
        return

    # Getting java 8 requires getting versioned casks (note that there isn't a java9, java10, or java11 versioned cask)
    command = f"brew tap homebrew/cask-versions"
    run_command(command)

    command = f"brew cask uninstall java8"
    run_command_with_communication(command, sudo_password)

    logger.info(
        f"Language Environment Manager: Successfully uninstalled language version [language=java, version={language_version}]"
    )
def uninstall_language_environment_manager_via_homebrew(env_manager):
    if env_manager == LanguageManager.PYENV:
        command = "brew uninstall pyenv"
        run_command(command)
    elif env_manager == LanguageManager.JENV:
        command = "brew uninstall jenv"
        run_command(command)
    else:
        raise NotImplementedError(
            "Language Environment Manager: Sorry, the requested language manager is not currently supported (feel free to open an issue at https://github.com/JasonYao/pydotfiles/issues/new)"
        )
 def is_installed(self):
     if self.language_plugin_manager == LanguagePluginManager.PYENV_VIRTUALENV:
         current_installed_brew_packages = run_command("brew list")
         return "pyenv-virtualenv" in current_installed_brew_packages
     else:
         raise NotImplementedError(
             f"Language Environment Plugin Manager: Sorry, the requested language plugin manager is not currently supported (feel free to open an issue at https://github.com/JasonYao/pydotfiles/issues/new) [env_plugin_manager={self.language_plugin_manager}]"
         )
def uninstall_language_environment_plugin_manager_via_homebrew(
        language_plugin_manager):
    logger.info(
        f"Language Environment Plugin Manager: Uninstalling environment manager [env_plugin_manager={language_plugin_manager}]"
    )

    if language_plugin_manager == LanguagePluginManager.PYENV_VIRTUALENV:
        command = "brew uninstall pyenv-virtualenv"
        run_command(command)
    else:
        raise NotImplementedError(
            f"Language Environment Plugin Manager: Sorry, the requested language manager is not currently supported (feel free to open an issue at https://github.com/JasonYao/pydotfiles/issues/new) [env_plugin_manager={language_plugin_manager}]"
        )

    logger.info(
        f"Language Environment Plugin Manager: Successfully uninstalled environment manager [env_plugin_manager={language_plugin_manager}]"
    )
def install_language_environment_manager_via_homebrew(env_manager):
    logger.info(
        f"Language Environment Manager: Installing environment manager [env_manager={env_manager}]"
    )
    if env_manager == LanguageManager.PYENV:
        command = "brew install pyenv"
        run_command(command)
    elif env_manager == LanguageManager.JENV:
        command = "brew install jenv"
        run_command(command)
    else:
        raise NotImplementedError(
            "Language Environment Manager: Sorry, the requested language manager is not currently supported (feel free to open an issue at https://github.com/JasonYao/pydotfiles/issues/new)"
        )

    logger.info(
        f"Language Environment Manager: Successfully installed environment manager [env_manager={env_manager}]"
    )
def install_java_version_via_homebrew(language_version, sudo_password=""):
    # Checks to make sure that we haven't already installed this java version
    check_command = f"brew cask list"
    check_response = run_command(check_command)

    if (language_version == "latest"
            or language_version == LATEST_CURRENT_JAVA_VERSION_IN_HOMEBREW
        ) and "java " in check_response:
        logger.info(
            f"Language Environment Manager: Already installed language version [language=java, version={language_version}]"
        )
        return
    elif language_version == "8" and "java8" in check_response:
        logger.info(
            f"Language Environment Manager: Already installed language version [language=java, version={language_version}]"
        )
        return

    # Actually installs java
    logger.info(
        f"Language Environment Manager: Installing language version (takes a bit, ~2 min) [language=java, version={language_version}]"
    )

    if language_version != "8" and language_version != LATEST_CURRENT_JAVA_VERSION_IN_HOMEBREW and language_version != "latest":
        raise ValueError(
            f"Language Environment Manager: Due to a limitation in Homebrew, we are unable to install any Java versions besides Java 8 and the latest Java (currently version {LATEST_CURRENT_JAVA_VERSION_IN_HOMEBREW})"
        )

    if language_version == LATEST_CURRENT_JAVA_VERSION_IN_HOMEBREW or language_version == "latest":
        command = f"brew cask install java"
        run_command_with_communication(command, sudo_password)
        return

    # Getting java 8 requires getting versioned casks (note that there isn't a java9, java10, or java11 versioned cask)
    command = f"brew tap homebrew/cask-versions"
    run_command(command)

    command = f"brew cask install java8"
    run_command_with_communication(command, sudo_password)

    logger.info(
        f"Language Environment Manager: Successfully installed language version [language=java, version={language_version}]"
    )
def test_run_command_success(tmpdir):
    # Setup
    some_file = tmpdir.join("test.txt")
    some_file.write("testing")

    # Setup
    output = run_command("ls " + tmpdir.realpath().__str__())

    # Verification
    assert output == "test.txt"
def install_virtual_environment_version_with_pyenv(
        virtual_environment: VirtualEnvironment):
    logger.info(
        f"Language Environment Plugin Manager: Installing virtual environment [name={virtual_environment.name}, version={virtual_environment.version}]"
    )

    # Makes sure that the virtual env hasn't been created yet
    check_command = "pyenv versions"
    check_response = run_command(check_command)

    if virtual_environment.name in check_response:
        logger.info(
            f"Language Environment Plugin Manager: Already installed the virtual environment [name={virtual_environment.name}, version={virtual_environment.version}]"
        )
        return

    command = f"pyenv virtualenv {virtual_environment.version} {virtual_environment.name}"
    run_command(command)

    logger.info(
        f"Language Environment Plugin Manager: Successfully installed virtual environment [name={virtual_environment.name}, version={virtual_environment.version}]"
    )
def uninstall_language(env_manager, language_version, sudo_password=""):
    if env_manager == LanguageManager.PYENV:
        check_command = f"pyenv versions"
        check_response = run_command(check_command)

        if language_version not in check_response:
            logger.info(
                f"Language Environment Manager: Already uninstalled language version [language=python, version={language_version}]"
            )
            return

        logger.info(
            f"Language Environment Manager: Uninstalling language version [language=python, version={language_version}]"
        )

        command = f"pyenv uninstall {language_version}"
        run_command_with_communication(
            command, "y\n"
        )  # The 'y\n' is to confirm that we want to uninstall the given python version

        logger.info(
            f"Language Environment Manager: Successfully uninstalled language version [language=python, version={language_version}]"
        )
    elif env_manager == LanguageManager.JENV:
        host_system = OS.get_host_system()
        package_manager = OS.get_package_manager(host_system)

        if package_manager == PackageManager.BREW:
            uninstall_java_version_via_homebrew(language_version,
                                                sudo_password)
        else:
            raise NotImplementedError(
                f"Language Environment Manager: Sorry, the requested package manager is not currently supported [package_manager={package_manager}]"
            )
    else:
        raise NotImplementedError(
            "Language Environment Manager: Sorry, the requested language manager is not currently supported (feel free to open an issue at https://github.com/JasonYao/pydotfiles/issues/new)"
        )
Exemple #11
0
 def restart_dock():
     command = f"killall Dock"
     run_command(command)
Exemple #12
0
 def add_application_to_default_on_dock(application):
     command = f'defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/{application}.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"'
     run_command(command)
Exemple #13
0
 def delete_dock_plist_file():
     command = f'defaults delete com.apple.Dock persistent-apps'
     run_command(command)
Exemple #14
0
def test_run_command_fail_executable_not_found_in_path():
    with pytest.raises(RuntimeError):
        # System under test
        run_command("commandabc")
Exemple #15
0
def test_run_command_fail_none():
    with pytest.raises(RuntimeError):
        # System under test
        run_command(None)