Esempio n. 1
0
def migrate():
    for dirname in os.listdir(RUNNER_DIR):
        path = os.path.join(RUNNER_DIR, dirname)
        if not os.path.isdir(path):
            return
        if dirname in [
                "atari800",
                "dgen",
                "dolphin",
                "dosbox",
                "frotz",
                "fs-uae",
                "gens",
                "hatari",
                "jzintv",
                "mame",
                "mednafen",
                "mess",
                "mupen64plus",
                "nulldc",
                "o2em",
                "osmose",
                "reicast",
                "ResidualVM",
                "residualvm",
                "scummvm",
                "snes9x",
                "stella",
                "vice",
                "virtualjaguar",
                "zdoom",
        ]:
            system.remove_folder(path)
Esempio n. 2
0
def update_runtime(set_status):
    logger.debug("Updating runtime")
    remote_version = get_remote_version()
    local_version = get_local_version()
    if remote_version <= local_version:
        logger.debug("Runtime already up to date")
        return
    runtime32_file = "lutris-runtime-i386.tar.gz"
    runtime64_file = "lutris-runtime-amd64.tar.gz"

    set_status("Updating Runtime")
    runtime32_path = os.path.join(settings.RUNTIME_DIR, runtime32_file)
    http.download_asset(settings.RUNTIME_URL + runtime32_file, runtime32_path,
                        overwrite=True)
    runtime64_path = os.path.join(settings.RUNTIME_DIR, runtime64_file)
    http.download_asset(settings.RUNTIME_URL + runtime64_file, runtime64_path,
                        overwrite=True)
    system.remove_folder(os.path.join(settings.RUNTIME_DIR, 'lib32'))
    system.remove_folder(os.path.join(settings.RUNTIME_DIR, 'lib64'))
    extract.extract_archive(runtime32_path, settings.RUNTIME_DIR,
                            merge_single=False)
    extract.extract_archive(runtime64_path, settings.RUNTIME_DIR,
                            merge_single=False)
    os.unlink(runtime32_path)
    os.unlink(runtime64_path)

    with open(LOCAL_VERSION_PATH, 'w') as version_file:
        version_file.write(str(remote_version))
    set_status("Runtime updated")
    logger.debug("Runtime updated")
Esempio n. 3
0
    def on_downloaded(self, path):
        """Actions taken once a runtime is downloaded

        Arguments:
            path (str): local path to the runtime archive
        """
        stats = os.stat(path)
        if not stats.st_size:
            logger.error("Download failed: file %s is empty, Deleting file.",
                         path)
            os.unlink(path)
            self.updater.notify_finish(self)
            return False
        directory, _filename = os.path.split(path)

        # Delete the existing runtime path
        initial_path = os.path.join(directory, self.name)
        system.remove_folder(initial_path)

        # Extract the runtime archive
        jobs.AsyncCall(extract_archive,
                       self.on_extracted,
                       path,
                       settings.RUNTIME_DIR,
                       merge_single=False)
        return False
Esempio n. 4
0
def extract_archive(path, to_directory='.', merge_single=True, extractor=None):
    path = os.path.abspath(path)
    mode = None
    logger.debug("Extracting %s to %s", path, to_directory)

    if path.endswith('.tar.gz') or path.endswith('.tgz') or extractor == 'tgz':
        opener, mode = tarfile.open, 'r:gz'
    elif path.endswith('.tar.xz') or path.endswith(
            '.txz') or extractor == 'txz':
        opener, mode = tarfile.open, 'r:xz'
    elif path.endswith('.tar') or extractor == 'tar':
        opener, mode = tarfile.open, 'r:'
    elif path.endswith('.gz') or extractor == 'gzip':
        decompress_gz(path, to_directory)
        return
    elif (path.endswith('.tar.bz2') or path.endswith('.tbz')
          or extractor == 'bz2'):
        opener, mode = tarfile.open, 'r:bz2'
    elif is_7zip_supported(path, extractor):
        opener = '7zip'
    else:
        raise RuntimeError(
            "Could not extract `%s` as no appropriate extractor is found" %
            path)
    temp_name = ".extract-" + str(uuid.uuid4())[:8]
    temp_path = temp_dir = os.path.join(to_directory, temp_name)
    _do_extract(path, temp_path, opener, mode, extractor)
    if merge_single:
        extracted = os.listdir(temp_path)
        if len(extracted) == 1:
            temp_path = os.path.join(temp_path, extracted[0])

    if os.path.isfile(temp_path):
        destination_path = os.path.join(to_directory, extracted[0])
        if os.path.isfile(destination_path):
            logger.warning("Overwrite existing file %s", destination_path)
            os.remove(destination_path)
        shutil.move(temp_path, to_directory)
        os.removedirs(temp_dir)
    else:
        for archive_file in os.listdir(temp_path):
            source_path = os.path.join(temp_path, archive_file)
            destination_path = os.path.join(to_directory, archive_file)
            logger.debug("Moving extracted files from %s to %s", source_path,
                         destination_path)

            if os.path.exists(destination_path):
                logger.warning("Overwrite existing path %s", destination_path)
                if os.path.isfile(destination_path):
                    os.remove(destination_path)
                    shutil.move(source_path, destination_path)
                elif os.path.isdir(destination_path):
                    system.merge_folders(source_path, destination_path)
            else:
                shutil.move(source_path, destination_path)
        system.remove_folder(temp_dir)
    logger.debug("Finished extracting %s", path)
    return path, to_directory
