def get_wine_mono_download_link_from_github() -> str: """ >>> get_wine_mono_download_link_from_github() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE 'https://github.com//madewokherd/wine-mono/releases/download/wine-mono-.../wine-mono-...msi' """ filename = configmagick_linux.get_path_home_dir_current_user( ) / 'mono-latest-release.html' try: download_link = 'https://github.com/madewokherd/wine-mono/releases/latest' configmagick_linux.download_file(download_link=download_link, filename=filename) link = lib_shell.run_shell_command( 'fgrep ".msi" "{filename}" | fgrep "wine-mono" | fgrep "href="'. format(filename=filename), shell=True, quiet=True, use_sudo=True).stdout link = link.split('href="', 1)[1] link = 'https://github.com/' + link.split('"', 1)[0] finally: lib_shell.run_shell_command( 'rm -f "{filename}"'.format(filename=filename), shell=True, quiet=True, use_sudo=True) return str(link)
def get_wine_registry_data_type(reg_key: str, reg_subkey: str, wine_prefix: Union[str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux.get_current_username()) -> str: """ >>> install_wine_machine.create_wine_test_prefixes() >>> result = get_wine_registry_data_type(reg_key='HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment',\ reg_subkey='PATH', wine_prefix='wine_test_32') >>> assert result == 'REG_EXPAND_SZ' >>> result = get_wine_registry_data_type(reg_key='HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment',\ reg_subkey='PATH', wine_prefix='wine_test_64') >>> assert result == 'REG_EXPAND_SZ' >>> result = get_wine_registry_data_type(reg_key='HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment',\ reg_subkey='UNKNOWN', wine_prefix='wine_test_32') # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE Traceback (most recent call last): ... RuntimeError: can not read Wine Registry Data Type, WINEPREFIX=".../wine_test_32", key="...", subkey="UNKNOWN" """ wine_prefix = get_and_check_wine_prefix(wine_prefix=wine_prefix, username=username) try: registry_data_type = get_l_wine_registry_data_struct(reg_key=reg_key, reg_subkey=reg_subkey, wine_prefix=wine_prefix, username=username)[0] return registry_data_type except RuntimeError: raise RuntimeError('can not read Wine Registry Data Type, WINEPREFIX="{wine_prefix}", key="{reg_key}", subkey="{reg_subkey}"'.format( wine_prefix=wine_prefix, reg_key=reg_key, reg_subkey=reg_subkey))
def prepend_path_to_wine_registry_path(path_to_add: Union[str, pathlib.WindowsPath], wine_prefix: Union[str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux.get_current_username()) -> None: """ >>> install_wine_machine.create_wine_test_prefixes() >>> old_path = get_wine_registry_path(wine_prefix='wine_test_32') >>> prepend_path_to_wine_registry_path(path_to_add='c:\\\\test',wine_prefix='wine_test_32') >>> assert get_wine_registry_path(wine_prefix='wine_test_32').startswith('c:\\\\test;') >>> write_wine_registry_path(path=old_path, wine_prefix='wine_test_32') >>> assert get_wine_registry_path(wine_prefix='wine_test_32') == old_path """ wine_prefix = get_and_check_wine_prefix(wine_prefix=wine_prefix, username=username) current_wine_registry_path = get_wine_registry_path(wine_prefix=wine_prefix, username=username) s_path_to_add = str(path_to_add).strip() l_current_wine_registry_path = current_wine_registry_path.split(';') l_current_wine_registry_path = lib_list.ls_strip_elements(l_current_wine_registry_path) # the path must not end with \\ , because if we set it this might escape the last " !!! # like : wine reg add "..." /t "REG_EXPAND_SZ" /v "PATH" /d "c:\test\" /f leads to : /bin/sh: 1: Syntax error: Unterminated quoted string l_current_wine_registry_path = lib_list.ls_rstrip_elements(l_current_wine_registry_path, '\\') l_current_wine_registry_path = lib_list.del_double_elements(l_current_wine_registry_path) if not lib_list.is_list_element_fnmatching(ls_elements=l_current_wine_registry_path, s_fnmatch_searchpattern=s_path_to_add): l_current_wine_registry_path = [s_path_to_add] + l_current_wine_registry_path new_wine_registry_path = ';'.join(l_current_wine_registry_path) write_wine_registry_path(path=new_wine_registry_path, wine_prefix=wine_prefix, username=username)
def install_mono_latest(wine_prefix: Union[ str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux. get_current_username(), quiet: bool = False) -> None: """ install the latest mono version from github >>> install_wine_machine.create_wine_test_prefixes() >>> install_mono_latest('wine_test_32', quiet=True) >>> install_mono_latest('wine_test_64', quiet=True) """ wine_prefix = lib_wine.get_and_check_wine_prefix(wine_prefix, username) wine_arch = lib_wine.get_wine_arch_from_wine_prefix( wine_prefix=wine_prefix, username=username) mono_download_link = get_wine_mono_download_link_from_github() mono_msi_filename = pathlib.Path(mono_download_link.rsplit('/', 1)[1]) wine_cache_directory = lib_wine.get_path_wine_cache_for_user( username=username) lib_log_utils.banner_verbose( 'Installing Wine Mono :\n' 'WINEPREFIX="{wine_prefix}"\n' 'WINEARCH="{wine_arch}"\n' 'mono_msi_filename="{mono_msi_filename}"\n' 'wine_cache_directory="{wine_cache_directory}"'.format( wine_prefix=wine_prefix, wine_arch=wine_arch, wine_cache_directory=wine_cache_directory, mono_msi_filename=mono_msi_filename), quiet=quiet) download_latest_mono_msi_files_from_github(username=username, force_download=False, quiet=quiet) lib_log_utils.log_verbose( 'Install "{mono_msi_filename}" on WINEPREFIX="{wine_prefix}"'.format( mono_msi_filename=mono_msi_filename, wine_prefix=wine_prefix), quiet=quiet) command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine msiexec /i "{wine_cache_directory}/{mono_msi_filename}"'\ .format(wine_prefix=wine_prefix, wine_arch=wine_arch, wine_cache_directory=wine_cache_directory, mono_msi_filename=mono_msi_filename) lib_shell.run_shell_command(command, shell=True, run_as_user=username, pass_stdout_stderr_to_sys=True, quiet=quiet) lib_wine.fix_wine_permissions( wine_prefix=wine_prefix, username=username) # it is cheap, just in case lib_log_utils.banner_success( 'Wine Mono "{mono_msi_filename}" installed'.format( mono_msi_filename=mono_msi_filename))
def install_mono_recommended(wine_prefix: Union[ str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux. get_current_username(), quiet: bool = False) -> None: """ Installs the mono version stated in appwiz.cpl - might be not the newest version, se we should prefer to install the latest wine-mono from github Mono version can only be extracted from wine prefixes created with wine version 4.18 upwards, on older version this does not work >>> install_wine_machine.create_wine_test_prefixes() >>> install_mono_recommended('wine_test_32', quiet=True) >>> install_mono_recommended('wine_test_64', quiet=True) """ wine_prefix = lib_wine.get_and_check_wine_prefix(wine_prefix, username) wine_arch = lib_wine.get_wine_arch_from_wine_prefix( wine_prefix=wine_prefix, username=username) mono_msi_filename = get_mono_msi_filename_from_appwiz( wine_prefix=wine_prefix, username=username) wine_cache_directory = lib_wine.get_path_wine_cache_for_user( username=username) lib_log_utils.banner_verbose( 'Installing Wine Mono :\n' 'WINEPREFIX="{wine_prefix}"\n' 'WINEARCH="{wine_arch}"\n' 'mono_msi_filename="{mono_msi_filename}"\n' 'wine_cache_directory="{wine_cache_directory}"'.format( wine_prefix=wine_prefix, wine_arch=wine_arch, wine_cache_directory=wine_cache_directory, mono_msi_filename=mono_msi_filename), quiet=quiet) download_mono_msi_files_from_appwiz(wine_prefix=wine_prefix, username=username, force_download=False, quiet=quiet) command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine msiexec /i "{wine_cache_directory}/{mono_msi_filename}"'\ .format(wine_prefix=wine_prefix, wine_arch=wine_arch, wine_cache_directory=wine_cache_directory, mono_msi_filename=mono_msi_filename) lib_shell.run_shell_command(command, shell=True, run_as_user=username, pass_stdout_stderr_to_sys=True, quiet=quiet) lib_wine.fix_wine_permissions( wine_prefix=wine_prefix, username=username) # it is cheap, just in case
def get_python_exe_backup_download_link(version: str, arch: str = 'win32') -> str: """ get the download link for the python version from the webpage to the python installer exe Parameter: version = '3.8.0' arch = 'win32' or 'win64' >>> import unittest >>> assert get_python_exe_backup_download_link(version='3.8.0', arch='win32') == 'https://www.python.org/ftp/python/3.8.0/python-3.8.0.exe' >>> assert get_python_exe_backup_download_link(version='3.8.0', arch='win64') == 'https://www.python.org/ftp/python/3.8.0/python-3.8.0-amd64.exe' >>> unittest.TestCase().assertRaises(RuntimeError, get_python_exe_backup_download_link, version='3.8.0', arch='invalid') # invalid arch >>> unittest.TestCase().assertRaises(RuntimeError, get_python_exe_backup_download_link, version='3.1.9', arch='win32') # invalid version """ # noinspection PyBroadException arch = lib_wine.get_and_check_wine_arch_valid(arch) filename = configmagick_linux.get_path_home_dir_current_user( ) / 'python-latest-release.html' path_python_filename = get_path_python_exe_filename(version=version, arch=arch) try: download_link = 'https://www.python.org/downloads/windows/' configmagick_linux.download_file(download_link=download_link, filename=filename) python_backup_download_link = lib_shell.run_shell_command( 'fgrep "{path_python_filename}" "{filename}" | fgrep "href="'. format(filename=filename, path_python_filename=path_python_filename), shell=True, quiet=True, use_sudo=True).stdout # <li>Download <a href="https://www.python.org/ftp/python/3.8.0/python-3.8.0-amd64.exe">Windows x86-64 executable installer</a></li> python_backup_download_link = python_backup_download_link.split( '<a href="')[1] # https://www.python.org/ftp/python/3.8.0/python-3.8.0-amd64.exe">Windows x86-64 executable installer</a></li> python_backup_download_link = python_backup_download_link.split( '"')[0].strip() # https://www.python.org/ftp/python/3.8.0/python-3.8.0-amd64.exe except Exception: raise RuntimeError( 'can not get Download Link for Python {path_python_filename}'. format(path_python_filename=path_python_filename)) finally: lib_shell.run_shell_command( 'rm -f "{filename}"'.format(filename=filename), shell=True, quiet=True, use_sudo=True) return str(python_backup_download_link)
def get_wine_registry_path(wine_prefix: Union[str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux.get_current_username()) -> str: """ >>> install_wine_machine.create_wine_test_prefixes() >>> result = get_wine_registry_path(wine_prefix='wine_test_32') >>> assert 'c:\\windows' in result.lower() >>> result = get_wine_registry_path(wine_prefix='wine_test_64') >>> assert 'c:\\windows' in result.lower() """ wine_prefix = get_and_check_wine_prefix(wine_prefix=wine_prefix, username=username) current_wine_registry_path = get_wine_registry_data(reg_key='HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment', reg_subkey='PATH', wine_prefix=wine_prefix, username=username) return current_wine_registry_path
def install_gecko(wine_prefix: Union[ str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux.get_current_username(), quiet: bool = False) -> None: """ install 32 Bit Gecko for 32/64 Bit Wine, and 64 Bit Gecko for 64 Bit Wine >>> install_wine_machine.create_wine_test_prefixes() >>> install_gecko(wine_prefix='wine_test_32', quiet=True) >>> install_gecko(wine_prefix='wine_test_64', quiet=True) """ lib_log_utils.banner_verbose( 'Install Gecko on WINEPREFIX="{wine_prefix}"'.format( wine_prefix=wine_prefix), quiet=quiet) wine_prefix = lib_wine.get_and_check_wine_prefix( wine_prefix, username) # prepend /home/user if needed download_gecko_msi_files(wine_prefix=wine_prefix, username=username, quiet=True) wine_arch = lib_wine.get_wine_arch_from_wine_prefix(wine_prefix, username) if wine_arch == 'win32' or wine_arch == 'win64': lib_log_utils.log_verbose( 'Install Gecko 32 Bit on WINEPREFIX="{wine_prefix}"'.format( wine_prefix=wine_prefix), quiet=quiet) install_gecko_32(wine_prefix=wine_prefix, username=username, quiet=quiet) if wine_arch == 'win64': lib_log_utils.log_verbose( 'Install Gecko 64 Bit on WINEPREFIX="{wine_prefix}"'.format( wine_prefix=wine_prefix), quiet=quiet) install_gecko_64(wine_prefix=wine_prefix, username=username, quiet=quiet) lib_wine.fix_wine_permissions( wine_prefix=wine_prefix, username=username) # it is cheap, just in case lib_log_utils.banner_success('Wine Gecko installed')
def install_python_setuptools(wine_prefix: Union[ str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux. get_current_username(), quiet: bool = False) -> None: wine_prefix = lib_wine.get_and_check_wine_prefix(wine_prefix, username) wine_arch = lib_wine.get_wine_arch_from_wine_prefix( wine_prefix=wine_prefix, username=username) wine_cache_directory = lib_wine.get_path_wine_cache_for_user( username=username) download_get_pip(username=username) command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine python "{wine_cache_directory}/get-pip.py"'.format( wine_prefix=wine_prefix, wine_arch=wine_arch, wine_cache_directory=wine_cache_directory) lib_shell.run_shell_command(command, run_as_user=username, quiet=True, shell=True)
def get_latest_python_version() -> str: """ get latest Python3 Version as String, or '3.8.0' if can not determined Returns: "3.8.0" or whatever is the latest Version Number >>> version = get_latest_python_version() >>> assert '.' in version >>> assert get_latest_python_version().startswith('3') """ # noinspection PyBroadException filename = configmagick_linux.get_path_home_dir_current_user( ) / 'python-latest-release.html' try: download_link = 'https://www.python.org/downloads/windows/' configmagick_linux.download_file(download_link=download_link, filename=filename) s_version = lib_shell.run_shell_command( 'fgrep "Latest Python 3 Release" "{filename}" | fgrep "href="'. format(filename=filename), shell=True, quiet=True, use_sudo=True).stdout # <li><a href="/downloads/release/python-380/">Latest Python 3 Release - Python 3.8.0</a></li> s_version = s_version.rsplit('Latest Python 3 Release', 1)[1] # - Python 3.8.0</a></li> s_version = s_version.split('Python', 1)[1].strip() # 3.8.0</a></li> s_version = s_version.split('</a>', 1)[0].strip() # 3.8.0 except Exception: lib_log_utils.log_warning( 'can not determine latest Python Version, assuming Version 3.8.0') s_version = '3.8.0' finally: lib_shell.run_shell_command( 'rm -f "{filename}"'.format(filename=filename), shell=True, quiet=True, use_sudo=True) return str(s_version)
def get_git_portable_download_link_from_github(wine_arch: str) -> str: """ Parameter: wine_arch = win32 or win64 >>> get_git_portable_download_link_from_github(wine_arch='win32') # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE 'https://github.com/git-for-windows/git/releases/download/v...windows.1/PortableGit-...-32-bit.7z.exe' >>> get_git_portable_download_link_from_github(wine_arch='win64') # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE 'https://github.com/git-for-windows/git/releases/download/v...windows.1/PortableGit-...-64-bit.7z.exe' >>> get_git_portable_download_link_from_github(wine_arch='invalid') # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE Traceback (most recent call last): ... subprocess.CalledProcessError: ... """ filename = configmagick_linux.get_path_home_dir_current_user( ) / 'git-latest-release.html' try: download_link = 'https://github.com/git-for-windows/git/releases/latest' configmagick_linux.download_file(download_link=download_link, filename=filename) link = lib_shell.run_shell_command( 'fgrep "PortableGit-" "{filename}" | fgrep "{bit}-bit.7z.exe" | fgrep "href="' .format(filename=filename, bit=wine_arch[3:]), shell=True, quiet=True, use_sudo=True).stdout link = link.split('href="', 1)[1] link = 'https://github.com' + link.split('"', 1)[0] finally: lib_shell.run_shell_command( 'rm -f "{filename}"'.format(filename=filename), shell=True, quiet=True, use_sudo=True) return str(link)
def write_wine_registry_path(path: str, wine_prefix: Union[str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux.get_current_username()) -> None: """ >>> install_wine_machine.create_wine_test_prefixes() >>> old_path = get_wine_registry_path(wine_prefix='wine_test_32') >>> write_wine_registry_path(path='c:\\\\test', wine_prefix='wine_test_32') >>> assert get_wine_registry_path(wine_prefix='wine_test_32') == 'c:\\\\test' >>> write_wine_registry_path(path=old_path, wine_prefix='wine_test_32') >>> restored_path = get_wine_registry_path(wine_prefix='wine_test_32') >>> assert restored_path == old_path """ # the path must not end with \\ , because if we set it this might escape the last " !!! # like : wine reg add "..." /t "REG_EXPAND_SZ" /v "PATH" /d "c:\test\" /f leads to : /bin/sh: 1: Syntax error: Unterminated quoted string path = path.strip().rstrip('\\') wine_prefix = get_and_check_wine_prefix(wine_prefix=wine_prefix, username=username) write_wine_registry_data(reg_key='HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment', reg_subkey='PATH', reg_data=path, wine_prefix=wine_prefix, username=username)
def write_wine_registry_data(reg_key: str, reg_subkey: str, reg_data: str, reg_data_type: str = 'auto', wine_prefix: Union[str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux.get_current_username()) -> None: """ write wine registry data Parameter: reg_data_type: 'auto' to get the data type if the key already exists, otherwise put 'REG_SZ' or 'REG_EXPAND_SZ' """ wine_prefix = get_and_check_wine_prefix(wine_prefix=wine_prefix, username=username) try: wine_arch = get_wine_arch_from_wine_prefix(wine_prefix=wine_prefix, username=username) if reg_data_type == 'auto': reg_data_type = get_wine_registry_data_type(reg_key=reg_key, reg_subkey=reg_subkey, wine_prefix=wine_prefix, username=username) command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine reg add "{reg_key}" /t "{reg_data_type}" /v "{reg_subkey}" /d "{reg_data}" /f'\ .format(wine_prefix=wine_prefix, wine_arch=wine_arch, reg_key=reg_key, reg_data_type=reg_data_type, reg_subkey=reg_subkey, reg_data=reg_data) lib_shell.run_shell_command(command, quiet=True, shell=True, run_as_user=username) except subprocess.CalledProcessError: raise RuntimeError('can not write Wine Registry, WINEPREFIX="{wine_prefix}", key="{reg_key}", subkey="{reg_subkey}"'.format( wine_prefix=wine_prefix, reg_key=reg_key, reg_subkey=reg_subkey))
def get_l_wine_registry_data_struct(reg_key: str, reg_subkey: str, wine_prefix: Union[str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux.get_current_username()) -> Tuple[str, str]: """ :returns [data_type, data] >>> install_wine_machine.create_wine_test_prefixes() >>> result = get_l_wine_registry_data_struct(reg_key='HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment',\ reg_subkey='PATH', wine_prefix='wine_test_32') >>> assert result[0] == 'REG_EXPAND_SZ' >>> assert 'c:\\windows' in result[1].lower() >>> result = get_l_wine_registry_data_struct(reg_key='HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment',\ reg_subkey='PATH', wine_prefix='wine_test_64') >>> assert result[0] == 'REG_EXPAND_SZ' >>> assert 'c:\\windows' in result[1].lower() >>> result = get_l_wine_registry_data_struct(reg_key='HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment',\ reg_subkey='UNKNOWN', wine_prefix='wine_test_32') # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE Traceback (most recent call last): ... RuntimeError: can not read Wine Registry, WINEPREFIX=".../wine_test_32", key="...", subkey="UNKNOWN" """ try: wine_prefix = get_and_check_wine_prefix(wine_prefix=wine_prefix, username=username) wine_arch = get_wine_arch_from_wine_prefix(wine_prefix=wine_prefix, username=username) command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine reg query "{reg_key}" /v "{reg_subkey}"'.format( wine_prefix=wine_prefix, wine_arch=wine_arch, reg_key=reg_key, reg_subkey=reg_subkey) result = lib_shell.run_shell_command(command, quiet=True, shell=True, run_as_user=username) registry_string = result.stdout.split(reg_key)[1] # because there may be blanks in the key registry_string = registry_string.split(reg_subkey)[1] # and there might be blanks in the subkey l_registry_data = registry_string.split(maxsplit=1) # here we split data_type and Data, there might be blanks in the data return l_registry_data[0], l_registry_data[1] except subprocess.CalledProcessError: raise RuntimeError('can not read Wine Registry, WINEPREFIX="{wine_prefix}", key="{reg_key}", subkey="{reg_subkey}"'.format( wine_prefix=wine_prefix, reg_key=reg_key, reg_subkey=reg_subkey))
def install_git(wine_prefix: Union[ str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux.get_current_username(), quiet: bool = False) -> None: """ install git on wine >>> install_wine_machine.create_wine_test_prefixes() >>> install_git(wine_prefix='wine_test_32', quiet=True) >>> install_git(wine_prefix='wine_test_64', quiet=True) """ configmagick_linux.full_update_and_upgrade(quiet=quiet) configmagick_linux.install_linux_package('p7zip-full', quiet=quiet) wine_prefix = lib_wine.get_and_check_wine_prefix(wine_prefix, username) wine_arch = lib_wine.get_wine_arch_from_wine_prefix( wine_prefix=wine_prefix, username=username) wine_cache_directory = lib_wine.get_path_wine_cache_for_user( username=username) path_git_filename = get_path_git_filename(wine_arch=wine_arch) lib_log_utils.banner_verbose( 'Installing Git Portable :\n' 'WINEPREFIX="{wine_prefix}"\n' 'WINEARCH="{wine_arch}"\n' 'git_filename="{path_git_filename}"\n' 'wine_cache_directory="{wine_cache_directory}"'.format( wine_prefix=wine_prefix, wine_arch=wine_arch, path_git_filename=path_git_filename, wine_cache_directory=wine_cache_directory), quiet=quiet) download_latest_git_files_from_github_to_winecache(wine_prefix=wine_prefix, username=username, quiet=quiet) lib_log_utils.log_verbose( 'Install "{path_git_filename}" on WINEPREFIX="{wine_prefix}"'.format( path_git_filename=path_git_filename, wine_prefix=wine_prefix), quiet=quiet) path_git_install_dir = wine_prefix / 'drive_c/Program Files/PortableGit' lib_shell.run_shell_command('rm -Rf "{path_git_install_dir}"'.format( path_git_install_dir=path_git_install_dir), quiet=True, use_sudo=True, shell=True) # remove old installation if exists configmagick_linux.force_remove_directory_recursive(path_git_install_dir) command = '7z e {wine_cache_directory}/{path_git_filename} -o"{path_git_install_dir}" -y -bd'.format( wine_cache_directory=wine_cache_directory, path_git_filename=path_git_filename, path_git_install_dir=path_git_install_dir) lib_shell.run_shell_command(command, shell=True, run_as_user=username, pass_stdout_stderr_to_sys=True, quiet=quiet) lib_wine.fix_wine_permissions( wine_prefix=wine_prefix, username=username) # it is cheap, just in case lib_wine.prepend_path_to_wine_registry_path( path_to_add='C:\\Program Files\\PortableGit', wine_prefix=wine_prefix, username=username) # we need to use wineconsole here command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wineconsole git --version'.format( wine_prefix=wine_prefix, wine_arch=wine_arch) try: lib_shell.run_shell_command(command, run_as_user=username, quiet=True, shell=True) lib_log_utils.banner_success('Git installed') except subprocess.CalledProcessError: raise RuntimeError( 'can not install git portable on WINEPREFIX="{wine_prefix}"'. format(wine_prefix=wine_prefix))
def install_python_nuget(wine_prefix: Union[ str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux. get_current_username(), quiet: bool = False) -> None: """ install python on wine, using the nuget installer wine stable 4.0.2 : not working wine devel 4.19 : working wine staging 4.19 : working >>> install_wine_machine.create_wine_test_prefixes() >>> install_python_nuget(wine_prefix='wine_test_32', quiet=True) >>> install_python_nuget(wine_prefix='wine_test_64', quiet=True) >>> # test python 32 Bit installed >>> wine_prefix = lib_wine.get_and_check_wine_prefix(wine_prefix='wine_test_32') >>> wine_arch = lib_wine.get_wine_arch_from_wine_prefix(wine_prefix=wine_prefix) >>> command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine ' >>> result = lib_shell.run_shell_command('WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine python --version' ... .format(wine_prefix=wine_prefix, wine_arch=wine_arch), shell=True, quiet=True) >>> assert result.stdout.startswith('Python') >>> assert '.' in result.stdout >>> # test python 64 Bit installed >>> wine_prefix = lib_wine.get_and_check_wine_prefix(wine_prefix='wine_test_64') >>> wine_arch = lib_wine.get_wine_arch_from_wine_prefix(wine_prefix=wine_prefix) >>> command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine ' >>> result = lib_shell.run_shell_command('WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine python --version' ... .format(wine_prefix=wine_prefix, wine_arch=wine_arch), shell=True, quiet=True) >>> assert result.stdout.startswith('Python') >>> assert '.' in result.stdout """ wine_prefix = lib_wine.get_and_check_wine_prefix(wine_prefix, username) wine_arch = lib_wine.get_wine_arch_from_wine_prefix( wine_prefix=wine_prefix, username=username) if wine_arch == 'win32': python_version = 'pythonx86' else: python_version = 'python' wine_cache_directory = lib_wine.get_path_wine_cache_for_user( username=username) path_nuget_filename = pathlib.Path('nuget.exe') lib_log_utils.banner_verbose( 'Installing Python :\n' 'WINEPREFIX="{wine_prefix}"\n' 'WINEARCH="{wine_arch}"\n' 'wine_cache_directory="{wine_cache_directory}"'.format( wine_prefix=wine_prefix, wine_arch=wine_arch, wine_cache_directory=wine_cache_directory), quiet=quiet) download_nuget(username=username) lib_log_utils.log_verbose( 'Install Python on WINEPREFIX="{wine_prefix}"'.format( wine_prefix=wine_prefix), quiet=quiet) command = 'DISPLAY="{display}" WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" '\ 'wineconsole "{wine_cache_directory}/{path_nuget_filename}" '\ 'install {python_version} -ExcludeVersion -OutputDirectory "C:\\Program Files"'\ .format(display=configmagick_linux.get_env_display(), wine_prefix=wine_prefix, wine_arch=wine_arch, wine_cache_directory=wine_cache_directory, path_nuget_filename=path_nuget_filename, python_version=python_version) lib_shell.run_shell_command(command, shell=True, run_as_user=username, pass_stdout_stderr_to_sys=True, quiet=quiet) lib_wine.fix_wine_permissions(wine_prefix=wine_prefix, username=username) lib_wine.prepend_path_to_wine_registry_path( 'C:\\Program Files\\{python_version}\\tools'.format( python_version=python_version), wine_prefix=wine_prefix, username=username) command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine python --version'.format( wine_prefix=wine_prefix, wine_arch=wine_arch) try: result = lib_shell.run_shell_command(command, run_as_user=username, quiet=True, shell=True) assert result.stdout.startswith('Python') lib_log_utils.banner_success('{python_version} installed OK'.format( python_version=result.stdout)) except (subprocess.CalledProcessError, AssertionError): raise RuntimeError( 'can not install Python on WINEPREFIX="{wine_prefix}"'.format( wine_prefix=wine_prefix))
def install_python(wine_prefix: Union[ str, pathlib.Path] = configmagick_linux.get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux.get_current_username(), python_version: str = 'latest', quiet: bool = False) -> None: """ install python on wine, using the normal installer - unfortunately this does not work on travis Parameter: python_version : 'latest' or valid Version number, like '3.8.0' >>> install_wine_machine.create_wine_test_prefixes() >>> install_python(wine_prefix='wine_test_32', quiet=True) >>> install_python(wine_prefix='wine_test_64', quiet=True) >>> # test python 32 Bit installed >>> wine_prefix = lib_wine.get_and_check_wine_prefix(wine_prefix='wine_test_32') >>> wine_arch = lib_wine.get_wine_arch_from_wine_prefix(wine_prefix=wine_prefix) >>> command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine ' >>> result = lib_shell.run_shell_command('WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine python --version' ... .format(wine_prefix=wine_prefix, wine_arch=wine_arch), shell=True, quiet=True) >>> assert result.stdout.startswith('Python') >>> assert '.' in result.stdout >>> # test python 64 Bit installed >>> wine_prefix = lib_wine.get_and_check_wine_prefix(wine_prefix='wine_test_64') >>> wine_arch = lib_wine.get_wine_arch_from_wine_prefix(wine_prefix=wine_prefix) >>> command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine ' >>> result = lib_shell.run_shell_command('WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine python --version' ... .format(wine_prefix=wine_prefix, wine_arch=wine_arch), shell=True, quiet=True) >>> assert result.stdout.startswith('Python') >>> assert '.' in result.stdout """ wine_prefix = lib_wine.get_and_check_wine_prefix(wine_prefix, username) wine_arch = lib_wine.get_wine_arch_from_wine_prefix( wine_prefix=wine_prefix, username=username) if python_version == 'latest': python_version = get_latest_python_version() path_python_filename = get_path_python_exe_filename(version=python_version, arch=wine_arch) wine_cache_directory = lib_wine.get_path_wine_cache_for_user( username=username) lib_log_utils.banner_verbose( 'Installing Python :\n' 'WINEPREFIX="{wine_prefix}"\n' 'WINEARCH="{wine_arch}"\n' 'python_filename="{path_python_filename}"\n' 'wine_cache_directory="{wine_cache_directory}"'.format( wine_prefix=wine_prefix, wine_arch=wine_arch, wine_cache_directory=wine_cache_directory, path_python_filename=path_python_filename), quiet=quiet) download_python_exe_file(python_version=python_version, wine_prefix=wine_prefix, username=username) lib_log_utils.log_verbose( 'Install "{path_python_filename}" on WINEPREFIX="{wine_prefix}"'. format(path_python_filename=path_python_filename, wine_prefix=wine_prefix), quiet=quiet) command = 'DISPLAY="{display}" WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" '\ 'wineconsole "{wine_cache_directory}/{path_python_filename}" '\ '/quiet InstallAllUsers=1 PrependPath=1 Include_test=0'\ .format(wine_prefix=wine_prefix, wine_arch=wine_arch, wine_cache_directory=wine_cache_directory, path_python_filename=path_python_filename, display=configmagick_linux.get_env_display()) lib_shell.run_shell_command(command, shell=True, run_as_user=username, pass_stdout_stderr_to_sys=True, quiet=quiet) lib_wine.fix_wine_permissions(wine_prefix=wine_prefix, username=username) command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine python --version'.format( wine_prefix=wine_prefix, wine_arch=wine_arch) try: result = lib_shell.run_shell_command(command, run_as_user=username, quiet=True, shell=True) assert result.stdout.startswith('Python') lib_log_utils.banner_success('{python_version} installed OK'.format( python_version=result.stdout)) except (subprocess.CalledProcessError, AssertionError): raise RuntimeError( 'can not install Python on WINEPREFIX="{wine_prefix}"'.format( wine_prefix=wine_prefix))