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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#!/usr/bin/env python
################################################################################
#
# qooxdoo - the new era of web development
#
# http://qooxdoo.org
#
# Copyright:
# 2007 1&1 Internet AG, Germany, http://www.1and1.org
#
# License:
# LGPL: http://www.gnu.org/licenses/lgpl.html
# EPL: http://www.eclipse.org/org/documents/epl-v10.php
# See the LICENSE file in the project's top-level directory for details.
#
# Authors:
# * Sebastian Werner (wpbasti)
#
################################################################################
import os
import sys
import shutil
import optparse
def rmgeneric(path, __func__):
try:
__func__(path)
except OSError, (errno, strerror):
print ERROR_STR % {'path' : path, 'error': strerror }
def removeall(path):
if not os.path.isdir(path):
return
files=os.listdir(path)
for x in files:
fullpath=os.path.join(path, x)
if os.path.isfile(fullpath):
f=os.remove
rmgeneric(fullpath, f)
elif os.path.isdir(fullpath):
removeall(fullpath)
f=os.rmdir
rmgeneric(fullpath, f)
def copy_file(kde, fd, options):
img_sizes = [16, 22, 32, 48, 64, 72, 96, 128]
found = []
notfound = []
if options.verbose:
print " - Processing: %s -> %s" % (kde, fd)
for size in img_sizes:
kde_file = "%s/%sx%s/%s.png" % (options.input, size, size, kde)
fd_file = "%s/%sx%s/%s.png" % (options.output, size, size, fd)
if os.path.exists(kde_file):
fd_dir = os.path.dirname(fd_file)
if not os.path.exists(fd_dir):
os.makedirs(fd_dir)
shutil.copyfile(kde_file, fd_file)
found.append(size)
else:
notfound.append(size)
if options.verbose:
dbg = " "
for size in img_sizes:
if size in found:
ret = "Y"
else:
ret = "N"
dbg += " [%s] %s" % (ret, size)
print dbg
def main():
parser = optparse.OptionParser("usage: %prog [options]")
parser.add_option("-q", "--quiet", action="store_false", dest="verbose", default=False, help="Quiet output mode.")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help="Verbose output mode.")
parser.add_option("--input", "-i", action="store", dest="input", metavar="DIRECTORY", help="Input directory")
parser.add_option("--output", "-o", action="store", dest="output", metavar="DIRECTORY", help="Output directory")
(options, args) = parser.parse_args(sys.argv[1:])
if options.input == None or options.output == None:
basename = os.path.basename(sys.argv[0])
print "You must define both, the input and output folders!"
print "usage: %s [options]" % basename
print "Try '%s -h' or '%s --help' to show the help message." % (basename, basename)
sys.exit(1)
print " - Cleaning up..."
removeall(options.output)
dat = open("%s/../data/kde_freedesktop.dat" % os.path.dirname(sys.argv[0]))
print " - Copying files..."
for line in dat.readlines():
line = line.strip();
if line == "" or line[0] == "#":
continue
if not line[0] in ["+", "*"]:
continue
line = line[1:]
(fd, kde) = map(lambda x: x.strip(), line.split("="))
copy_file(kde, fd, options)
if __name__ == "__main__":
sys.exit(main())
|