linuxmint / mint-y-icons

The Mint-Y icon theme
123 stars 56 forks source link

Missing script to automate the creation of 'places' icons (symlinks, index.theme) #292

Open antrrax opened 2 years ago

antrrax commented 2 years ago

In Mint-Y Icons Script to automate the creation of symbolic links from the 'places' directory is missing. Also missing script to automate the creation of the index.theme file from the 'places' directory

If I use the script below to try to create a new icon color, the files mentioned in the icon theme are missing, and the icon theme is broken:

set -e

SYSTEM_USER=false   #$HOME/.icons
#SYSTEM_USER=true   #/usr/share/icons/

VARIATION_NAME="Yellow-New"
VARIATION_SVG_COLOR="ffe35f"

MINT_Y_GIT="https://github.com/linuxmint/mint-y-icons/archive/refs/heads/master.zip"
OUTPUT_NAME_GIT="mint-y-icons-master"

INIT_DIR="$PWD/$OUTPUT_NAME_GIT"
SVG_PLACES="$INIT_DIR/src/places"
VARIATION_SVG_NAME=${VARIATION_NAME,,}
#==============

wget -c "$MINT_Y_GIT" -P "$PWD" -O "$OUTPUT_NAME_GIT.zip"

echo "=========> Unzip File"
unzip -qq -o "./$OUTPUT_NAME_GIT.zip"

if [ -d "$INIT_DIR/usr/share/icons/Mint-Y-$VARIATION_NAME" ]; then
    rm -fr "$INIT_DIR/usr/share/icons/Mint-Y-$VARIATION_NAME"
fi

if ! grep -q "COLORS\[\"$VARIATION_SVG_NAME\"\] = \"$VARIATION_SVG_COLOR\"" "$SVG_PLACES/generate-color-variations.py" ; then
    echo "=========> Modifying file: $SVG_PLACES/generate-color-variations.py"
    sed -i "s/GREEN_COLOR = \"8bb158\"/COLORS[\"$VARIATION_SVG_NAME\"] = \"$VARIATION_SVG_COLOR\"\n\nGREEN_COLOR = \"8bb158\"/g" "$SVG_PLACES/generate-color-variations.py"
fi

echo "=========> Generating file: $SVG_PLACES/$VARIATION_SVG_NAME.svg"
cd "$SVG_PLACES"
"./generate-color-variations.py"

if ! grep -q "\"$VARIATION_NAME\"" "$INIT_DIR/src/render_places.py" ; then
    echo "=========> Modifying file(Add new color): $INIT_DIR/src/render_places.py"
    sed -i "s/colors = \[/colors = \[\"$VARIATION_NAME\", /g" "$INIT_DIR/src/render_places.py"
    sed -i "s/ or All./, $VARIATION_NAME or All./g" "$INIT_DIR/src/render_places.py"
fi

echo "=========> Rendering files:"
cd "$INIT_DIR/src"
"./render_places.py" "$VARIATION_NAME"

echo -e "=========> Compressing file: $INIT_DIR/$VARIATION_NAME.tar.gz"
cd "$INIT_DIR/usr/share/icons"
tar -zcf "$INIT_DIR/$VARIATION_NAME.tar.gz" "Mint-Y-$VARIATION_NAME"

if [ -d "$HOME/.icons/Mint-Y-$VARIATION_NAME" ]; then
    echo -e "=========> Removing folder: $HOME/.icons/Mint-Y-$VARIATION_NAME\n"
    rm -fr "$HOME/.icons/Mint-Y-$VARIATION_NAME"
fi

if [ "$SYSTEM_USER" = true ]; then
    if [ -d "/usr/share/icons/Mint-Y-$VARIATION_NAME" ]; then
        echo -e "=========> Removing folder: /usr/share/icons/Mint-Y-$VARIATION_NAME\n"
        sudo rm -fr "/usr/share/icons/Mint-Y-$VARIATION_NAME"
    fi

    echo -e "=========> Unpacking file to: /usr/share/icons/"
    sudo tar zxf "$INIT_DIR/$VARIATION_NAME".tar.gz -C "/usr/share/icons/"

else
    mkdir -p "$HOME/.icons"
    echo -e "=========> Unpacking file to: $HOME/.icons"
    tar zxf "$INIT_DIR/$VARIATION_NAME".tar.gz -C "$HOME/.icons"

    if [ -d "/usr/share/icons/Mint-Y-$VARIATION_NAME" ]; then
        echo -e "=========> Removing folder: /usr/share/icons/Mint-Y-$VARIATION_NAME\n"
        sudo rm -fr "/usr/share/icons/Mint-Y-$VARIATION_NAME"
    fi
fi
antrrax commented 2 years ago

Here is a suggestion

To automate the creation of symbolic links I added this function in the file 'render_places.py'

