add regression testing, initial checkin with dtd->inline trunk
authorZbigniew Braniecki <gandalf@mozilla.com>
Thu, 19 Aug 2010 21:05:46 +0200
branchtrunk
changeset 438 b1dd85aefac7cb67ab1cec5f6edeb2191b87cfcc
parent 437 b41b4e9f3692ae5a39a3d5831a4d37be2a99319a
child 439 c4892f86b64559d940cef102a63f51c57a109a6e
push id22
push userzbraniecki@mozilla.com
push dateMon, 23 Aug 2010 14:01:03 +0000
add regression testing, initial checkin with dtd->inline
scripts/l20n/regression/__init__.py
scripts/l20n/regression/data.py
scripts/l20n/regression/xul.py
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/scripts/l20n/regression/data.py
@@ -0,0 +1,119 @@
+import re
+import os
+
+
+def get_prerelease_suffix(version):
+    """ Returns the prerelease suffix from the version string argument """
+    def mfunc(m):
+        return " %s %s %s" % (m.group('prefix'),
+                         {'a': 'Alpha', 'b': 'Beta'}[m.group('c')],
+                         m.group('suffix'))
+    result, c = re.subn(r'^(?P<prefix>(\d+\.)*\d+)(?P<c>[ab])(?P<suffix>\d+)(?P<pre>pre)$',
+                      mfunc, version)
+    if c != 1:
+        return ''
+    return result
+
+def _get_pre_release_suffix(base_path):
+    path_ver = os.path.join(base_path,
+                            'browser/config/version.txt')
+    with open(path_ver, 'r') as file:
+        ver = file.read().strip()
+    path2 = os.path.join(base_path,
+                         'config/printprereleasesuffix.py')
+    return get_prerelease_suffix(ver)
+
+def preprocess_browser_xul(source, base_path):
+    prs = _get_pre_release_suffix(base_path)
+    return source.replace('@PRE_RELEASE_SUFFIX@', prs)
+
+files = []
+files.append({
+    'type': 'xul',
+    'path': 'browser/base/content/browser.xul',
+    'dtds': [
+        'browser/locales/en-US/chrome/browser/browser.dtd',
+        'other-licenses/branding/firefox/locales/en-US/brand.dtd',
+        'toolkit/locales/en-US/chrome/global/customizeToolbar.dtd',
+    ],
+    'hooks': {
+        'pre': preprocess_browser_xul
+    }
+})
+files.append({
+    'type': 'xul',
+    'path': 'browser/base/content/macBrowserOverlay.xul',
+    'dtds': [
+        'browser/locales/en-US/chrome/browser/browser.dtd',
+    ]
+})
+files.append({
+    'type': 'xul',
+    'path': 'browser/base/content/browser-sets.inc',
+    'dtds': [
+        'browser/locales/en-US/chrome/browser/browser.dtd',
+    ]
+})
+
+files.append({
+    'type': 'xul',
+    'path': 'browser/base/content/browser-menubar.inc',
+    'dtds': [
+        'browser/locales/en-US/chrome/browser/browser.dtd',
+        'other-licenses/branding/firefox/locales/en-US/brand.dtd',
+        'toolkit/locales/en-US/chrome/global/charsetOverlay.dtd',
+    ]
+})
+files.append({
+    'type': 'xul',
+    'path': 'browser/base/content/browser-context.inc',
+    'dtds': [
+        'browser/locales/en-US/chrome/browser/browser.dtd',
+        'toolkit/locales/en-US/chrome/global/textcontext.dtd',
+    ]
+})
+files.append({
+    'type': 'xul',
+    'path': 'browser/base/content/baseMenuOverlay.xul',
+    'dtds': [
+        'other-licenses/branding/firefox/locales/en-US/brand.dtd',
+        'browser/locales/en-US/chrome/browser/baseMenuOverlay.dtd',
+    ]
+})
+files.append({
+    'type': 'xul',
+    'path': 'browser/components/places/content/placesOverlay.xul',
+    'dtds': [
+        'browser/locales/en-US/chrome/browser/places/places.dtd',
+        'browser/locales/en-US/chrome/browser/browser.dtd',
+    ]
+})
+files.append({
+    'type': 'xul',
+    'path': 'toolkit/content/charsetOverlay.xul',
+    'dtds': [
+        'toolkit/locales/en-US/chrome/global/charsetOverlay.dtd',
+    ]
+})
+files.append({
+    'type': 'xul',
+    'path': 'toolkit/content/editMenuOverlay.xul',
+    'dtds': [
+        'toolkit/locales/en-US/chrome/global/editMenuOverlay.dtd',
+    ]
+})
+files.append({
+    'type': 'xul',
+    'path': 'toolkit/content/macWindowMenu.inc',
+    'dtds': [
+        'browser/locales/en-US/chrome/browser/baseMenuOverlay.dtd',
+    ]
+})
+files.append({
+    'type': 'xul',
+    'path': 'browser/components/safebrowsing/content/blockedSite.xhtml',
+    'dtds': [
+        'dom/locales/en-US/chrome/global.dtd',
+        'browser/locales/en-US/chrome/browser/safebrowsing/phishing-afterload-warning-message.dtd',
+    ]
+})
new file mode 100644
--- /dev/null
+++ b/scripts/l20n/regression/xul.py
@@ -0,0 +1,91 @@
+import re
+import sys
+import os
+
+sys.path.append('../../../../silme/lib')
+
+import silme.core
+import silme.io
+import silme.format
+
+from data import files
+
+silme.format.Manager.register('dtd')
+
+base_path = '/Users/zbraniecki/projects/mozilla/mozilla-central'
+
+patterns = {
+    'xml_entity': re.compile(r'\&([^;\n]+);', re.I),
+    'l10n_id': re.compile(r'l10n_id="([^"]+)"', re.I),
+}
+
+skip_entities = [
+    'amp',
+]
+
+io = silme.io.Manager.get('file')
+
+def dtd2inline(xul, elist):
+    def strip_script(xul):
+        p = re.compile(r'<script.*?<\/script>', re.I|re.M|re.S)
+        return p.subn('', xul)[0]
+
+    def strip_doctype(xul):
+        p = re.compile(r'<!ENTITY.*?>\n?', re.I|re.M|re.S)
+        xul = p.subn('', xul)[0]
+        p = re.compile(r'%[^;]*?;\n?', re.I|re.M|re.S)
+        xul = p.subn('', xul)[0]
+        return xul
+
+    #xul = strip_script(xul)
+    pt = 0
+    match = patterns['xml_entity'].search(xul)
+    while match:
+        eid = match.group(1)
+        pt = match.end(0)
+        if eid in skip_entities:
+            pass
+        elif eid in elist:
+            xul = '%s%s%s' % (xul[:match.start(0)],
+                              dtd2inline(elist[eid].value, elist),
+                              xul[match.end(0):])
+            pt += len(elist[eid].value)-len(match.group(0)) 
+        else:
+            print 'ERROR: Missing entity "%s"' % eid
+        match = patterns['xml_entity'].search(xul, pt)
+    xul = strip_doctype(xul)
+    return xul 
+
+def j20n2inline(xul, elist):
+    pt = 0
+    match = patterns['l10n_id'].search(xul)
+    while match:
+        eid = match.group(1)
+        pt = match.end(0)
+        if eid in elist:
+            params = 'foo'
+            xul = '%s%s%s' % (xul[:match.start(0)],
+                              params,
+                              xul[match.end(0):])
+            pt += len(params)-len(match.group(0))
+        else:
+            print 'ERROR: Missing entity "%s"' % eid
+        match = patterns['l10n_id'].search(xul, pt)
+    return xul
+
+def main():
+    for file in files:
+        xul_path = file['path']
+        dtd_path = file['dtds']
+        xul = io.get_source(os.path.join(base_path, xul_path))[0]
+        if 'hooks' in file and 'pre' in file['hooks']:
+            xul = file['hooks']['pre'](xul, base_path)
+        
+        elist = silme.core.EntityList()
+        for path in dtd_path:
+            elist2 = io.get_entitylist(os.path.join(base_path, path))
+            elist += elist2
+        res = dtd2inline(xul, elist)
+        io.write_source(res, os.path.join(base_path, xul_path), 'utf8')
+
+main()