def find_potentially_unused_strings(filepath, keys): ldict = jsondict.JSONDict(filepath) merged = ordereddict.OrderedDict() merged["*"] = "" count = 0 for key in sorted(ldict.keys()): merged[key.encode("UTF-8")] = ldict[key].encode("UTF-8") if not key.startswith("*") and not key.startswith("!") and not key in keys: safe_print("Found potentially unused '%s' in '%s'" % (key, os.path.basename(filepath))) count += 1 safe_print("Found %i potentially unused keys in '%s'" % (count, os.path.basename(filepath)))
def main(): keys = {} for (dirpath, dirnames, filenames) in os.walk(os.path.join(root, "DisplayCAL")): for filename in filenames: ext = os.path.splitext(filename)[1][1:] if ext not in ("py", "pyw", "xrc"): continue filepath = os.path.join(dirpath, filename) with open(filepath, "rb") as py: code = py.read() if ext == "xrc": pattern = r'<(?:label|title|tooltip)>([^>]+)</(?:label|title|tooltip)>' else: pattern = r'(?:getstr\(|(?:lstr|msg|msgid|msgstr|title)\s*=)\s*["\']([^"\']+)["\']' for match in re.findall(pattern, code): if not match in keys: keys[match.decode("UTF-8")] = 1 safe_print(len(keys), "unique keys in py/pyw/xrc") usage_path = os.path.join(confighome, "localization_usage.json") if os.path.isfile(usage_path): usage = jsondict.JSONDict(usage_path) usage.load() keys.update(usage) safe_print(len(keys), "unique keys after merging localization_usage.json") for langfile in listdir_re(os.path.join(root, "DisplayCAL", "lang"), r"^\w+\.json$"): if langfile != "en.json": find_potentially_unused_strings(os.path.join("lang", langfile), keys.keys()) raw_input("Press any key to continue") safe_print("")
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import os import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from DisplayCAL import ICCProfile as iccp from DisplayCAL.defaultpaths import iccprofiles, iccprofiles_home from DisplayCAL.safe_print import safe_print for p in set(iccprofiles_home + iccprofiles): if os.path.isdir(p): for f in os.listdir(p): try: profile = iccp.ICCProfile(os.path.join(p, f)) except: pass else: if profile.profileClass == "spac": safe_print(f) safe_print("ICC Version:", profile.version) safe_print("Color space:", profile.colorSpace) safe_print("Connection color space:", profile.connectionColorSpace) safe_print("")
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from DisplayCAL import ICCProfile as ICCP, xrandr from DisplayCAL.safe_print import safe_print from DisplayCAL.RealDisplaySizeMM import RealDisplaySizeMM as RDSMM for i in xrange(5): # Show ICC info for first five screens / outputs try: x_icc_c = xrandr.get_atom( "_ICC_PROFILE" if i < 1 else "_ICC_PROFILE_%i" % i) except ValueError: x_icc_c = None if x_icc_c: safe_print("Root window %s" % ("_ICC_PROFILE" if i < 1 else "_ICC_PROFILE_%i" % i)) x_icc = ICCP.ICCProfile("".join(chr(n) for n in x_icc_c)) safe_print("Description:", x_icc.getDescription()) safe_print("Checksum ID:", hexlify(x_icc.calculateID())) safe_print("") try: xrr_icc_c = xrandr.get_output_property(i, "_ICC_PROFILE") except ValueError: xrr_icc_c = None if xrr_icc_c: safe_print("XRandR Output %i _ICC_PROFILE:" % i) xrr_icc = ICCP.ICCProfile("".join(chr(n) for n in xrr_icc_c)) safe_print("Description:", xrr_icc.getDescription()) safe_print("Checksum ID:", hexlify(xrr_icc.calculateID())) safe_print("")
from DisplayCAL import ICCProfile as iccp from DisplayCAL.defaultpaths import iccprofiles, iccprofiles_home from DisplayCAL.safe_print import safe_print for p in set(iccprofiles_home + iccprofiles): if os.path.isdir(p): for f in os.listdir(p): try: profile = iccp.ICCProfile(os.path.join(p, f)) except: pass else: if isinstance(profile.tags.desc, iccp.TextDescriptionType): if profile.tags.desc.get( "Unicode") or profile.tags.desc.get("Macintosh"): safe_print(os.path.join(p, f)) if profile.tags.desc.get("Unicode"): safe_print("Unicode Language Code:", profile.tags.desc.unicodeLanguageCode) safe_print("Unicode Description:", profile.tags.desc.Unicode) if profile.tags.desc.get("Macintosh"): safe_print("Macintosh Language Code:", profile.tags.desc.macScriptCode) safe_print("Macintosh Description:", profile.tags.desc.Macintosh) if profile.tags.desc.get( "Unicode") or profile.tags.desc.get("Macintosh"): safe_print("") elif not isinstance(profile.tags.desc, iccp.MultiLocalizedUnicodeType):
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import os import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from DisplayCAL import ICCProfile as iccp from DisplayCAL.defaultpaths import iccprofiles, iccprofiles_home from DisplayCAL.safe_print import safe_print for p in set(iccprofiles_home + iccprofiles): if os.path.isdir(p): for f in os.listdir(p): try: profile = iccp.ICCProfile(os.path.join(p, f)) except: pass else: if profile.version >= 4: safe_print(os.path.join(p, f)) safe_print("Descriptions:", profile.tags.desc.keys(), profile.tags.desc.values()[0].keys()) safe_print("")
with open(filepath, "rb") as py: code = py.read() if ext == "xrc": pattern = r'<(?:label|title|tooltip)>([^>]+)</(?:label|title|tooltip)>' else: pattern = r'(?:getstr\(|(?:lstr|msg|msgid|msgstr|title)\s*=)\s*["\']([^"\']+)["\']' for match in re.findall(pattern, code): if not match in keys: keys[match.decode("UTF-8")] = 1 safe_print(len(keys), "unique keys in py/pyw/xrc") usage_path = os.path.join(confighome, "localization_usage.json") if os.path.isfile(usage_path): usage = jsondict.JSONDict(usage_path) usage.load() keys.update(usage) safe_print(len(keys), "unique keys after merging localization_usage.json") for langfile in listdir_re(os.path.join(root, "DisplayCAL", "lang"), r"^\w+\.json$"): if langfile != "en.json": find_potentially_unused_strings(os.path.join("lang", langfile), keys.keys()) raw_input("Press any key to continue") safe_print("") if __name__ == "__main__": if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]: safe_print("Usage: %s" % os.path.basename(sys.argv[0])) safe_print("Finds potentially unused strings in localizations") else: main()
# -*- coding: utf-8 -*- import os import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from DisplayCAL import ICCProfile as iccp from DisplayCAL.defaultpaths import iccprofiles, iccprofiles_home from DisplayCAL.safe_print import safe_print for p in set(iccprofiles_home + iccprofiles): if os.path.isdir(p): for f in os.listdir(p): try: profile = iccp.ICCProfile(os.path.join(p, f)) except: pass else: curve = None for key in ("r", "g", "b", "k"): curve = profile.tags.get(key + "TRC") if curve: break if curve and isinstance( curve, iccp.CurveType) and len(curve) == 1 and curve[0] < 1.8: safe_print(f) safe_print(curve) safe_print("")
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import os import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from DisplayCAL import ICCProfile as iccp from DisplayCAL.defaultpaths import iccprofiles, iccprofiles_home from DisplayCAL.safe_print import safe_print for p in set(iccprofiles_home + iccprofiles): if os.path.isdir(p): for f in os.listdir(p): try: profile = iccp.ICCProfile(os.path.join(p, f)) except: pass else: if profile.creator == "argl": safe_print(f) safe_print("")
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import os import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from DisplayCAL import ICCProfile as iccp from DisplayCAL.defaultpaths import iccprofiles, iccprofiles_home from DisplayCAL.safe_print import safe_print for p in set(iccprofiles_home + iccprofiles): if os.path.isdir(p): for f in os.listdir(p): try: profile = iccp.ICCProfile(os.path.join(p, f)) except: pass else: if "clrt" in profile.tags: safe_print(f) safe_print(profile.connectionColorSpace) for name in profile.tags.clrt: safe_print(name, profile.tags.clrt[name]) safe_print("")
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import os import sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from DisplayCAL import ICCProfile as iccp from DisplayCAL.defaultpaths import iccprofiles, iccprofiles_home from DisplayCAL.safe_print import safe_print for p in set(iccprofiles_home + iccprofiles): if os.path.isdir(p): for f in os.listdir(p): try: profile = iccp.ICCProfile(os.path.join(p, f)) except: pass else: if "chad" in profile.tags: safe_print(f) safe_print(profile.tags.chad) safe_print("")
sys.path.insert(0, root) from DisplayCAL import jsondict from DisplayCAL.safe_print import safe_print from DisplayCAL.util_list import natsort from DisplayCAL.util_os import safe_glob from DisplayCAL.util_str import wrap def convert(infilename): dictin = jsondict.JSONDict(infilename) dictin.load() outfilename = os.path.splitext(infilename)[0] + ".yaml" with open(outfilename, "wb") as outfile: for key in natsort(dictin.keys(), False): outfile.write('"%s": |-\n' % key.encode("UTF-8")) for line in dictin[key].split("\n"): # Do not use splitlines, returns empty list for empty string outfile.write(" %s\n" % line.encode("UTF-8")) if __name__ == "__main__": if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]: safe_print("Usage: %s" % os.path.basename(sys.argv[0])) safe_print("Converts translation JSON files to YAML files") else: for langfile in safe_glob(os.path.join(root, "DisplayCAL", "lang", "*.json")): convert(langfile)