qmm.filehandler module

exception qmm.filehandler.ArchiveException[source]

Bases: Exception

class qmm.filehandler.ArchiveInstance(archive_name, file_list)[source]

Bases: qmm.ab.archives.ABCArchiveInstance

Represent an archive and its content already analyzed and ready for display.

ar_type = 1
conflicts()[source]

Yield FileMetadata of conflicting entries of the archive.

ignored()[source]

Yield file metadata of ignored entries of the archive.

install_info()[source]

Return a several lists useful to the installation process.

The content in matched and ignored key will be compiled into a set of exclude flags, whereas the content of mismatched key will be overridden.

known_conflictors()[source]
matched()[source]

Yield file metadata of matched entries of the archive.

mismatched()[source]

Yield file metadata of mismatched entries of the archive.

missing()[source]

Yield file metadata of missing entries of the archive.

reset_conflicts()[source]

Generate a list of conflicting files, either from in the game folders or in other archives, for each file present in this archive.

uninstall_info()[source]

Informations necessary to the uninstall function.

class qmm.filehandler.ArchivesCollection[source]

Bases: MutableMapping[str, qmm.filehandler.ArchiveInstance]

Manage sets of ArchiveInstance.

add_archive(path, hashsum: Optional[str] = None, progress=None)[source]

Add an archive to the list of managed archives.

This method should be used over __setitem__ as it setup the different metadata required by the UI.

build_archives_list(progress, rebuild=False)[source]
diff_matched_with_loosefiles()[source]
find(archive_name: Optional[str] = None, hashsum: Optional[str] = None)[source]

Find a member based on the name or hashsum of the archive.

If archiveName is not None, will check if archiveName exists in the keys of the collection. If hashsum is not None, will check if the value exists in the self._hashsums dict. If all checks fails, returns False.

Parameters
  • archive_name – filename of the archive, suffix included (default None)

  • hashsum – sha256sum of the file (default None)

Returns

Boolean or ArchiveInstance

hashsums(key)[source]
initiate_conflicts_detection()[source]
refresh() Iterable[Tuple[int, str]][source]

Scan the local repository to add or remove archives as needed.

This is a companion method to use with WatchDog whenever something changes on the filesystem.

Yields

(Union[ArchiveEvents.FILE_ADDED, ArchiveEvents.FILE_REMOVED], str) – State and name of the file.

rename_archive(src_path, dest_path)[source]

Rename the key pointing to an archive.

Whenever an archive on the drive gets renamed, we need to do the same with the key under which the parsed data is stored.

property special
stat(key)[source]
class qmm.filehandler.VirtualArchiveInstance(file_list)[source]

Bases: qmm.ab.archives.ABCArchiveInstance

ar_type = 2
conflicts()[source]

Yield FileMetadata of conflicting entries of the archive.

ignored()[source]

Yield file metadata of ignored entries of the archive.

install_info()[source]
matched()[source]

Yield file metadata of matched entries of the archive.

mismatched()[source]

Yield file metadata of mismatched entries of the archive.

missing()[source]

Yield file metadata of missing entries of the archive.

reset_conflicts()[source]
uninstall_info()[source]

Informations necessary to the uninstall function.

qmm.filehandler.build_cmd(filepath, *ext, extract=True, output=None, **extra)[source]
qmm.filehandler.build_game_files_crc32(progress=None)[source]

Compute the CRC32 value of all the game files then add them to a bucket.

The paths returned by this function are non-existent due to a difference between the mods and the game folder structure. It is needed to be that way in order to compare the mod files with the existing game files.

Parameters

progress (progress()) – Callback to a method accepting strings as argument.

qmm.filehandler.build_loose_files_crc32(progress=None)[source]

Build the CRC32 value of all loose files.

Parameters

progress (progress()) – Callback to a method accepting strings as argument.

qmm.filehandler.conflicts_process_files(files, archives_list, current_archive, processed)[source]

Process an archive, verify that each of its files are unique.

Parameters
  • files (files()) – Process the files fed by the instance method.

  • archives_list (ArchivesCollection) – Instance of ArchivesCollection.

  • current_archive (str) – Filename on the disk of the current archive being processed.

  • processed (list or None) – List of processed archives. Set to None if only one archive needs to be processed.

qmm.filehandler.copy_archive_to_repository(filename)[source]

Copy an archive to the manager’s repository.

qmm.filehandler.delete_archive(filepath)[source]

Delete an archive from the filesystem.

qmm.filehandler.extract7z(file_archive: pathlib.Path, output_path: pathlib.Path, exclude_list=None, progress=None) Union[List[qmm.bucket.FileMetadata], bool][source]
qmm.filehandler.file_in_other_archives(file: qmm.bucket.FileMetadata, archives: qmm.filehandler.ArchivesCollection, ignore: Optional[List]) List[source]

Search for existence of file in other archives.

Parameters
  • file (FileMetadata) – file to be found

  • archives (ArchivesCollection) – instance of ArchivesCollection

  • ignore (list) – list of archives to ignore, for example already parsed archives

Returns

List of archives containing the same file.

Return type

List

qmm.filehandler.generate_conflicts_between_archives(archives_lists: qmm.filehandler.ArchivesCollection, progress=None)[source]
qmm.filehandler.get_mod_folder(with_file: Optional[str] = None) pathlib.Path[source]

Return the path to the game folder.

Parameters

with_file – append ‘with_file’ to the path

Returns

PathLike structure representing the game folder.

qmm.filehandler.install_archive(file_to_extract: str, file_context: Dict[str, List[qmm.bucket.FileMetadata]]) Union[bool, List[qmm.bucket.FileMetadata]][source]

Install the content of an archive into the game mod folder.

Parameters
  • file_to_extract (str) – path to the archive to extract.

  • file_context (dict) –

    A dict containing the keys matched, mismatched, ignored. Each of these entries point to a list containing FileMetadata objects.

    The content in matched and ignored key will be compiled into a set of exclude flags, whereas the content of mismatched key will be overridden. See ArchiveInstance.install_info()

Returns

Output of function extract7z() or False

qmm.filehandler.list7z(file_path: Union[str, pathlib.Path], progress=None) List[qmm.bucket.FileMetadata][source]
qmm.filehandler.reErrorMatch(string, pos=0, endpos=9223372036854775807)

Matches zero or more characters at the beginning of the string.

qmm.filehandler.reExtractMatch(string, pos=0, endpos=9223372036854775807)

Matches zero or more characters at the beginning of the string.

qmm.filehandler.reListMatch(string, pos=0, endpos=9223372036854775807)

Matches zero or more characters at the beginning of the string.

qmm.filehandler.sha256hash(filename: Union[IO, str, os.PathLike]) Optional[str][source]

Return the 256 hash of the managed archive.

Parameters

filename – path to the file to hash

Returns

a string if successful, otherwise None

Return type

str or None

qmm.filehandler.uninstall_files(file_list: List[qmm.bucket.FileMetadata], progress, maximum)[source]

Removes a list of files and directory from the filesystem.

Parameters
  • file_list (list[FileMetadata]) – FileMetadata objects are required in order extract necessary information pertaining to the archive we want to uninstall.

  • progress (QProgressDialog) – Used to granually inform the user about the uninstallation progress.

  • maximum (int) – Maximum amount of steps allocated for the archive. Pertain to the progress widget.

Returns

True on success, False if an error occurred during the deleting process.

Return type

bool

Notes

Any error will be logged silently to the application configured facility.