2
""" A script/util to upgrade all files in a directory
4
This is rather conservative in its approach, only copying/overwriting
5
new and unedited files.
7
To be used by "upgrade" feature.
10
from IPython.external.path import path
16
def showdiff(old,new):
19
lines = d.compare(old.lines(),new.lines())
23
if not realdiff and not l[0].isspace():
27
def upgrade_dir(srcdir, tgtdir):
28
""" Copy over all files in srcdir to tgtdir w/ native line endings
30
Creates .upgrade_report in tgtdir that stores md5sums of all files
31
to notice changed files b/w upgrades.
36
junk = ['.svn','ipythonrc*','*.pyc', '*.pyo', '*~', '.hg']
40
if p.startswith(pat) or p.fnmatch(pat):
45
files = [path(srcdir).relpathto(p) for p in path(srcdir).walkfiles()]
47
rep = tgtdir / '.upgrade_report'
49
rpt = pickle.load(rep.open())
59
pr("Creating %s" % str(tgt))
61
tgt.write_text(src.text())
62
rpt[str(tgt)] = md5.new(tgt.text()).hexdigest()
65
sum = rpt.get(str(tgt), None)
67
if sum and md5.new(cont).hexdigest() == sum:
68
pr("%s: Unedited, installing new version" % tgt)
69
tgt.write_text(src.text())
70
rpt[str(tgt)] = md5.new(tgt.text()).hexdigest()
72
pr(' == Modified, skipping %s, diffs below == ' % tgt)
73
#rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest()
74
real = showdiff(tgt,src)
77
pr("(Ok, it was identical, only upgrading checksum)")
78
rpt[str(tgt)] = md5.new(tgt.text()).hexdigest()
83
pickle.dump(rpt, rep.open('w'))
85
print "\n\nDelete the following files manually (and rerun %upgrade)\nif you need a full upgrade:"
91
if __name__ == "__main__":
92
upgrade_dir(path(sys.argv[1]), path(sys.argv[2]))