Esempio n. 5
0
 def on_downloaded(self, path):
     dir, filename = os.path.split(path)
     folder = os.path.join(dir, filename[:filename.find('.')])
     system.remove_folder(folder)
     jobs.AsyncCall(extract_archive,
                    self.on_extracted,
                    path,
                    RUNTIME_DIR,
                    merge_single=False)
Esempio n. 6
0
 def uninstall_runner(self, row):
     version = row[self.COL_VER]
     arch = row[self.COL_ARCH]
     system.remove_folder(self.get_runner_path(version, arch))
     row[self.COL_INSTALLED] = False
     if self.runner == "wine":
         logger.debug("Clearing wine version cache")
         from lutris.util.wine.wine import get_wine_versions
         get_wine_versions.cache_clear()
Esempio n. 7
0
    def revert(self):
        logger.debug("Install cancelled")
        self.cancelled = True

        if self.abort_current_task:
            self.abort_current_task()

        if self.reversion_data.get('created_main_dir'):
            system.remove_folder(self.target_path)
Esempio n. 8
0
def extract_archive(path, to_directory=".", merge_single=True, extractor=None):
    path = os.path.abspath(path)
    logger.debug("Extracting %s to %s", path, to_directory)

    if extractor is None:
        extractor = guess_extractor(path)

    opener, mode = get_archive_opener(extractor, path)

    temp_name = ".extract-" + random_id()
    temp_path = temp_dir = os.path.join(to_directory, temp_name)
    try:
        _do_extract(path, temp_path, opener, mode, extractor)
    except (OSError, zlib.error, tarfile.ReadError, EOFError) as ex:
        logger.error("Extraction failed: %s", ex)
        raise ExtractFailure(str(ex))
    if merge_single:
        extracted = os.listdir(temp_path)
        if len(extracted) == 1:
            temp_path = os.path.join(temp_path, extracted[0])

    if os.path.isfile(temp_path):
        destination_path = os.path.join(to_directory, extracted[0])
        if os.path.isfile(destination_path):
            logger.warning("Overwrite existing file %s", destination_path)
            os.remove(destination_path)
        if os.path.isdir(destination_path):
            os.rename(destination_path, destination_path + random_id())

        shutil.move(temp_path, to_directory)
        os.removedirs(temp_dir)
    else:
        for archive_file in os.listdir(temp_path):
            source_path = os.path.join(temp_path, archive_file)
            destination_path = os.path.join(to_directory, archive_file)
            # logger.debug("Moving extracted files from %s to %s", source_path, destination_path)

            if system.path_exists(destination_path):
                logger.warning("Overwrite existing path %s", destination_path)
                if os.path.isfile(destination_path):
                    os.remove(destination_path)
                    shutil.move(source_path, destination_path)
                elif os.path.isdir(destination_path):
                    try:
                        system.merge_folders(source_path, destination_path)
                    except OSError as ex:
                        logger.error(
                            "Failed to merge to destination %s: %s",
                            destination_path,
                            ex,
                        )
                        raise ExtractFailure(str(ex))
            else:
                shutil.move(source_path, destination_path)
        system.remove_folder(temp_dir)
    logger.debug("Finished extracting %s to %s", path, to_directory)
    return path, to_directory
Esempio n. 9
0
    def revert(self):
        """Revert installation in case of an error"""
        logger.debug("Install cancelled")
        self.cancelled = True

        if self.abort_current_task:
            self.abort_current_task()

        if self.game_dir_created:
            system.remove_folder(self.target_path)
