Created
September 8, 2020 23:04
-
-
Save KennFatt/13b535bada559806c9051accdd3c9e6d to your computer and use it in GitHub Desktop.
Find all icon directories for option that Dunst notification needs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
import os | |
import configparser | |
import sys | |
import traceback | |
HOME = Path().home() | |
ICONS_PATH = [ | |
HOME.joinpath(".local/share/icons"), | |
HOME.joinpath(".icons") | |
] | |
def main(): | |
parser = configparser.ConfigParser() | |
icon_directories = [] | |
for icon_path in ICONS_PATH: | |
for (dirpath, _, filenames) in os.walk(icon_path): | |
if "index.theme" not in filenames: | |
continue | |
try: | |
with open(Path(dirpath).joinpath("index.theme"), "r", encoding="utf-8") as f: | |
parser.read_file(f) | |
if dirs := parser.get(section="Icon Theme", option="Directories", fallback=[]): | |
dirs = dirs.split(",") | |
for dirname in dirs: | |
dirname_path = Path(dirpath).joinpath(dirname) | |
if dirname_path.is_dir(): | |
icon_directories.append(str(dirname_path)) | |
parser.clear() | |
except: | |
continue | |
_save_content(icon_directories) | |
def _save_content(icon_directories): | |
try: | |
with open("icon_path.txt", "w") as f: | |
f.write(":".join(icon_directories)) | |
except: | |
traceback.print_exc(file=sys.stderr) | |
if __name__ == "__main__": | |
main() | |
# parser = configparser.ConfigParser() | |
# parser.read_file(open("index.theme")) | |
# dirs = parser.get(section="Icon Theme", option="Directories") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment