Example #1
0
    def _merge_header(self, out, base, local, remote):
        def newer(left, right, attribute):
            if self._get_time(left.get(attribute)) >= self._get_time(right.get(attribute)):
                return True
            else:
                return False

        base_dict = poheader.parseheaderstring(base.target)
        local_dict = poheader.parseheaderstring(local.target)
        remote_dict = poheader.parseheaderstring(remote.target)
        out.target = ''
        c = 0

        allkeys = self.merge_list(base_dict.keys(),
                local_dict.keys(), remote_dict.keys())
        for key in allkeys:
            b = base_dict.get(key, None)
            l = local_dict.get(key, None)
            r = remote_dict.get(key, None)
            if b == l:
                res = r
            elif b == r or l == r:
                res = l
            else: # conflict...
                if key in self._template_headers:
                    use_local = newer(local_dict, remote_dict, 'POT-Creation-Date')
                else:
                    use_local = newer(local_dict, remote_dict, 'PO-Revision-Date')
                if use_local:
                    used, other, ofile = local_dict, remote_dict, remote
                else:
                    used, other, ofile = remote_dict, local_dict, local

                res = used.get(key, None)
                out.addnote(u'(conflict) %(file)s (%(project)s): %(key)s: %(value)s' % {
                    'file': _getname(ofile._store, ('remote' if use_local else 'local')),
                    'project': other.get('Project-Id-Version', u'???'),
                    'key': key,
                    'value': other.get(key, u'<unset>'),
                    })
                c = 1
            if res is not None:
                out.target += '%s: %s\n' % (key, res)
        out.markfuzzy(
                self.merge_simple(base.isfuzzy(), local.isfuzzy(),
                        remote.isfuzzy()))
        return c
def test_parseheaderstring():
    """ test for the header parsing function"""
    source = r'''item1: one
item2: two:two
this item must get ignored because there is no colon sign in it
item3: three
'''
    d = poheader.parseheaderstring(source)
    print(type(d))
    assert len(d) == 3
    assert d['item1'] == 'one'
    assert d['item2'] == 'two:two'
    assert d['item3'] == 'three'
Example #3
0
def test_parseheaderstring():
    """test for the header parsing function"""
    source = r"""item1: one
item2: two:two
this item must get ignored because there is no colon sign in it
item3: three
"""
    d = poheader.parseheaderstring(source)
    print(type(d))
    assert len(d) == 3
    assert d["item1"] == "one"
    assert d["item2"] == "two:two"
    assert d["item3"] == "three"
Example #4
0
def test_parseheaderstring():
    """ test for the header parsing function"""
    source = r'''item1: one
item2: two:two
this item must get ignored because there is no colon sign in it
item3: three
'''
    d = poheader.parseheaderstring(source)
    print(type(d))
    assert len(d) == 3
    assert d['item1'] == 'one'
    assert d['item2'] == 'two:two'
    assert d['item3'] == 'three'
Example #5
0
def test_parseheaderstring():
    """ test for the header parsing function"""
    source = r"""item1: one
item2: two:two
this item must get ignored because there is no colon sign in it
item3: three
"""
    d = poheader.parseheaderstring(source)
    print(type(d))
    assert len(d) == 3
    assert d["item1"] == "one"
    assert d["item2"] == "two:two"
    assert d["item3"] == "three"