9 from filecmp
import dircmp
14 from .terminal
import color_diff, color_header
18 D = collections.defaultdict(list)
19 for name
in dcmp.diff_files:
20 D[
'diff'].append(os.path.join(folder, name))
21 for name
in dcmp.left_only:
22 D[
'deleted'].append(os.path.join(folder, name))
23 for name
in dcmp.right_only:
24 D[
'added'].append(os.path.join(folder, name))
26 for sub_dcmp
in dcmp.subdirs.values():
27 sub_f = sub_dcmp.left.replace(dcmp.left,
'')
37 dcmp = dircmp(original_folder, new_folder)
42 return open(os.path.join(folder, filename)).readlines()
45 def print_diff(filename, left_folder=None, right_folder=None):
46 if left_folder
is None:
51 if right_folder
is None:
56 diff = difflib.unified_diff(left, right, fromfile=filename, tofile=
'%s (modified)' % filename)
62 temp_dir = tempfile.mkdtemp()
63 new_package_root = os.path.join(temp_dir, package.name)
64 shutil.copytree(package.root, new_package_root)
65 new_pkg =
Package(new_package_root)
70 if 'sibling_packages' in inspect.getargspec(fne).args:
71 fne(new_pkg, sibling_packages=get_sibling_packages(package))
75 the_diff =
get_diff(package.root, new_package_root)
76 if len(the_diff) == 0:
84 for filename
in the_diff.get(
'diff', []):
85 print_diff(filename, package.root, new_package_root)
86 for filename
in the_diff.get(
'deleted', []):
88 for filename
in the_diff.get(
'added', []):
89 print_diff(filename, right_folder=new_package_root)
91 shutil.rmtree(new_package_root)
92 shutil.copytree(package.root, new_package_root)
93 shutil.rmtree(temp_dir)
98 a_lines = string_a.split(
'\n')
99 b_lines = string_b.split(
'\n')
100 while len(a_lines) < len(b_lines):
102 while len(b_lines) < len(a_lines):
104 return zip(a_lines, b_lines)
def get_diff_helper(dcmp, folder='')
def prepare_diff_lines(string_a, string_b)
def preview_changes(package, fn_name, fne, use_package_name=False)
def get_diff(original_folder, new_folder)
def color_header(s, fore='WHITE', back='BLUE')
def get_lines(folder, filename)
def print_diff(filename, left_folder=None, right_folder=None)