コード例 #1
0
ファイル: patchdiff.py プロジェクト: L0FKA/PyPatcher
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()
コード例 #2
0
ファイル: patchdiff.py プロジェクト: L0FKA/PyPatcher
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()
コード例 #3
0
ファイル: __init__.py プロジェクト: Simperium/jsondiff
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
コード例 #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)