Esempio n. 10
0
    def revert(self):
        """Revert installation in case of an error"""
        logger.debug("Install cancelled")
        self.cancelled = True

        if self.abort_current_task:
            self.abort_current_task()

        if self.game_dir_created:
            system.remove_folder(self.target_path)
Esempio n. 11
0
    def revert(self):
        """Revert installation in case of an error"""
        logger.info("Cancelling installation of %s", self.game_name)
        self.cancelled = True

        if self.abort_current_task:
            self.abort_current_task()

        if self.game_dir_created:
            system.remove_folder(self.target_path)
Esempio n. 12
0
def migrate():
    for dirname in os.listdir(RUNNER_DIR):
        path = os.path.join(RUNNER_DIR, dirname)
        if not os.path.isdir(path):
            return
        if dirname in ['atari800', 'dgen', 'dolphin', 'dosbox', 'frotz', 'fs-uae',
                       'gens', 'hatari', 'jzintv', 'mame', 'mednafen', 'mess',
                       'mupen64plus', 'nulldc', 'o2em', 'osmose',
                       'reicast', 'ResidualVM', 'residualvm', 'scummvm',
                       'snes9x', 'stella', 'vice', 'virtualjaguar', 'zdoom']:
            system.remove_folder(path)
Esempio n. 13
0
    def wine_runner_uninstall(self, version):
        version = f"{version}{'' if '-x86_64' in version else '-x86_64'}"
        WINE_DIR = os.path.join(settings.RUNNER_DIR, "wine")
        runner_path = os.path.join(WINE_DIR, version)
        if os.path.isdir(runner_path):
            system.remove_folder(runner_path)
            print(f"Wine version '{version}' has been removed.")
        else:
            print(f"""
Specified version of Wine is not installed: {version}.
Please check if the Wine Runner and specified version are installed (for that use --list-wine-runners).
Also, check that the version specified is in the correct format.
                """)
Esempio n. 14
0
    def revert(self, remove_game_dir=True):
        """Revert installation in case of an error"""
        logger.info("Cancelling installation of %s", self.installer.game_name)
        if self.installer.runner.startswith("wine"):
            self.task({"name": "winekill"})

        self.cancelled = True

        if self.abort_current_task:
            self.abort_current_task()

        if self.target_path and remove_game_dir:
            system.remove_folder(self.target_path)
Esempio n. 15
0
    def on_downloaded(self, path):
        """Actions taken once a runtime is downloaded

        Arguments:
            path (str): local path to the runtime archive
        """
        directory, _filename = os.path.split(path)

        # Delete the existing runtime path
        initial_path = os.path.join(directory, self.name)
        system.remove_folder(initial_path)

        # Extract the runtime archive
        jobs.AsyncCall(extract_archive, self.on_extracted, path, RUNTIME_DIR, merge_single=False)
        return False
Esempio n. 16
0
def update_runtime(set_status):
    logger.debug("Updating runtime")
    remote_version = get_remote_version()
    local_version = get_local_version()
    if remote_version <= local_version:
        logger.debug("Runtime already up to date")
        return
    runtime32_file = "steam-runtime_32.tar.gz"
    runtime64_file = "steam-runtime_64.tar.gz"

    # Download
    set_status("Updating Runtime")
    runtime32_path = os.path.join(RUNTIME_DIR, runtime32_file)
    http.download_asset(RUNTIME_URL + runtime32_file, runtime32_path,
                        overwrite=True)
    runtime64_path = os.path.join(RUNTIME_DIR, runtime64_file)
    http.download_asset(RUNTIME_URL + runtime64_file, runtime64_path,
                        overwrite=True)
    # Remove current
    system.remove_folder(os.path.join(RUNTIME_DIR, 'steam'))
    # Remove legacy folders
    system.remove_folder(os.path.join(RUNTIME_DIR, 'lib32'))
    system.remove_folder(os.path.join(RUNTIME_DIR, 'lib64'))

    # Extract
    extract.extract_archive(runtime32_path, RUNTIME_DIR,
                            merge_single=False)
    extract.extract_archive(runtime64_path, RUNTIME_DIR,
                            merge_single=False)
    os.unlink(runtime32_path)
    os.unlink(runtime64_path)

    with open(LOCAL_VERSION_PATH, 'w') as version_file:
        version_file.write(str(remote_version))
    set_status("Runtime updated")
    logger.debug("Runtime updated")
Esempio n. 17
0
 def uninstall(self):
     runner_path = os.path.join(settings.RUNNER_DIR, self.name)
     if os.path.isdir(runner_path):
         system.remove_folder(runner_path)
