qmm.filehandler module¶
- class qmm.filehandler.ArchiveInstance(archive_name, file_list)[source]¶
Bases:
ABCArchiveInstanceRepresent an archive and its content already analyzed and ready for display.
- ar_type = 1¶
- 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.
See also
- class qmm.filehandler.ArchivesCollection[source]¶
Bases:
MutableMapping[str,ArchiveInstance]Manage sets of
ArchiveInstance.- add_archive(path, hashsum: 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.
- find(archive_name: str = None, hashsum: 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
- 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¶
- class qmm.filehandler.VirtualArchiveInstance(file_list)[source]¶
Bases:
ABCArchiveInstance- ar_type = 2¶
- 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.extract7z(file_archive: Path, output_path: Path, exclude_list=None, progress=None) List[FileMetadata] | bool[source]¶
- qmm.filehandler.file_in_other_archives(file: FileMetadata, archives: ArchivesCollection, ignore: List | None) 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: ArchivesCollection, progress=None)[source]¶
- qmm.filehandler.get_mod_folder(with_file: str = None) 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[FileMetadata]]) bool | List[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
FileMetadataobjects.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()orFalse
- 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: IO | str | PathLike) str | None[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[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
progresswidget.
- Returns:
Trueon success,Falseif an error occurred during the deleting process.- Return type:
Notes
Any error will be logged silently to the application configured facility.