File indexing completed on 2024-05-12 16:28:26
0001 #!/usr/bin/python -Qwarnall 0002 0003 # This is a simple script to check which icon files are not referenced 0004 # from either mark-up'ed icon names or desktop files. 0005 # Call it from the toplevel source dir of Calligra. 0006 0007 import sys, subprocess, polib 0008 0009 dotDesktopIconsFileName = "dotDesktopIconFiles.list" 0010 calligraIconsFileName = "calligra-icons.list" 0011 0012 0013 # TODO: make path a variable 0014 def createCalligraIconFile(calligraIconsFile): 0015 r = subprocess.call( ("find . " + 0016 "-type d \( -name 'doc' -o " + 0017 "-name 'docs' -o " + 0018 "-name 'tests' \) -prune -o " + 0019 "! -path './braindump/data/states/states/*' " + 0020 "! -path './gemini/themes/*' " + 0021 "! -path './karbon/stencils/*' " + 0022 "! -path './plugins/karbonplugins/tools/CalligraphyTool/tutorial/*' " + 0023 "! -path './sheets/data/sheetstyles/*' " + 0024 "! -path './stage/pics/animations/*' " + # names are calculated when used, needs more complex check 0025 "! -path './words/templates/*' " + # find out where gemini style templates refer icon used 0026 "\( -name '*.png' -o -name '*.svg' -o -name '*.svgz' \) -printf '%%f\n' | " + 0027 "sed -e 's/\.png$//' -e 's/\.svg$//' -e 's/\.svgz$//' | " + 0028 "sort -u > %s") % (calligraIconsFile), shell=True) 0029 return r 0030 0031 0032 # TODO: make path a variable 0033 def createDotDesktopIconFile(): 0034 r = subprocess.call("grep 'Icon=' . -R --exclude-dir='karbon/stencils' --include=\*.desktop > " + dotDesktopIconsFileName, shell=True) 0035 return r 0036 0037 0038 # TODO: make path a variable 0039 def createPotFile(): 0040 r = subprocess.call("find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.c' | sort > koIconFiles.list", shell=True) 0041 if r: 0042 return r 0043 r = subprocess.call("xgettext --from-code=UTF-8 -k " + 0044 "-kkoIcon:1 " + 0045 "-kkoIconName:1 " + 0046 "-kkoIconNameCStr:1 " + 0047 "-kkoSmallIcon:1 " + 0048 "-kkoDesktopIcon:1 " + 0049 0050 "-kkoIconNeeded:1c,2 " + 0051 "-kkoIconNeededWithSubs:1c,2 " + 0052 "-kkoIconNameNeeded:1c,2 " + 0053 "-kkoIconNameNeededWithSubs:1c,2 " + 0054 "-kkoIconNameCStrNeeded:1c,2 " + 0055 "-kkoIconNameCStrNeededWithSubs:1c,2 " + 0056 0057 "-kkoIconWanted:1c,2 " + 0058 "-kkoIconNameWanted:1c,2 " + 0059 0060 "-D . --files-from=koIconFiles.list -o koIconNames.po -n", shell=True) 0061 return r 0062 #TODO: use Python pipes and/or clean-up helper files 0063 0064 sizePrefixes = ( 0065 "16-", "22-", "24-", "32-", "48-", "64-", "128-", "256-", "512-", "1024-", "sc-" 0066 ) 0067 groupPrefixes = [ 0068 # KDE 3 compatibility 0069 "mime-", "filesys-", "device-", "app-", "action-", 0070 # KDE 4 / icon naming specification compatibility 0071 "mimetypes-", "places-", "devices-", "apps-", "actions-", "categories-", 0072 "status-", "emblems-", "emotes-", "animations-", "intl-" 0073 ] 0074 0075 elsewhereUsedIcons = ( 0076 "application-x-sqlite2", 0077 "application-x-sqlite3", 0078 "calligra-logo-black-glow", 0079 "calligra-logo-white-glow", 0080 "layout-elements", # stage UI element 0081 "questionmark", # for unknown shapes 0082 "cursor_shear", "cursor_rotate", "cursor_connect", "zoom_out_cursor", "zoom_in_cursor" # cursor images 0083 ) 0084 0085 0086 # returns map of iconnames with used filenames 0087 def readIcons(fileName): 0088 iconNames = {} 0089 with open(fileName, "r") as f: 0090 for line in f: 0091 iconFileName = line.strip().lower() 0092 if iconFileName: 0093 iconName = iconFileName; 0094 if iconName.startswith(sizePrefixes): 0095 iconName = iconName.split('-',2)[2] 0096 0097 if iconName in iconNames: 0098 iconNames[iconName].append(iconFileName) 0099 else: 0100 iconNames[iconName] = [iconFileName]; 0101 return iconNames 0102 0103 0104 def readDotDesktopIcons(): 0105 iconNames = set() 0106 with open(dotDesktopIconsFileName, "r") as f: 0107 for line in f: 0108 line = line.strip().lower() 0109 if line: 0110 fileName, entry = line.split(':', 1) 0111 iconName = entry.split('=', 1)[1] 0112 if iconName: 0113 iconNames.add(iconName) 0114 return iconNames 0115 0116 0117 def main(): 0118 0119 r = createCalligraIconFile(calligraIconsFileName) 0120 if r: 0121 return r 0122 0123 calligraIcons = readIcons(calligraIconsFileName) 0124 0125 r = createPotFile() 0126 if r: 0127 return r 0128 0129 r = createDotDesktopIconFile() 0130 if r: 0131 return r 0132 0133 po = polib.pofile('koIconNames.po') 0134 0135 # collect icons and their occurrences 0136 codeUsedIcons = set() 0137 0138 for entry in po: 0139 codeUsedIcons.add(entry.msgid) 0140 0141 desktopFileUsedIcons = readDotDesktopIcons() 0142 0143 # output unused icons 0144 for iconName, iconFileNames in sorted(calligraIcons.iteritems()): 0145 if not iconName in codeUsedIcons and not iconName in desktopFileUsedIcons and not iconName in elsewhereUsedIcons: 0146 print iconName 0147 for filename in iconFileNames: 0148 print ' %s' % (filename) 0149 0150 return 0 0151 0152 if __name__ == '__main__': 0153 main()