#key: symlink_name
#value: target_file_name
symlink_dict = {'athena': 'folder', 'desktop': 'user-desktop', 'file-manager': 'folder', 'folder_home': 'user-home', 'folder-open': 'folder-drag-accept', 'folder-remote': 'gtk-network', 'gnome-fs-desktop': 'user-desktop', 'gnome-fs-home': 'user-home', 'gtk-directory': 'folder', 'inode-directory': 'folder', 'kfm': 'folder', 'library-music': 'folder-music', 'nautilus-actions-config-tool': 'folder', 'nautilus': 'folder', 'nemo': 'folder', 'network-server': 'network-workgroup', 'org.xfce.gigolo': 'gtk-network', 'org.xfce.panel.directorymenu': 'folder', 'org.xfce.panel.showdesktop': 'user-desktop', 'org.xfce.thunar': 'folder', 'org.xfce.xfdesktop': 'user-desktop', 'redhat-filemanager': 'folder', 'stock_folder': 'folder', 'system-file-manager': 'folder', 'thunar': 'folder', 'Thunar': 'folder', 'xapp-user-favorites': 'user-bookmarks', 'xfce-filemanager': 'folder'}

def create_symlink_places(symbolic_dict, dir):
    for k,v in symbolic_dict.items():
        symlink_path = os.path.join(dir, f'''{k}.png''').rstrip()
        target_path = os.path.join(dir, f'''{v}.png''').rstrip()

        if not os.path.islink(symlink_path):
            subprocess.call(['ln', '-s', '-r', target_path, symlink_path])
            print(f'''symlink: {symlink_path} created''')

the complete file looked like this:

import os
import subprocess
import sys

colors = ["Yellow-New", "Aqua", "Blue", "Brown", "Green", "Grey", "Orange", "Pink", "Purple", "Red", "Sand", "Teal", "Yellow"]
sizes = ["16", "22", "24", "32", "48", "64", "96", "128"]

#key: symlink_name
#value: target_file_name
symlink_dict = {'athena': 'folder', 'desktop': 'user-desktop', 'file-manager': 'folder', 'folder_home': 'user-home', 'folder-open': 'folder-drag-accept', 'folder-remote': 'gtk-network', 'gnome-fs-desktop': 'user-desktop', 'gnome-fs-home': 'user-home', 'gtk-directory': 'folder', 'inode-directory': 'folder', 'kfm': 'folder', 'library-music': 'folder-music', 'nautilus-actions-config-tool': 'folder', 'nautilus': 'folder', 'nemo': 'folder', 'network-server': 'network-workgroup', 'org.xfce.gigolo': 'gtk-network', 'org.xfce.panel.directorymenu': 'folder', 'org.xfce.panel.showdesktop': 'user-desktop', 'org.xfce.thunar': 'folder', 'org.xfce.xfdesktop': 'user-desktop', 'redhat-filemanager': 'folder', 'stock_folder': 'folder', 'system-file-manager': 'folder', 'thunar': 'folder', 'Thunar': 'folder', 'xapp-user-favorites': 'user-bookmarks', 'xfce-filemanager': 'folder'}

def create_symlink_places(symbolic_dict, dir):
    for k,v in symbolic_dict.items():
        symlink_path = os.path.join(dir, f'''{k}.png''').rstrip()
        target_path = os.path.join(dir, f'''{v}.png''').rstrip()

        if not os.path.islink(symlink_path):
            subprocess.call(['ln', '-s', '-r', target_path, symlink_path])
            print(f'''symlink: {symlink_path} created''')

def generate_color(color):
    source = "places/" + color.lower() + ".svg"
    if color == "Green":
        theme_dir = "../usr/share/icons/Mint-Y"
    else:
        theme_dir = "../usr/share/icons/Mint-Y-%s" % color
    os.system("mkdir -p %s" % theme_dir)

    for size in sizes:
        icon_dir = os.path.join(theme_dir, "places", size)
        icon_dir_2x = os.path.join(theme_dir, "places", size + "@2x")
        os.system("mkdir -p %s" % icon_dir)
        os.system("mkdir -p %s" % icon_dir_2x)
        names = subprocess.check_output("inkscape -S %s | grep -E \"_%s\" | sed 's/\,.*$//'" % (source, size), shell=True).decode("UTF-8")
        for name in names.split("\n"):
            if "_" in name:
                icon_name = name.replace("_%s" % size, "")
                icon_path = os.path.join(icon_dir, icon_name + ".png")
                print("Rendering %s" % icon_path)
                os.system("inkscape --export-id=%s \
                               --export-id-only \
                               --export-png=%s %s >/dev/null \
                     && optipng -o7 --quiet %s" % (name, icon_path, source, icon_path))

                icon_path = os.path.join(icon_dir_2x, icon_name + ".png")
                print("Rendering %s" % icon_path)
                os.system("inkscape --export-id=%s \
                               --export-id-only \
                               --export-dpi=192 \
                               --export-png=%s %s >/dev/null \
                     && optipng -o7 --quiet %s" % (name, icon_path, source, icon_path))

        create_symlink_places(symlink_dict, icon_dir)
        create_symlink_places(symlink_dict, icon_dir_2x)

def parse_arg(arg):
    if arg == "All":
        for color in colors:
            generate_color(color)
    else:
        generate_color(arg)

def usage():
    print ("Usage: render_places.py color \n\
    color can be: Aqua, Blue, Brown, Green, Grey, Orange, Pink, Purple, Red, Sand, Teal, Yellow, Yellow-New or All.")
    sys.exit(1)

if len(sys.argv) != 2:
    usage()
else:
    parse_arg(sys.argv[1])