summaryrefslogtreecommitdiffstats
path: root/icons/copybreeze.sh
blob: 86e3f019432857eef44e2cc642be9a26cdd3baf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python2

import sh
import subprocess
import os
from shutil import copyfile, copy2
from os import path

wantedIcons = [
    "application-menu.svg",
    "dialog-cancel.svg",
    "dialog-ok.svg",
    "document-decrypt.svg",
    "document-edit.svg",
    "document-encrypt.svg",
    "document-save.svg",
    "document-sign.svg",
    "edit-delete.svg",
    "edit-find.svg",
    "edit-undo.svg",
    "error.svg",
    "folder.svg",
    "im-user.svg",
    "mail-mark-important.svg",
    "mail-mark-unread-new.svg",
    "mail-reply-sender.svg",
    "mail-folder-outbox.svg",
    "network-disconnect.svg",
    "view-refresh.svg",
    "go-down.svg",
    "go-up.svg",
    "go-previous.svg",
    "mail-message.svg",
    "list-add.svg",
    "list-remove.svg",
    "checkbox.svg",
    "edit-copy.svg",
    "password-show-on.svg",
    "password-show-off.svg",
    "format-text-bold-symbolic.svg",
    "format-text-italic-symbolic.svg",
    "format-text-underline-symbolic.svg",
    "kdocumentinfo.svg",
    "group.svg"
]

def ensure_dir(file_path):
    directory = os.path.dirname(file_path)
    if not os.path.exists(directory):
        os.makedirs(directory)

def copyFile(rootDir, dir, file):
    print("Copy file " + root + ", " + dir + ", " + file)
    reldir = dir.replace(path.join(rootDir, "icons"), "")
    src = os.path.join(dir, file)
    if os.path.islink(src):
        # We're dealing with a symlink
        linkto = os.readlink(src)
        targetRelpath = path.join(os.path.dirname(src), linkto)
        targetReldir = os.path.dirname(targetRelpath)

        # First recursively copy target
        copyFile(rootDir, targetReldir, targetRelpath.replace(targetReldir + "/", ""))

        #Create symlinks for normal and dark version
        dst = "./breeze/icons" + path.join(reldir, file)
        if not os.path.exists(dst):
            ensure_dir(dst)
            os.symlink(linkto, dst)

        invertedDst = "./breeze/icons" + path.join(reldir, file.replace(".svg", "-inverted.svg"))
        if not os.path.exists(invertedDst):
            ensure_dir(invertedDst)
            os.symlink(linkto.replace(".svg", "-inverted.svg"), invertedDst)
    else:
        # A regular icon, just copy normal and dark version
        dst = "./breeze/icons" + path.join(reldir, file)
        if not os.path.exists(dst):
            print("Copying: " + path.join(dir, file) + " to " + dst)
            ensure_dir(dst)
            copy2(src, dst)

        invertedDst = "./breeze/icons" + path.join(reldir, file.replace(".svg", "-inverted.svg"))
        if not os.path.exists(invertedDst):
            print("Copying: " + src.replace("icons", "icons-dark") + " to " + invertedDst)
            ensure_dir(invertedDst)
            copy2(src.replace("icons", "icons-dark"), invertedDst)

dir="upstreamBreeze"
if not os.path.exists(dir):
    sh.git.clone("--depth", "1", "git://anongit.kde.org/breeze-icons.git", dir)

dirToWalk = dir + "/icons"
for root, dirs, files in os.walk(dirToWalk):
    for file in files:
        if any(file == s for s in wantedIcons):
            copyFile(dir, root, file)
        elif "mimetypes" in root: #Except the explicitly mentioned icons we'll also want all mimetypes
            copyFile(dir, root, file)