Commits

Axel Hecht  committed a63c2f7

Actually tweak the extension to be gaia-l10n specific.
We're hardcoding the migration patterns to apps, shared, and parse
the manifest.webapp into properties.

  • Participants
  • Parent commits 652bd22

Comments (0)

Files changed (3)

File gaiaconv/convcmd.py

     if sortmode == 'closesort' and not srcc.hasnativeclose():
         raise util.Abort(_('--closesort is not supported by this data source'))
 
-    fmap = opts.get('filemap')
-    if fmap:
-        srcc = filemap.filemap_source(ui, srcc, fmap)
-        destc.setfilemapmode(True)
+    srcc = filemap.filemap_source(ui, srcc)
+    destc.setfilemapmode(True)
 
     if not revmapfile:
         try:

File gaiaconv/filemap.py

     A name can be mapped to itself, a new name, or None (omit from new
     repository).'''
 
-    def __init__(self, ui, path=None):
+    def __init__(self, ui):
         self.ui = ui
-        self.include = {}
-        self.exclude = {}
-        self.rename = {}
-        if path:
-            if self.parse(path):
-                raise util.Abort(_('errors in filemap'))
-
-    def parse(self, path):
-        errs = 0
-        def check(name, mapping, listname):
-            if not name:
-                self.ui.warn(_('%s:%d: path to %s is missing\n') %
-                             (lex.infile, lex.lineno, listname))
-                return 1
-            if name in mapping:
-                self.ui.warn(_('%s:%d: %r already in %s list\n') %
-                             (lex.infile, lex.lineno, name, listname))
-                return 1
-            if (name.startswith('/') or
-                name.endswith('/') or
-                '//' in name):
-                self.ui.warn(_('%s:%d: superfluous / in %s %r\n') %
-                             (lex.infile, lex.lineno, listname, name))
-                return 1
-            return 0
-        lex = shlex.shlex(open(path), path, True)
-        lex.wordchars += '!@#$%^&*()-=+[]{}|;:,./<>?'
-        cmd = lex.get_token()
-        while cmd:
-            if cmd == 'include':
-                name = normalize(lex.get_token())
-                errs += check(name, self.exclude, 'exclude')
-                self.include[name] = name
-            elif cmd == 'exclude':
-                name = normalize(lex.get_token())
-                errs += check(name, self.include, 'include')
-                errs += check(name, self.rename, 'rename')
-                self.exclude[name] = name
-            elif cmd == 'rename':
-                src = normalize(lex.get_token())
-                dest = normalize(lex.get_token())
-                errs += check(src, self.exclude, 'exclude')
-                self.rename[src] = dest
-            elif cmd == 'source':
-                errs += self.parse(normalize(lex.get_token()))
-            else:
-                self.ui.warn(_('%s:%d: unknown directive %r\n') %
-                             (lex.infile, lex.lineno, cmd))
-                errs += 1
-            cmd = lex.get_token()
-        return errs
-
-    def lookup(self, name, mapping):
-        name = normalize(name)
-        for pre, suf in rpairs(name):
-            try:
-                return mapping[pre], pre, suf
-            except KeyError:
-                pass
-        return '', name, ''
 
     def __call__(self, name):
-        if self.include:
-            inc = self.lookup(name, self.include)[0]
-        else:
-            inc = name
-        if self.exclude:
-            exc = self.lookup(name, self.exclude)[0]
-        else:
-            exc = ''
-        if (not self.include and exc) or (len(inc) <= len(exc)):
-            return None
-        newpre, pre, suf = self.lookup(name, self.rename)
-        if newpre:
-            if newpre == '.':
-                return suf
-            if suf:
-                if newpre.endswith('/'):
-                    return newpre + suf
-                return newpre + '/' + suf
-            return newpre
-        return name
+        # map apps/browser/locales/browser.en-US.properties
+        # to apps/browser/browser.properties and
+        # map apps/browser/manifest.webapp to ..manifest.properties
+        # The content of manifest.properties is rewritten in
+        # hg.mercurial_source.get_file
+        _name = normalize(name)
+        is_prop = _name.endswith('.en-US.properties')
+        is_manifest = _name.endswith('/manifest.webapp')
+        if is_prop or is_manifest:
+            for d in ('branding/official', '_apps', '-apps'):
+                if d in _name:
+                    return None
+            if is_prop:
+                return _name.replace('.en-US', '').replace('/locales', '')
+            return _name.replace('.webapp', '.properties')
+        return None
 
     def active(self):
-        return bool(self.include or self.exclude or self.rename)
+        # we're always active
+        return True
 
 # This class does two additional things compared to a regular source:
 #
 #   or more interesting revisions.
 
 class filemap_source(converter_source):
-    def __init__(self, ui, baseconverter, filemap):
+    def __init__(self, ui, baseconverter):
         super(filemap_source, self).__init__(ui)
         self.base = baseconverter
-        self.filemapper = filemapper(ui, filemap)
+        self.filemapper = filemapper(ui)
         self.commits = {}
         # if a revision rev has parent p in the original revision graph, then
         # rev will have parent self.parentmap[p] in the restricted graph.

File gaiaconv/hg.py

 #   source.
 
 
-import os, time, cStringIO
+import os, time, cStringIO, json
 from mercurial.i18n import _
 from mercurial.node import bin, hex, nullid
 from mercurial import hg, util, context, bookmarks, error
             text = "(octopus merge fixup)\n"
             p2 = hex(self.repo.changelog.tip())
 
-        if self.filemapmode and nparents == 1:
+        # switch off the no-change changeset check
+        # we're cool with that in particular for manifests
+        if False and self.filemapmode and nparents == 1:
             man = self.repo.manifest
             mnode = self.repo.changelog.read(bin(p2))[0]
             closed = 'close' in commit.extra
     def getfile(self, name, rev):
         try:
             fctx = self.changectx(rev)[name]
-            return fctx.data(), fctx.flags()
+            data = fctx.data()
+            if name.endswith('manifest.webapp'):
+                # GAIA special, convert json to .properties
+                try:
+                    manifest_webapp = json.loads(data)
+                except ValueError:
+                    manifest_webapp = {}
+                lines = []
+                # manifest can either be a top-level app or
+                # have entry points, notably happening in
+                # the communications apps.
+                if ('entry_points' in manifest_webapp):
+                    data_list = manifest_webapp['entry_points'].iteritems()
+                else:
+                    data_list = [(None, manifest_webapp)]
+                for ep, entry_data in data_list:
+                    if ('locales' in entry_data and
+                        'en-US' in entry_data['locales']):
+                        _data = entry_data['locales']['en-US']
+                        if ep:
+                            lines.append('%s.name=%s\n' % (ep, _data['name']))
+                            lines.append('%s.description=%s\n' %
+                                         (ep, _data['description']))
+                        else:
+                            lines.append('name=%s\n' % _data['name'])
+                            lines.append('description=%(description)s\n' %
+                                         _data)
+                data = ''.join(lines)
+            return data, fctx.flags()
         except error.LookupError, err:
             raise IOError(err)