def full_update_and_upgrade(quiet: bool = False) -> None: lib_shell.run_shell_command( '{apt_command} update'.format(apt_command=conf_install.apt_command), use_sudo=True, shell=True, pass_stdout_stderr_to_sys=True, quiet=quiet) lib_shell.run_shell_command('{apt_command} upgrade -y'.format( apt_command=conf_install.apt_command), use_sudo=True, shell=True, pass_stdout_stderr_to_sys=True, quiet=quiet) lib_shell.run_shell_command('{apt_command} dist-upgrade -y'.format( apt_command=conf_install.apt_command), use_sudo=True, shell=True, pass_stdout_stderr_to_sys=True, quiet=quiet) lib_shell.run_shell_command('{apt_command} autoclean -y'.format( apt_command=conf_install.apt_command), use_sudo=True, shell=True, pass_stdout_stderr_to_sys=True, quiet=quiet) lib_shell.run_shell_command('{apt_command} autoremove -y'.format( apt_command=conf_install.apt_command), use_sudo=True, shell=True, pass_stdout_stderr_to_sys=True, quiet=quiet)
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 add_wine_key(linux_release_name: str, quiet: bool = False) -> None: """ >>> add_wine_key(configmagick_linux.get_linux_release_name(), quiet=True) """ lib_log_utils.log_verbose( 'Add Wine Key and Repository, linux_release_name="{linux_release_name}"' .format(linux_release_name=linux_release_name), quiet=quiet) lib_shell.run_shell_command('rm -f ./winehq.key*', shell=True, use_sudo=True, quiet=quiet) lib_shell.run_shell_command( 'wget -nv -c https://dl.winehq.org/wine-builds/winehq.key', use_sudo=True, quiet=quiet) lib_shell.run_shell_command('apt-key add winehq.key', use_sudo=True, quiet=quiet) lib_shell.run_shell_command('rm -f ./winehq.key*', shell=True, use_sudo=True, quiet=quiet) lib_shell.run_shell_command( 'apt-add-repository "deb https://dl.winehq.org/wine-builds/ubuntu/ {linux_release_name} main"' .format(linux_release_name=linux_release_name), use_sudo=True, pass_stdout_stderr_to_sys=True, quiet=quiet)
def ping_darwin_ipv4(target: str, times: int) -> lib_shell.ShellCommandResponse: """ >>> if lib_platform.is_platform_darwin: ... response = ping_darwin_ipv4(target='1.1.1.1', times=1) ... assert response.stdout is not None >>> if lib_platform.is_platform_darwin: ... response = ping_darwin_ipv4(target='1.1.1.1', times=10) ... assert response.stdout is not None """ # ping -i parameter decimal sign can be different (0.2 or 0,2) on different linux versions try: cmd = 'ping -c {times} -W2000 -i 0.2 {target}'.format(times=times, target=target) response = lib_shell.run_shell_command( command=cmd, shell=True, log_settings=lib_shell.conf_lib_shell.log_settings_qquiet, retries=1) except subprocess.CalledProcessError: cmd = 'ping -c {times} -W2000 -i 0,2 {target}'.format(times=times, target=target) response = lib_shell.run_shell_command( command=cmd, shell=True, log_settings=lib_shell.conf_lib_shell.log_settings_qquiet, retries=1) return response
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 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 force_remove_directory_recursive( path_to_remove: Union[pathlib.Path, str]) -> None: path_to_remove = pathlib.Path(path_to_remove) lib_shell.run_shell_command( 'rm -Rf "{path_to_remove}"'.format(path_to_remove=path_to_remove), quiet=True, use_sudo=True, shell=True) if path_to_remove.exists(): raise RuntimeError('path "{path_to_remove}" can not be removed'.format( path_to_remove=path_to_remove))
def fix_wine_permissions(wine_prefix: Union[str, pathlib.Path], username: str) -> None: wine_prefix = get_and_check_wine_prefix(wine_prefix, username) # prepend /home/user if needed if wine_prefix.exists(): lib_shell.run_shell_command('chown -R "{username}"."{username}" "{wine_prefix}"' .format(username=username, wine_prefix=wine_prefix), quiet=True, use_sudo=True) lib_shell.run_shell_command('chmod -R 0775 "{wine_prefix}"' .format(wine_prefix=wine_prefix), quiet=True, use_sudo=True) fix_permissions_winecache(username=username)
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 download_file(download_link: str, filename: pathlib.Path, quiet: bool = True, use_sudo: bool = False) -> None: lib_shell.run_shell_command( 'wget -nv -c --no-check-certificate -O "{filename}" "{download_link}"'. format(filename=filename, download_link=download_link), quiet=quiet, use_sudo=use_sudo) if not filename.exists(): raise RuntimeError( 'File "{filename}" can not be downloaded from "{download_link}"'. format(filename=filename, download_link=download_link))
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 ping_windows_ipv6(target: str) -> lib_shell.ShellCommandResponse: cmd = 'ping -w 2000 ' + target response = lib_shell.run_shell_command( command=cmd, shell=True, log_settings=lib_shell.conf_lib_shell.log_settings_qquiet, retries=1) return response
def get_linux_release_name() -> str: """ >>> assert get_linux_release_name() is not None """ linux_release_name = lib_shell.run_shell_command('lsb_release -c -s', quiet=True).stdout return str(linux_release_name)
def install_gecko_by_architecture(wine_prefix: Union[str, pathlib.Path], username: str, path_gecko_msi_filename: pathlib.Path, quiet: bool = False) -> None: path_wine_cache = lib_wine.get_path_wine_cache_for_user(username) wine_arch = lib_wine.get_wine_arch_from_wine_prefix(wine_prefix, username) command = 'WINEPREFIX="{wine_prefix}" WINEARCH="{wine_arch}" wine msiexec /i "{path_wine_cache}/{path_gecko_msi_filename}"'.format( wine_prefix=wine_prefix, wine_arch=wine_arch, path_wine_cache=path_wine_cache, path_gecko_msi_filename=path_gecko_msi_filename) lib_shell.run_shell_command(command, shell=True, run_as_user=username, pass_stdout_stderr_to_sys=True, quiet=quiet)
def get_linux_release_number() -> str: """ returns for instance '18.04' >>> assert '.' in get_linux_release_number() """ release = lib_shell.run_shell_command('lsb_release -r -s', quiet=True).stdout return str(release)
def stop_service(service: str, quiet: bool = False) -> None: """ >>> import unittest >>> unittest.TestCase().assertRaises(RuntimeError, stop_service, service='unknown') """ if not is_service_installed(service=service): raise RuntimeError( 'can not stop service "{service}", because it is not installed'. format(service=service)) if is_service_active(service=service): lib_shell.run_shell_command( command='service {service} stop'.format(service=service), shell=True, use_sudo=True, quiet=quiet) if is_service_active(service=service): raise RuntimeError( 'can not stop service "{service}"'.format(service=service))
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 ping_darwin_ipv6(target: str, times: int) -> lib_shell.ShellCommandResponse: # ping -i parameter decimal sign can be different (0.2 or 0,2) on different linux versions try: cmd = 'ping -6 -c {times} -W2000 -i 0.2 {target}'.format(times=times, target=target) response = lib_shell.run_shell_command( command=cmd, shell=True, log_settings=lib_shell.conf_lib_shell.log_settings_qquiet, retries=1) except subprocess.CalledProcessError: cmd = 'ping -6 -c {times} -W2000 -i 0,2 {target}'.format(times=times, target=target) response = lib_shell.run_shell_command( command=cmd, shell=True, log_settings=lib_shell.conf_lib_shell.log_settings_qquiet, retries=1) return response
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 is_service_installed(service: str) -> bool: """ >>> assert not is_service_installed('unknown') >>> assert is_service_installed('ssh') is not None """ response = lib_shell.run_shell_command( command='systemctl list-units --full -all | fgrep "{service}.service"'. format(service=service), shell=True, raise_on_returncode_not_zero=False, log_settings=lib_shell.conf_lib_shell.log_settings_qquiet) return bool(response.stdout)
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 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 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_winetricks(quiet: bool = False) -> None: lib_log_utils.banner_verbose('Installing Winetricks', quiet=quiet) lib_shell.run_shell_command('rm -f /usr/bin/winetricks', use_sudo=True, quiet=quiet) lib_shell.run_shell_command( 'wget -nv -c --directory-prefix=/usr/bin/ https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks', use_sudo=True, quiet=quiet) lib_shell.run_shell_command('chmod +x /usr/bin/winetricks', use_sudo=True, quiet=quiet) lib_log_utils.banner_success('Winetricks Installation OK', quiet=quiet)
def is_service_active(service: str) -> bool: """ >>> assert not is_service_active('unknown') >>> if is_service_installed('ssh'): ... is_ssh_active = is_service_active('ssh') ... stop_service('ssh') ... assert not is_service_active('ssh') ... start_service('ssh') ... assert is_service_active('ssh') ... if not is_ssh_active: ... stop_service('ssh') """ response = lib_shell.run_shell_command( command='systemctl is-active {service}'.format(service=service), shell=True, log_settings=lib_shell.conf_lib_shell.log_settings_qquiet, raise_on_returncode_not_zero=False) if response.stdout.startswith('active'): return True else: return False
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 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 add_architecture_386(quiet: bool = False) -> None: lib_log_utils.log_verbose('Add 386 Architecture', quiet=quiet) lib_shell.run_shell_command('dpkg --add-architecture i386', use_sudo=True, pass_stdout_stderr_to_sys=True, quiet=quiet)