io.py

mdpo I/O utilities.

mdpo.io.filehash(filepath)

Compute the hash of a file.

Parameters

filepath (str) – Path to the file.

mdpo.io.filter_paths(filepaths, ignore_paths=[])

Filters a list of paths removing those defined in other list of paths.

The paths to filter can be defined in the list of paths to ignore in several forms:

  • The same string.

  • Only the file name.

  • Only their direct directory name.

  • Their direct directory full path.

Parameters
  • filepaths (list) – Set of source paths to filter.

  • ignore_paths (list) – Paths that must not be included in the response.

Returns

Non filtered paths ordered alphabetically.

Return type

list

mdpo.io.save_file_checking_file_changed(filepath, content, encoding='utf-8')

Save a file checking if the content has changed.

Parameters
  • pofile (polib.POFile) – POFile to save.

  • po_filepath (str) – Path to the new file to save in.

Returns

If the PO file content has been changed.

Return type

bool

mdpo.io.to_file_content_if_is_file(value, encoding='utf-8')

Check if the value passed is a file path or string content.

If is a file, reads its content and returns it, otherwise returns the string passed as is.

Parameters
  • value (str) – Value to check if is a filepath or content.

  • encoding (str) – Expected file encoding, if is a file.

Returns

File content if value is an existing file or value as is.

Return type

str

mdpo.io.to_glob_or_content(value)

Check if the value passed is a glob or is string content.

Parameters

value (str) – Value to check if is a glob or content.

Returns

Two values being the first a boolean that indicates if value is a glob (True) or content (False) and the second value is the content (parsed as glob is first value is True).

Return type

list