File indexing completed on 2024-05-12 16:39:34

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 './flow/*' " + # not ported for 3.x currently
0021             "! -path './gemini/themes/*' " +
0022             "! -path './karbon/stencils/*' " +
0023             "! -path './kexi/main/status/*' " +
0024             "! -path './kexi/pics/*_newobj.png' " + # kexi calculates iconname here, needs more complex checl
0025             "! -path './plan/about/*' " +
0026             "! -path './plugins/karbonplugins/tools/CalligraphyTool/tutorial/*' " +
0027             "! -path './sheets/data/sheetstyles/*' " +
0028             "! -path './stage/pics/animations/*' " + # names are calculated when used, needs more complex check
0029             "! -path './words/templates/*' " + # find out where gemini style templates refer icon used
0030             "\( -name '*.png' -o -name '*.svg' -o -name '*.svgz' \) -printf '%%f\n' | " +
0031             "sed -e 's/\.png$//' -e 's/\.svg$//' -e 's/\.svgz$//' | " +
0032             "sort -u > %s") % (calligraIconsFile), shell=True)
0033     return r
0034 
0035 
0036 # TODO: make path a variable
0037 def createDotDesktopIconFile():
0038     r = subprocess.call("grep 'Icon=' . -R --exclude-dir='karbon/stencils' --include=\*.desktop > " + dotDesktopIconsFileName, shell=True)
0039     return r
0040 
0041 
0042 # TODO: make path a variable
0043 def createPotFile():
0044     r = subprocess.call("find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.c' | sort > koIconFiles.list", shell=True)
0045     if r:
0046         return r
0047     r = subprocess.call("xgettext --from-code=UTF-8 -k " +
0048              "-kkoIcon:1 " +
0049              "-kkoIconName:1 " +
0050              "-kkoIconNameCStr:1 " +
0051              "-kkoSmallIcon:1 " +
0052              "-kkoDesktopIcon:1 " +
0053 
0054              "-kkoIconNeeded:1c,2 " +
0055              "-kkoIconNeededWithSubs:1c,2 " +
0056              "-kkoIconNameNeeded:1c,2 " +
0057              "-kkoIconNameNeededWithSubs:1c,2 " +
0058              "-kkoIconNameCStrNeeded:1c,2 " +
0059              "-kkoIconNameCStrNeededWithSubs:1c,2 " +
0060 
0061              "-kkoIconWanted:1c,2 " +
0062              "-kkoIconNameWanted:1c,2 " +
0063 
0064              "-D . --files-from=koIconFiles.list -o koIconNames.po -n", shell=True)
0065     return r
0066     #TODO: use Python pipes and/or clean-up helper files
0067 
0068 sizePrefixes = (
0069     "16-", "22-", "24-", "32-", "48-", "64-", "128-", "256-", "512-", "1024-", "sc-"
0070 )
0071 groupPrefixes = [
0072     # KDE 3 compatibility
0073     "mime-", "filesys-", "device-", "app-", "action-",
0074     # KDE 4 / icon naming specification compatibility
0075     "mimetypes-", "places-", "devices-", "apps-", "actions-", "categories-",
0076     "status-", "emblems-", "emotes-", "animations-", "intl-"
0077 ]
0078 
0079 elsewhereUsedIcons = (
0080     "application-x-vnd.kde.plan",
0081     "application-x-vnd.kde.plan.work",
0082     "application-x-vnd.kde.kplato",
0083     "application-x-vnd.kde.kplato.work",
0084     "application-x-kexi-connectiondata",
0085     "application-x-kexiproject-shortcut",
0086     "application-x-kexiproject-sqlite",
0087     "application-x-kexiproject-sqlite2",
0088     "application-x-kexiproject-sqlite3",
0089     "application-x-sqlite2",
0090     "application-x-sqlite3",
0091     "calligra-logo-black-glow",
0092     "calligra-logo-white-glow",
0093     "layout-elements", # stage UI element
0094     "tableview_pen", "tableview_plus", "tableview_pointer", # kexi xpm bases
0095     "questionmark", # for unknown shapes
0096     "cursor_shear", "cursor_rotate", "cursor_connect", "zoom_out_cursor", "zoom_in_cursor" # cursor images
0097 )
0098 
0099 
0100 # returns map of iconnames with used filenames
0101 def readIcons(fileName):
0102     iconNames = {}
0103     with open(fileName, "r") as f:
0104         for line in f:
0105             iconFileName = line.strip().lower()
0106             if iconFileName:
0107                 iconName = iconFileName;
0108                 if iconName.startswith(sizePrefixes):
0109                     iconName = iconName.split('-',2)[2]
0110 
0111                 if iconName in iconNames:
0112                     iconNames[iconName].append(iconFileName)
0113                 else:
0114                     iconNames[iconName] = [iconFileName];
0115     return iconNames
0116 
0117 
0118 def readDotDesktopIcons():
0119     iconNames = set()
0120     with open(dotDesktopIconsFileName, "r") as f:
0121         for line in f:
0122             line = line.strip().lower()
0123             if line:
0124                 fileName, entry = line.split(':', 1)
0125                 iconName = entry.split('=', 1)[1]
0126                 if iconName:
0127                     iconNames.add(iconName)
0128     return iconNames
0129 
0130 
0131 def main():
0132 
0133     r = createCalligraIconFile(calligraIconsFileName)
0134     if r:
0135         return r
0136 
0137     calligraIcons = readIcons(calligraIconsFileName)
0138 
0139     r = createPotFile()
0140     if r:
0141         return r
0142 
0143     r = createDotDesktopIconFile()
0144     if r:
0145         return r
0146 
0147     po = polib.pofile('koIconNames.po')
0148 
0149     # collect icons and their occurrences
0150     codeUsedIcons = set()
0151 
0152     for entry in po:
0153         codeUsedIcons.add(entry.msgid)
0154 
0155     desktopFileUsedIcons = readDotDesktopIcons()
0156 
0157     # output unused icons
0158     for iconName, iconFileNames in sorted(calligraIcons.iteritems()):
0159         if not iconName in codeUsedIcons and not iconName in desktopFileUsedIcons and not iconName in elsewhereUsedIcons:
0160             print iconName
0161             for filename in iconFileNames:
0162                 print '    %s' % (filename)
0163 
0164     return 0
0165 
0166 if __name__ == '__main__':
0167     main()