Esempio n. 18
0
 def remove_game_data(game_path=None):
     system.remove_folder(game_path)
Esempio n. 19
0
 def on_downloaded(self, path):
     dir, filename = os.path.split(path)
     folder = os.path.join(dir, filename[:filename.find('.')])
     system.remove_folder(folder)
     jobs.AsyncCall(extract_archive, self.on_extracted, path, RUNTIME_DIR,
                    merge_single=False)
Esempio n. 20
0
 def uninstall_runner(self, row):
     version = row[self.COL_VER]
     arch = row[self.COL_ARCH]
     system.remove_folder(self.get_runner_path(version, arch))
     row[self.COL_INSTALLED] = False
Esempio n. 21
0
 def cleanup(self):
     """Clean up install dir after a successful install"""
     os.chdir(os.path.expanduser("~"))
     system.remove_folder(self.cache_path)
Esempio n. 22
0
 def uninstall(self):
     runner_path = os.path.join(settings.RUNNER_DIR, self.name)
     if os.path.isdir(runner_path):
         system.remove_folder(runner_path)
Esempio n. 23
0
 def cleanup(self):
     """Clean up install dir after a successful install"""
     os.chdir(os.path.expanduser("~"))
     system.remove_folder(self.cache_path)
Esempio n. 24
0
 def uninstall_runner(self, row):
     version = row[self.COL_VER]
     arch = row[self.COL_ARCH]
     system.remove_folder(self.get_runner_path(version, arch))
     row[self.COL_INSTALLED] = False
Esempio n. 25
0
 def uninstall_runner(self, path):
     row = self.runner_store[path]
     version = row[self.COL_VER]
     arch = row[self.COL_ARCH]
     system.remove_folder(self.get_runner_path(version, arch))
     row[self.COL_INSTALLED] = False
Esempio n. 26
0
 def uninstall(self):
     retroarch_path = os.path.join(settings.RUNNER_DIR, 'retroarch')
     if os.path.isdir(retroarch_path):
         system.remove_folder(retroarch_path)
     super(libretro, self).uninstall()
Esempio n. 27
0
def extract_archive(path, to_directory=".", merge_single=True, extractor=None):
    path = os.path.abspath(path)
    mode = None
    logger.debug("Extracting %s to %s", path, to_directory)

    if path.endswith(".tar.gz") or path.endswith(".tgz") or extractor == "tgz":
        opener, mode = tarfile.open, "r:gz"
    elif path.endswith(".tar.xz") or path.endswith(
            ".txz") or extractor == "txz":
        opener, mode = tarfile.open, "r:xz"
    elif path.endswith(".tar") or extractor == "tar":
        opener, mode = tarfile.open, "r:"
    elif path.endswith(".gz") or extractor == "gzip":
        decompress_gz(path, to_directory)
        return
    elif path.endswith(".tar.bz2") or path.endswith(
            ".tbz") or extractor == "bz2":
        opener, mode = tarfile.open, "r:bz2"
    elif is_7zip_supported(path, extractor):
        opener = "7zip"
    else:
        raise RuntimeError(
            "Could not extract `%s` as no appropriate extractor is found" %
            path)
    temp_name = ".extract-" + str(uuid.uuid4())[:8]
    temp_path = temp_dir = os.path.join(to_directory, temp_name)
    try:
        _do_extract(path, temp_path, opener, mode, extractor)
    except (OSError, zlib.error) as ex:
        logger.exception("Extraction failed: %s", ex)
        raise ExtractFailure(str(ex))
    if merge_single:
        extracted = os.listdir(temp_path)
        if len(extracted) == 1:
            temp_path = os.path.join(temp_path, extracted[0])

    if os.path.isfile(temp_path):
        destination_path = os.path.join(to_directory, extracted[0])
        if os.path.isfile(destination_path):
            logger.warning("Overwrite existing file %s", destination_path)
            os.remove(destination_path)
        shutil.move(temp_path, to_directory)
        os.removedirs(temp_dir)
    else:
        for archive_file in os.listdir(temp_path):
            source_path = os.path.join(temp_path, archive_file)
            destination_path = os.path.join(to_directory, archive_file)
            # logger.debug("Moving extracted files from %s to %s", source_path, destination_path)

            if system.path_exists(destination_path):
                logger.warning("Overwrite existing path %s", destination_path)
                if os.path.isfile(destination_path):
                    os.remove(destination_path)
                    shutil.move(source_path, destination_path)
                elif os.path.isdir(destination_path):
                    try:
                        system.merge_folders(source_path, destination_path)
                    except OSError as ex:
                        logger.error("Failed to merge to destination %s: %s",
                                     destination_path, ex)
                        raise ExtractFailure(str(ex))
            else:
                shutil.move(source_path, destination_path)
        system.remove_folder(temp_dir)
    logger.debug("Finished extracting %s to %s", path, to_directory)
    return path, to_directory
