Skip to content
This repository
Browse code

Check locales during build

  • Loading branch information...
commit 7c1c8085d2e085a0a61283464ad32a89b4077ecc 1 parent bd27dcc
Nils Maier authored December 19, 2011
8  build.py
@@ -3,6 +3,12 @@
3 3
 from io import BytesIO
4 4
 from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED
5 5
 
  6
+try:
  7
+    from cmp_listed_locales import cmp_listed_locales
  8
+except ImportError, ex:
  9
+    def cmp_listed_locales(dirname):
  10
+        print >>sys.stderr, "WARNING: did not compare locales (%s)" % ex
  11
+
6 12
 from path import path
7 13
 
8 14
 jar_files = [
@@ -69,6 +75,7 @@ def chromejar_line(line):
69 75
 
70 76
 def main():
71 77
     basedir = path(__file__).dirname()
  78
+    cmp_listed_locales(basedir)
72 79
 
73 80
     with BytesIO() as xpi:
74 81
         zip_files(xpi, xpi_files, basedir)
@@ -83,6 +90,7 @@ def main():
83 90
                 zp.writestr("chrome.manifest", manifest)
84 91
         with open("mintrayr.xpi", "wb") as op:
85 92
             op.write(xpi.read())
  93
+    print "done!"
86 94
     return 0
87 95
 
88 96
 if __name__ == "__main__":
126  cmp_listed_locales.py
... ...
@@ -0,0 +1,126 @@
  1
+import os, re, sys
  2
+import logging
  3
+import codecs
  4
+
  5
+from glob import glob
  6
+from path import path
  7
+from os.path import basename, dirname
  8
+from Mozilla.CompareLocales import compareDirs
  9
+
  10
+logging.basicConfig()
  11
+logging.getLogger().setLevel(logging.WARNING)
  12
+
  13
+def cmp_listed_locales(dirname):
  14
+    basedir = dirname if isinstance(dirname, path) else path(dirname)
  15
+    listed = dict()
  16
+    def parseCM():
  17
+        r = re.compile(r'^locale\s+.+?\s+(.+?)\s+(?:jar:(.+?)!/)?(.+?)\s*$')
  18
+        with open(basedir / "chrome.manifest", 'r') as fp:
  19
+            for l in fp:
  20
+                m = r.match(l)
  21
+                if not m:
  22
+                    continue
  23
+                l, j, p = m.groups()
  24
+                if j:
  25
+                    j = dirname(j)
  26
+                    if j:
  27
+                        p = basepath / j / p
  28
+                listed[l] = path(p)
  29
+
  30
+    if (basedir / "chrome.manifest").isfile():
  31
+        parseCM()
  32
+    else:
  33
+        raise ValueError("Don't know what to do")
  34
+
  35
+    if len(listed) == 0:
  36
+        raise ValueError("Not localized")
  37
+    if len(listed) == 1:
  38
+        raise ValueError("Only one locale")
  39
+
  40
+    baseloc = None
  41
+    for bl in ('en-US', 'en', 'en-NZ', 'de-DE', 'de', 'fr-FR', 'fr'):
  42
+        if listed.has_key(bl):
  43
+            baseloc = bl
  44
+            break
  45
+    if not baseloc:
  46
+        raise ValueError("No base locale")
  47
+
  48
+    print "Using", baseloc, "as base locale"
  49
+
  50
+    bad = list()
  51
+    good = list()
  52
+    missing = list()
  53
+    for l,p in listed.iteritems():
  54
+        if not p.isdir():
  55
+          continue
  56
+        if l == baseloc:
  57
+            " skip base locale "
  58
+            continue
  59
+
  60
+        listed[l] = True
  61
+
  62
+        res = compareDirs(listed[baseloc], p)
  63
+        summary = res.getSummary()[None]
  64
+        if not 'missing' in summary and not 'errors' in summary:
  65
+            good += l,
  66
+            continue
  67
+        bad += l,
  68
+        if not 'changed' in summary:
  69
+            summary['changed'] = 0
  70
+        if not 'unchanged' in summary:
  71
+            summary['unchanged'] = 0
  72
+        summary["total"] = summary['changed'] + summary['unchanged']
  73
+        if not summary["total"]:
  74
+            summary["total"] = -1
  75
+        if not 'missing' in summary:
  76
+            summary['missing'] = 0
  77
+
  78
+        if not 'errors' in summary:
  79
+            summary['errors'] = 0
  80
+
  81
+        print "Locale: %s" % l
  82
+        print "Strings: %d (Missing: %d / %.2f%%)\nChanged: %d (%.2f%%), Unchanged %d (%.2f%%)\nErrors: %d" % (
  83
+            summary['total'],
  84
+            summary['missing'],
  85
+            100.0 * summary['missing'] / (summary['total'] + summary['missing']),
  86
+            summary['changed'],
  87
+            100.0 * summary['changed'] / summary['total'],
  88
+            summary['unchanged'],
  89
+            100.0 * summary['unchanged'] / summary['total'],
  90
+            summary['errors']
  91
+            )
  92
+        branches = list(res.details.branches)
  93
+        branches.sort()
  94
+        print "Issues:"
  95
+        for b in branches:
  96
+            for f in b:
  97
+                print "*", f
  98
+                for k, v in res.details[f].iteritems():
  99
+                    if isinstance(v, list):
  100
+                        v = ', '.join(v)
  101
+                    try:
  102
+                        print "\t%s: %s" % (unicode(k), unicode(v))
  103
+                    except:
  104
+                        pass
  105
+        print
  106
+    for l,p in listed.iteritems():
  107
+        if p is True or l == baseloc:
  108
+            continue
  109
+        missing += l,
  110
+    if bad:
  111
+        print "Bad:", ' '.join(bad)
  112
+    if missing:
  113
+        print "Missing:", ' '.join(missing)
  114
+    if good:
  115
+        print 'Good:', ' '.join(good)
  116
+    if bad or missing:
  117
+        raise ValueError("Not valid")
  118
+
  119
+if __name__ == "__main__":
  120
+    try:
  121
+        cmp_listed_locales(path("."))
  122
+    except Exception,ex:
  123
+        print >>sys.stderr, ex
  124
+        sys.exit(1)
  125
+    else:
  126
+        sys.exit(0)

0 notes on commit 7c1c808

Please sign in to comment.
Something went wrong with that request. Please try again.