qmm.filehandler module

exception qmm.filehandler.ArchiveException[source]

Bases: qmm.filehandler.FileHandlerException

class qmm.filehandler.ArchiveInstance(archive_name: str, file_list: List[qmm.bucket.FileMetadata])[source]

Bases: object

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

all_ignored

Value is True if all files of the archive are of status FILE_IGNORED.

all_matching

Return True if all files in the archive matches on the drive.

conflicts()[source]

Yield file metadata of conflicting entries of the archive.

files(exclude_directories=False) → Generator[qmm.bucket.FileMetadata, None, None][source]
folders() → Generator[qmm.bucket.FileMetadata, None, None][source]

Yield folders present in the archive

get_status(file)[source]
has_conflicts

Value is True if conflicts exists for this archive.

has_ignored

Value is True if a file of the archive is of status FILE_IGNORED.

has_matched

Return True if a file of the archive is of status FILE_MATCHED.

has_mismatched

Value is True if a file of the archive is of status FILE_MISMATCHED.

has_missing

Value is True if a file of the archive is of status FILE_MISSING.

ignored() → Iterable[qmm.bucket.FileMetadata][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

matched() → Generator[qmm.bucket.FileMetadata, None, None][source]

Yield file metadata of matched entries of the archive.

mismatched() → Generator[qmm.bucket.FileMetadata, None, None][source]

Yield file metadata of mismatched entries of the archive.

missing() → Generator[qmm.bucket.FileMetadata, None, None][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.

reset_status()[source]

Called whenever the state of an archive becomes dirty, which is also the default state.

Populate ‘self._meta’ with tuples containing the ‘FileMetadata’ object of each individual file alongside the current status of that file. The status can be either ‘FILE_MATCHED’, ‘FILE_MISMATCHED’, ‘FILE_IGNORED’ or ‘FILE_MISSING’.

status() → Generator[Tuple[qmm.bucket.FileMetadata, int], None, None][source]
uninstall_info()[source]

Informations necessary to the uninstall function

class qmm.filehandler.ArchivesCollection[source]

Bases: collections.abc.MutableMapping, typing.Generic

FileAdded = 1

State of a file yielded through refresh()

FileRemoved = 2

State of a file yielded through refresh()

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.

build_archives_list(progress, rebuild=False)[source]
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)
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[FileAdded, FileRemoved], 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.

stat(key)[source]
qmm.filehandler.FILE_IGNORED = 4

Indicate that the file will be ignored by the software.

qmm.filehandler.FILE_MATCHED = 1

Indicate that the file is found on the drive, and match in content.

qmm.filehandler.FILE_MISMATCHED = 3

Indicate that the file to exists on drive, but not matching in content.

qmm.filehandler.FILE_MISSING = 2

Indicate that the file is absent from the drive.

exception qmm.filehandler.FileHandlerException[source]

Bases: Exception

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.

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: List[T]) → List[T][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.file_status(file: qmm.bucket.FileMetadata) → int[source]
qmm.filehandler.generate_conflicts_between_archives(archives_lists: qmm.filehandler.ArchivesCollection, progress=None)[source]
qmm.filehandler.get_mod_folder(with_file: str = None, prepend_modpath=False) → pathlib.Path[source]

Return the path to the game folder.

Parameters:
  • with_file – append ‘with_file’ to the path
  • prepend_modpath – if True, adds the module path before ‘with_file’
Returns:

PathLike structure representing the game folder.

qmm.filehandler.ignore_patterns(seven_flag=False)[source]

Output a tuple of patterns to ignore.

Parameters:seven_flag (bool) – Patterns format following 7z exclude switch.
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()

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

qmm.filehandler.reExtractMatch()

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

qmm.filehandler.reListMatch()

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

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

Returns 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])[source]

Removes a list of files and directory from the filesystem.

Parameters:file_list (list[FileMetadata]) – A list of FileMetadata objects.
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.