Esempio n. 28
0
 def cleanup(self):
     os.chdir(os.path.expanduser('~'))
     system.remove_folder(self.cache_path)
Esempio n. 29
0
 def uninstall(self):
     retroarch_path = os.path.join(settings.RUNNER_DIR, 'retroarch')
     if os.path.isdir(retroarch_path):
         system.remove_folder(retroarch_path)
     super(libretro, self).uninstall()
Esempio n. 30
0
def extract_archive(path, to_directory=".", merge_single=True, extractor=None):  # noqa: C901
    # pylint: disable=too-many-branches,too-many-statements
    # TODO: split into multiple methods to reduce complexity (30)
    path = os.path.abspath(path)
    mode = None
    logger.debug("Extracting %s to %s", path, to_directory)

    if extractor is None:
        if path.endswith(".tar.gz") or path.endswith(".tgz"):
            extractor = "tgz"
        elif path.endswith(".tar.xz") or path.endswith(".txz"):
            extractor = "txz"
        elif path.endswith(".tar"):
            extractor = "tar"
        elif path.endswith(".tar.bz2") or path.endswith(".tbz"):
            extractor = "bz2"
        elif path.endswith(".gz"):
            extractor = "gzip"
        elif path.endswith(".exe"):
            extractor = "exe"
        elif is_7zip_supported(path, None):
            extractor = None
        else:
            raise RuntimeError("Could not extract `%s` - no appropriate extractor found" % path)

    if extractor == "tgz":
        opener, mode = tarfile.open, "r:gz"
    elif extractor == "txz":
        opener, mode = tarfile.open, "r:xz"
    elif extractor == "tar":
        opener, mode = tarfile.open, "r:"
    elif extractor == "bz2":
        opener, mode = tarfile.open, "r:bz2"
    elif extractor == "gzip":
        decompress_gz(path, to_directory)
        return
    elif extractor == "gog":
        opener = "innoextract"
    elif extractor == "exe":
        opener = "exe"
    elif extractor is None or is_7zip_supported(path, extractor):
        opener = "7zip"
    else:
        raise RuntimeError("Could not extract `%s` - unknown format specified" % path)

    temp_name = ".extract-" + random_id()
    temp_path = temp_dir = os.path.join(to_directory, temp_name)
    try:
        _do_extract(path, temp_path, opener, mode, extractor)
    except (OSError, zlib.error, tarfile.ReadError, EOFError) as ex:
        logger.error("Extraction failed: %s", ex)
        raise ExtractFailure(str(ex))
    if merge_single:
        extracted = os.listdir(temp_path)
        if len(extracted) == 1:
            temp_path = os.path.join(temp_path, extracted[0])

    if os.path.isfile(temp_path):
        destination_path = os.path.join(to_directory, extracted[0])
        if os.path.isfile(destination_path):
            logger.warning("Overwrite existing file %s", destination_path)
            os.remove(destination_path)
        if os.path.isdir(destination_path):
            os.rename(destination_path, destination_path + random_id())

        shutil.move(temp_path, to_directory)
        os.removedirs(temp_dir)
    else:
        for archive_file in os.listdir(temp_path):
            source_path = os.path.join(temp_path, archive_file)
            destination_path = os.path.join(to_directory, archive_file)
            # logger.debug("Moving extracted files from %s to %s", source_path, destination_path)

            if system.path_exists(destination_path):
                logger.warning("Overwrite existing path %s", destination_path)
                if os.path.isfile(destination_path):
                    os.remove(destination_path)
                    shutil.move(source_path, destination_path)
                elif os.path.isdir(destination_path):
                    try:
                        system.merge_folders(source_path, destination_path)
                    except OSError as ex:
                        logger.error(
                            "Failed to merge to destination %s: %s",
                            destination_path,
                            ex,
                        )
                        raise ExtractFailure(str(ex))
            else:
                shutil.move(source_path, destination_path)
        system.remove_folder(temp_dir)
    logger.debug("Finished extracting %s to %s", path, to_directory)
    return path, to_directory
Esempio n. 31
0
 def remove_game_data(game_path=None):
     system.remove_folder(game_path)