# -*- coding: utf-8 -*-
# Licensed under the EUPL v1.2
# © 2019-2020 bicobus <bicobus@keemail.me>
import logging
import os
from datetime import datetime
from typing import List, Tuple, Union
from qmm import get_data_path, is_windows
from qmm.config import Config
logger = logging.getLogger(__name__)
settings = Config(
filename="settings.json",
defaults={"local_repository": None, "game_folder": None, "language": None},
)
[docs]def settings_are_set():
"""Returns False if either 'local_repository' or 'game_folder' isn't set."""
if not settings["local_repository"] or not settings["game_folder"]:
return False
return True
[docs]def timestamp_to_string(timestamp):
"""Takes a UNIX timestamp and return a vernacular date."""
return datetime.strftime(datetime.fromtimestamp(timestamp), "%c")
[docs]def valid_suffixes(
output_format="qfiledialog",
) -> Union[List[str], Tuple[str, str, str], bool]:
"""Properly format a list of filters for QFileDialog.
Args:
output_format (str): Accepts either 'qfiledialog' or 'pathlib'.
'pathlib' returns a simple list of suffixes, whereas 'qfiledialog'
format the output to be an acceptable filter for QFileDialog.
Returns:
list: a list of valid suffixes.
"""
if output_format not in ("qfiledialog", "pathlib"):
return False
labels = ("7Zip Files", "Zip Files", "Rar Files")
suffixes = (".7z", ".zip", ".rar")
if output_format == "qfiledialog":
filter_on, tpl = [], []
for s in suffixes:
tpl.append(f"*{s}") # *.ext
string = "All Archives({})".format(" ".join(tpl))
filter_on.append(string)
for label, s in zip(labels, tpl):
filter_on.append(f"{label} ({s})")
return filter_on
return suffixes