Esempio n. 1
0
def _genTextPatch(old, new, patch):
    oldTxt = _getFileContents(old)
    newTxt = _getFileContents(new)
    
    o = diff_match_patch()
    patchTxt = o.patch_toText(o.patch_make(oldTxt, newTxt))

    _mkdirs(os.path.dirname(patch))
    f = open(patch, 'w')
    f.write(patchTxt)
    f.close()
Esempio n. 2
0
def _patchText(src, out, patch):
    o = diff_match_patch()
    txt = _getFileContents(src)
    patchTxt = _getFileContents(patch)

    #the result object is a tuple, the first element
    #is the patched text and the second is an array
    #of boolean values indicating which patches
    #were applied
    result = o.patch_apply(o.patch_fromText(patchTxt), txt)

    if not all(result[1]):
        raise PatchError(('Not all patches were applied when patching'
                        + 'the file ' + src + ' with patch ' + patch))

    outTxt = result[0]
    
    _mkdirs(os.path.dirname(out))
    f = open(out, 'w')
    f.write(outTxt)
    f.close()
Esempio n. 3
0
Created by Fred Cheng on 2011-02-21.
Copyright (c) 2011 Simperium, Inc. All rights reserved.
"""

import sys
import os
import copy
import json
import dmp_patch

from diffmatchpatch import diff_match_patch

dmp_patch.monkey()

DMP = diff_match_patch()

OTYPE_MAP = {
    "replace": ["+", "-", "r"],
    "list": ["+", "-", "L"],
    "list_dmp": ["+", "-", "dL"],
    "integer": ["+", "-", "I"],
    "string": ["+", "-", "d"],
}


def same_type(a, b):
    if isinstance(a, basestring) and isinstance(b, basestring):
        return True
    if (type(a) == bool and type(b) == int) or (type(a) == int and type(b) == bool):
        return True
Esempio n. 4
0
Created by Fred Cheng on 2011-02-21.
Copyright (c) 2011 Simperium, Inc. All rights reserved.
"""

import sys
import os
import copy
import json
import dmp_patch

from diffmatchpatch import diff_match_patch

dmp_patch.monkey()

DMP = diff_match_patch()

OTYPE_MAP = {
    'replace'   : [ '+', '-', 'r' ],
    'list'      : [ '+', '-', 'L' ],
    'list_dmp'  : [ '+', '-', 'dL' ],
    'integer'   : [ '+', '-', 'I' ],
    'string'    : [ '+', '-', 'd' ],
    }

def same_type(a, b):
    if isinstance(a, basestring) and isinstance(b, basestring):
        return True
    if (type(a) == bool and type(b) == int) or (type(a) == int and type(b) == bool):
        return True
    return type(a) == type(b)