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 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 download_nuget(username: str = configmagick_linux.get_current_username(), force_download: bool = False) -> None: """ Downloads nuget.exe to the WineCache directory >>> username = configmagick_linux.get_current_username() >>> path_nuget_filename = pathlib.Path('nuget.exe') >>> path_downloaded_file = configmagick_linux.get_path_home_dir_current_user() / '.cache/wine' / path_nuget_filename >>> if path_downloaded_file.is_file(): ... path_downloaded_file.unlink() >>> download_nuget(username=username, force_download=True) >>> assert path_downloaded_file.is_file() >>> download_nuget(username=username, force_download=False) >>> assert path_downloaded_file.is_file() """ nuget_download_link = 'https://aka.ms/nugetclidl' path_nuget_filename = pathlib.Path('nuget.exe') if lib_wine.is_file_in_wine_cache(filename=path_nuget_filename, username=username) or force_download: if force_download: lib_wine.remove_file_from_winecache(filename=path_nuget_filename, username=username) else: return lib_wine.download_file_to_winecache(download_link=nuget_download_link, filename=path_nuget_filename, username=username)
def download_latest_git_files_from_github_to_winecache( wine_prefix: Union[str, pathlib.Path] = configmagick_linux. get_path_home_dir_current_user() / '.wine', username: str = configmagick_linux.get_current_username(), force_download: bool = False, quiet: bool = False) -> None: """ >>> install_wine_machine.create_wine_test_prefixes() >>> download_latest_git_files_from_github_to_winecache(wine_prefix = 'wine_test_32', force_download=True, quiet=False) >>> download_latest_git_files_from_github_to_winecache(wine_prefix = 'wine_test_64', force_download=False, quiet=False) """ 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) lib_log_utils.log_verbose( 'Download latest Portable Git from Github to Wine Cache', quiet=quiet) git_download_link = get_git_portable_download_link_from_github( wine_arch=wine_arch) git_exe_filename = pathlib.Path(git_download_link.rsplit('/', 1)[1]) if lib_wine.is_file_in_wine_cache(filename=git_exe_filename, username=username) or force_download: if force_download: lib_wine.remove_file_from_winecache(filename=git_exe_filename, username=username) lib_wine.download_file_to_winecache( download_link=git_download_link, filename=git_exe_filename, username=username) else: lib_wine.download_file_to_winecache(download_link=git_download_link, filename=git_exe_filename, username=username)
def is_file_in_wine_cache(filename: pathlib.Path, username: str = configmagick_linux.get_current_username()) -> bool: path_wine_cache = get_path_wine_cache_for_user(username=username) path_file = path_wine_cache / filename if path_file.is_file(): return True else: return False
def fix_permissions_winecache(username: str = configmagick_linux.get_current_username()) -> None: path_wine_cache = get_path_wine_cache_for_user(username=username) if path_wine_cache.exists(): lib_shell.run_shell_command('chown -R "{username}"."{username}" "{path_wine_cache}"' .format(username=username, path_wine_cache=path_wine_cache), quiet=True, use_sudo=True) lib_shell.run_shell_command('chmod -R 0775 "{path_wine_cache}"' .format(path_wine_cache=path_wine_cache), quiet=True, use_sudo=True)
def get_gecko_64_filename_from_appwiz( wine_prefix: Union[str, pathlib.Path], username: str = configmagick_linux.get_current_username() ) -> pathlib.Path: """ Gecko 64 Bit Filename can only be read from a 64 Bit Wine Prefix Gecko Filename can only be extracted from wine prefixes created with wine version 4.18 upwards, on older version this does not work and we assume gecko-2.47 >>> import unittest >>> install_wine_machine.create_wine_test_prefixes() >>> wine_prefix = lib_wine.get_and_check_wine_prefix('wine_test_32') >>> unittest.TestCase().assertRaises(RuntimeError, get_gecko_64_filename_from_appwiz, wine_prefix) >>> wine_prefix = lib_wine.get_and_check_wine_prefix('wine_test_64') >>> path_gecko_64_filename = get_gecko_64_filename_from_appwiz(wine_prefix) >>> assert str(path_gecko_64_filename).startswith('wine_gecko-') and str(path_gecko_64_filename).endswith('-x86_64.msi') """ wine_arch = lib_wine.get_wine_arch_from_wine_prefix( wine_prefix=wine_prefix, username=username) if wine_arch == 'win32': raise RuntimeError( 'can not determine Gecko 64 Bit msi Filename from a 32 Bit Wine Machine' ) else: path_appwiz = pathlib.Path( wine_prefix) / 'drive_c/windows/system32/appwiz.cpl' if not path_appwiz.is_file(): raise RuntimeError( 'can not determine Gecko MSI Filename, File "{path_appwiz}" does not exist' .format(path_appwiz=path_appwiz)) try: response = lib_shell.run_shell_command( 'strings -d --bytes=12 --encoding=s "{path_appwiz}" | fgrep "wine_gecko" | fgrep "x86_64.msi"' .format(path_appwiz=path_appwiz), shell=True, quiet=True, use_sudo=True) gecko_64_filename = response.stdout except (subprocess.CalledProcessError, RuntimeError): # this happens on old wine versions, the wine_gecko-2.47-x86.msi is not present in the appwiz.cpl lib_log_utils.log_warning( 'Can not determine Gecko Version from appwiz.cpl - assuming "wine_gecko-2.47-x86_64.msi"' ) gecko_64_filename = 'wine_gecko-2.47-x86_64.msi' path_gecko_64_filename = pathlib.Path(gecko_64_filename) return path_gecko_64_filename
def raise_if_wine_prefix_does_not_match_user_homedir(wine_prefix: Union[str, pathlib.Path], username: str = configmagick_linux.get_current_username()) -> None: """ >>> import unittest >>> assert raise_if_wine_prefix_does_not_match_user_homedir(wine_prefix='/home/test/wine', username='******') is None >>> unittest.TestCase().assertRaises(RuntimeError, raise_if_wine_prefix_does_not_match_user_homedir, wine_prefix='/home/test/wine', username='******') """ if username == 'root': if not str(wine_prefix).startswith('/root/'): raise RuntimeError('wine_prefix "{wine_prefix}" is not within user home directory "/root"'.format(wine_prefix=wine_prefix)) else: if not str(wine_prefix).startswith('/home/{username}/'.format(username=username)): raise RuntimeError('wine_prefix "{wine_prefix}" is not within user home directory "/home/{username}"'.format( wine_prefix=wine_prefix, username=username))
def raise_if_path_outside_homedir(wine_prefix: Union[str, pathlib.Path], username: str = configmagick_linux.get_current_username()) -> None: """ >>> import unittest >>> username = configmagick_linux.get_current_username() >>> path_user_home = configmagick_linux.get_path_home_dir_user(username=username) >>> assert raise_if_path_outside_homedir(wine_prefix=path_user_home / 'test', username=username) is None >>> unittest.TestCase().assertRaises(RuntimeError, raise_if_path_outside_homedir, wine_prefix='/test', username=username) """ wine_prefix = pathlib.Path(wine_prefix) # if wine_prefix is passed as string path_user_home = configmagick_linux.get_path_home_dir_user(username=username) if not str(wine_prefix).startswith(str(path_user_home)): raise RuntimeError('the WINEPREFIX does not reside under {path_user_home}: "{wine_prefix}"' .format(path_user_home=path_user_home, wine_prefix=wine_prefix))
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 get_wine_arch_from_wine_prefix(wine_prefix: Union[str, pathlib.Path], username: str = configmagick_linux.get_current_username()) -> str: l_valid_wine_archs = ['win32', 'win64'] wine_prefix = get_and_check_wine_prefix(wine_prefix=wine_prefix, username=username) path_wine_system_registry = get_and_check_path_wine_system_registry(wine_prefix=wine_prefix) with open(str(path_wine_system_registry), mode='r') as registry_file: registry_file_content = registry_file.read() l_result = lib_regexp.reg_grep('#arch=', registry_file_content) if not l_result: raise RuntimeError('can not get wine_arch from system_registry="{path_wine_system_registry}"' .format(path_wine_system_registry=path_wine_system_registry)) wine_arch = l_result[0].rsplit('=', 1)[1].strip().lower() if wine_arch not in l_valid_wine_archs: raise RuntimeError('invalid wine_arch detected in system_registry="{path_wine_system_registry}": "{wine_arch}"' .format(path_wine_system_registry=path_wine_system_registry, wine_arch=wine_arch)) return str(wine_arch)
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 get_and_check_wine_prefix(wine_prefix: Union[str, pathlib.Path], username: str = configmagick_linux.get_current_username()) -> pathlib.Path: """ if wine_prefix does not start with /home/ then prepend /home/<username>/ >>> assert get_and_check_wine_prefix(wine_prefix='/home/test/my_wine', username='******') == pathlib.PosixPath('/home/test/my_wine') >>> assert get_and_check_wine_prefix(wine_prefix='my_wine', username='******') == pathlib.PosixPath('/home/test/my_wine') """ wine_prefix = pathlib.Path(wine_prefix) # if wine_prefix is passed as string if username == 'root': if not str(wine_prefix).startswith('/root/'): wine_prefix = pathlib.Path('/root') / str(wine_prefix) else: if not str(wine_prefix).startswith('/home/'): wine_prefix = pathlib.Path('/home/{username}'.format(username=username)) / str(wine_prefix) raise_if_wine_prefix_does_not_match_user_homedir(wine_prefix=wine_prefix, username=username) return wine_prefix
def download_setup_tools( username: str = configmagick_linux.get_current_username(), quiet: bool = False) -> None: """ >>> download_setup_tools(quiet=True) >>> wine_cache_directory = lib_wine.get_path_wine_cache_for_user() >>> assert (wine_cache_directory / 'setuptools/easy_install.py').exists() """ configmagick_linux.install_linux_package('git') wine_cache_directory = lib_wine.get_path_wine_cache_for_user( username=username) command = 'git clone https://github.com/pypa/setuptools.git {wine_cache_directory}/setuptools'.format( wine_cache_directory=wine_cache_directory) lib_shell.run_shell_command(command, shell=True, run_as_user=username, pass_stdout_stderr_to_sys=True, quiet=quiet)
def get_mono_msi_filename_from_appwiz( wine_prefix: Union[str, pathlib.Path], username: str = configmagick_linux.get_current_username() ) -> pathlib.Path: """ >>> install_wine_machine.create_wine_test_prefixes() >>> path_mono_msi_filename = get_mono_msi_filename_from_appwiz(wine_prefix='wine_test_32') >>> assert str(path_mono_msi_filename).startswith('wine-mono-') and str(path_mono_msi_filename).endswith('.msi') >>> path_mono_msi_filename = get_mono_msi_filename_from_appwiz(wine_prefix='wine_test_64') >>> assert str(path_mono_msi_filename).startswith('wine-mono-') and str(path_mono_msi_filename).endswith('.msi') """ 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': path_appwiz = wine_prefix / 'drive_c/windows/system32/appwiz.cpl' else: path_appwiz = wine_prefix / 'drive_c/windows/syswow64/appwiz.cpl' if not path_appwiz.is_file(): raise RuntimeError( 'can not determine Mono MSI Filename, File "{path_appwiz}" does not exist' .format(path_appwiz=path_appwiz)) # this fails from unknown reason on travis xenial ! response = lib_shell.run_shell_command( 'strings -d --bytes=12 --encoding=s "{path_appwiz}" | fgrep "wine-mono-" | fgrep ".msi"' .format(path_appwiz=path_appwiz), shell=True, quiet=True, use_sudo=True) mono_msi_filename = response.stdout if not mono_msi_filename: raise RuntimeError( 'can not determine Mono MSI Filename from WINEPREFIX="{wine_prefix}"' .format(wine_prefix=wine_prefix)) path_mono_msi = pathlib.Path(mono_msi_filename) return path_mono_msi
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 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 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 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 download_python_exe_file( python_version: str, wine_prefix: Union[str, pathlib.Path], username: str = configmagick_linux.get_current_username(), force_download: bool = False) -> None: """ Downloads the Python Exe File to the WineCache directory >>> install_wine_machine.create_wine_test_prefixes() >>> wine_prefix = configmagick_linux.get_path_home_dir_current_user() / 'wine_test_32' >>> wine_arch = lib_wine.get_wine_arch_from_wine_prefix(wine_prefix=wine_prefix) >>> username = configmagick_linux.get_current_username() >>> python_version = get_latest_python_version() >>> path_python_filename = get_path_python_exe_filename(version=python_version, arch=wine_arch) >>> path_downloaded_file = configmagick_linux.get_path_home_dir_current_user() / '.cache/wine' / path_python_filename >>> if path_downloaded_file.is_file(): ... path_downloaded_file.unlink() >>> download_python_exe_file(python_version=python_version, wine_prefix=wine_prefix, username=username, force_download=True) >>> assert path_downloaded_file.is_file() >>> download_python_exe_file(python_version=python_version, wine_prefix=wine_prefix, username=username, force_download=False) >>> assert path_downloaded_file.is_file() >>> wine_prefix = configmagick_linux.get_path_home_dir_current_user() / 'wine_test_64' >>> wine_arch = lib_wine.get_wine_arch_from_wine_prefix(wine_prefix=wine_prefix) >>> python_version = get_latest_python_version() >>> path_python_filename = get_path_python_exe_filename(version=python_version, arch=wine_arch) >>> path_downloaded_file = configmagick_linux.get_path_home_dir_current_user() / '.cache/wine' / path_python_filename >>> if path_downloaded_file.is_file(): ... path_downloaded_file.unlink() >>> download_python_exe_file(python_version=python_version, wine_prefix=wine_prefix, username=username, force_download=True) >>> assert path_downloaded_file.is_file() >>> download_python_exe_file(python_version=python_version, wine_prefix=wine_prefix, username=username, force_download=False) >>> assert path_downloaded_file.is_file() """ 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) python_download_link = get_python_exe_download_link(version=python_version, arch=wine_arch) python_backup_download_link = get_python_exe_backup_download_link( version=python_version, arch=wine_arch) path_python_filename = get_path_python_exe_filename(version=python_version, arch=wine_arch) if lib_wine.is_file_in_wine_cache(filename=path_python_filename, username=username) or force_download: if force_download: lib_wine.remove_file_from_winecache(filename=path_python_filename, username=username) else: return try: lib_wine.download_file_to_winecache(download_link=python_download_link, filename=path_python_filename, username=username) except subprocess.CalledProcessError: lib_wine.download_file_to_winecache( download_link=python_backup_download_link, filename=path_python_filename, username=username)
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))
def create_wine_cache_for_user(username: str = configmagick_linux.get_current_username()) -> None: path_wine_cache = get_path_wine_cache_for_user(username=username) if not path_wine_cache.is_dir(): lib_shell.run_shell_command('mkdir -p {path_wine_cache}'.format(path_wine_cache=path_wine_cache), quiet=True, use_sudo=True) fix_permissions_winecache(username=username)
def get_path_wine_cache_for_user(username: str = configmagick_linux.get_current_username()) -> pathlib.Path: path_user_home = configmagick_linux.get_path_home_dir_user(username=username) path_wine_cache = path_user_home / '.cache/wine' return pathlib.Path(path_wine_cache)