1 | #!/usr/bin/python2.7 |
---|
2 | |
---|
3 | import os |
---|
4 | import glob |
---|
5 | import subprocess |
---|
6 | import shutil |
---|
7 | |
---|
8 | |
---|
9 | COLOR_NONE = '\x1b[0m' |
---|
10 | COLOR_GREEN = '\x1b[32;01m' |
---|
11 | COLOR_RED = '\x1b[31;01m' |
---|
12 | |
---|
13 | METADATA={"Name":"LliureX 15.05","Comment":"Lliurex 15.05 icon set","Inherits":"Humanity,gnome,hicolor","Example":"user-home","Directories":""} |
---|
14 | |
---|
15 | CONTEXT={"actions":"Actions","apps":"Applications","categories":"Categories","devices":"Devices","emblems":"Emblems","mimetypes":"MimeTypes","places":"Places","status":"Status","lliurex-apps":"Lliurex Apps","resources":"Resources"} |
---|
16 | |
---|
17 | SRC_DIR="future-green" |
---|
18 | DST_DIR="build-desktop" |
---|
19 | |
---|
20 | DIRS=["actions","apps","categories","devices","emblems","mimetypes","places","status","lliurex-apps","resources"] |
---|
21 | SIZES=[0,16,32,24,48] |
---|
22 | |
---|
23 | print COLOR_GREEN,"* building icon set",COLOR_NONE |
---|
24 | |
---|
25 | if not os.path.exists(DST_DIR): |
---|
26 | print COLOR_GREEN,"* creating dst path",COLOR_NONE |
---|
27 | os.mkdir(DST_DIR) |
---|
28 | |
---|
29 | |
---|
30 | for sz in SIZES: |
---|
31 | |
---|
32 | if sz==0: |
---|
33 | print COLOR_GREEN,"* building scalable",COLOR_NONE |
---|
34 | sz_dir="scalable" |
---|
35 | |
---|
36 | else: |
---|
37 | sz_dir=str(sz) |
---|
38 | print COLOR_GREEN,"* building %dx%d" % (sz,sz),COLOR_NONE |
---|
39 | |
---|
40 | if not os.path.exists(DST_DIR+"/"+sz_dir): |
---|
41 | print COLOR_GREEN,"* creating path: %s" % (DST_DIR+"/"+sz_dir),COLOR_NONE |
---|
42 | os.mkdir(DST_DIR+"/"+sz_dir) |
---|
43 | |
---|
44 | for dr in DIRS: |
---|
45 | if not sz==0: |
---|
46 | METADATA["Directories"]=METADATA["Directories"]+","+sz_dir+"/"+dr |
---|
47 | else: |
---|
48 | METADATA["Directories"]=METADATA["Directories"]+",scalable/"+dr |
---|
49 | |
---|
50 | if not os.path.exists(DST_DIR+"/"+sz_dir+"/"+dr): |
---|
51 | print COLOR_GREEN,"* creating path %s" % (DST_DIR+"/"+sz_dir+"/"+dr),COLOR_NONE |
---|
52 | os.mkdir(DST_DIR+"/"+sz_dir+"/"+dr) |
---|
53 | |
---|
54 | print COLOR_GREEN,"* %s" % (DST_DIR+"/"+str(sz_dir)+"/"+dr),COLOR_NONE |
---|
55 | |
---|
56 | for f in glob.glob(SRC_DIR+"/"+dr+"/*.svg"): |
---|
57 | if not os.path.islink(f): |
---|
58 | |
---|
59 | #png |
---|
60 | if not sz==0: |
---|
61 | print COLOR_RED,"* processing %s" % (os.path.basename(f)),COLOR_NONE |
---|
62 | |
---|
63 | #subprocess.Popen(["inkscape",f,"-z","-w",str(sz),"-h",str(sz),"-e="+DST_DIR+"/"+sz_dir+"/"+dr+"/"+os.path.basename(f).replace(".svg",".png")]) |
---|
64 | subprocess.Popen(["rsvg-convert","--width="+str(sz),"--height="+str(sz),"-o",DST_DIR+"/"+sz_dir+"/"+dr+"/"+os.path.basename(f).replace(".svg",".png"),f]) |
---|
65 | |
---|
66 | #scalable case |
---|
67 | else: |
---|
68 | shutil.copy(f,DST_DIR+"/"+sz_dir+"/"+dr) |
---|
69 | |
---|
70 | else: |
---|
71 | if not sz==0: |
---|
72 | print COLOR_RED,"* symlink %s:%s" % (os.path.basename(f),os.path.realpath(f)),COLOR_NONE |
---|
73 | #shutil.copy(f,DST_DIR+"/"+sz_dir+"/"+dr) |
---|
74 | os.symlink(os.readlink(f).replace(".svg",".png"),DST_DIR+"/"+sz_dir+"/"+dr+"/"+os.path.basename(f).replace(".svg",".png")) |
---|
75 | else: |
---|
76 | os.symlink(os.readlink(f),DST_DIR+"/"+sz_dir+"/"+dr+"/"+os.path.basename(f)) |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | METADATA["Directories"]=METADATA["Directories"].lstrip(",") |
---|
81 | |
---|
82 | print COLOR_GREEN,"Writing Theme metadata...",COLOR_NONE |
---|
83 | |
---|
84 | f=open(DST_DIR+"/index.theme","w") |
---|
85 | |
---|
86 | f.write("[Icon Theme]\n") |
---|
87 | for data in METADATA: |
---|
88 | f.write("%s=%s\n"%(data,METADATA[data])) |
---|
89 | |
---|
90 | for sz in SIZES: |
---|
91 | for dr in DIRS: |
---|
92 | if not sz==0: |
---|
93 | f.write("[%d/%s]\n" % (sz,dr)) |
---|
94 | f.write("Size=%d\n"%(sz)) |
---|
95 | f.write("Context=%s\n" % (CONTEXT[dr])) |
---|
96 | f.write("Type=Fixed\n") |
---|
97 | else: |
---|
98 | f.write("[scalable/%s]\n" % (dr)) |
---|
99 | f.write("Size=48\n") |
---|
100 | f.write("MinSize=48\n") |
---|
101 | f.write("MaxSize=256\n") |
---|
102 | f.write("Context=%s\n" % (CONTEXT[dr])) |
---|
103 | f.write("Type=Scalable\n") |
---|
104 | |
---|
105 | |
---|
106 | f.close() |
---|
107 | |
---|
108 | |
---|
109 | print COLOR_GREEN,"Process completed",COLOR_NONE |
---|