4 from .terminal
import color_header, color_diff
10 from filecmp
import dircmp
14 D = collections.defaultdict(list)
15 for name
in dcmp.diff_files:
16 D[
'diff'].append(os.path.join(folder, name))
17 for name
in dcmp.left_only:
18 D[
'deleted'].append(os.path.join(folder, name))
19 for name
in dcmp.right_only:
20 D[
'added'].append(os.path.join(folder, name))
22 for sub_dcmp
in dcmp.subdirs.values():
23 sub_f = sub_dcmp.left.replace(dcmp.left,
'')
33 dcmp = dircmp(original_folder, new_folder)
38 return open(os.path.join(folder, filename)).readlines()
41 def print_diff(filename, left_folder=None, right_folder=None):
42 if left_folder
is None:
47 if right_folder
is None:
52 diff = difflib.unified_diff(left, right, fromfile=filename, tofile=
'%s (modified)' % filename)
58 temp_dir = tempfile.mkdtemp()
59 new_package_root = os.path.join(temp_dir, package.name)
60 shutil.copytree(package.root, new_package_root)
61 new_pkg =
Package(new_package_root)
64 the_diff =
get_diff(package.root, new_package_root)
65 if len(the_diff) == 0:
70 for filename
in the_diff.get(
'diff', []):
71 print_diff(filename, package.root, new_package_root)
72 for filename
in the_diff.get(
'deleted', []):
74 for filename
in the_diff.get(
'added', []):
75 print_diff(filename, right_folder=new_package_root)
77 shutil.rmtree(new_package_root)
78 shutil.copytree(package.root, new_package_root)
79 shutil.rmtree(temp_dir)
def get_diff_helper(dcmp, folder='')
def preview_changes(package, fn_name, fne)
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)