Show More
@@ -1,66 +1,67 b'' | |||
|
1 | 1 | """ A script/util to upgrade all files in a directory |
|
2 | 2 | |
|
3 | 3 | This is rather conservative in its approach, only copying/overwriting |
|
4 | 4 | new and unedited files. |
|
5 | 5 | |
|
6 | 6 | To be used by "upgrade" feature. |
|
7 | 7 | """ |
|
8 | 8 | from path import path |
|
9 | 9 | import md5,pickle |
|
10 | 10 | |
|
11 | 11 | def showdiff(old,new): |
|
12 | 12 | import difflib |
|
13 | 13 | d = difflib.Differ() |
|
14 | 14 | print "".join(d.compare(old.lines(),new.lines())) |
|
15 | 15 | |
|
16 | 16 | def upgrade_dir(srcdir, tgtdir): |
|
17 | 17 | """ Copy over all files in srcdir to tgtdir w/ native line endings |
|
18 | 18 | |
|
19 | 19 | Creates .upgrade_report in tgtdir that stores md5sums of all files |
|
20 | 20 | to notice changed files b/w upgrades. |
|
21 | 21 | """ |
|
22 | 22 | |
|
23 | 23 | def pr(s): |
|
24 | 24 | print s |
|
25 | 25 | |
|
26 | 26 | def ignorable(p): |
|
27 | if p.lower().startswith('.svn'): | |
|
27 | ||
|
28 | if p.lower().startswith('.svn') or p.startswith('ipythonrc'): | |
|
28 | 29 | return True |
|
29 | 30 | return False |
|
30 | 31 | |
|
31 | 32 | |
|
32 | 33 | files = [path(srcdir).relpathto(p) for p in path(srcdir).walkfiles()] |
|
33 | 34 | #print files |
|
34 | 35 | rep = tgtdir / '.upgrade_report' |
|
35 | 36 | try: |
|
36 | 37 | rpt = pickle.load(rep.open()) |
|
37 | 38 | except: |
|
38 | 39 | rpt = {} |
|
39 | 40 | |
|
40 | 41 | for f in files: |
|
41 | 42 | if ignorable(f): |
|
42 | 43 | continue |
|
43 | 44 | src = srcdir / f |
|
44 | 45 | tgt = tgtdir / f |
|
45 | 46 | if not tgt.isfile(): |
|
46 | 47 | pr("Creating %s" % str(tgt)) |
|
47 | 48 | |
|
48 | 49 | tgt.write_text(src.text()) |
|
49 | 50 | rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest() |
|
50 | 51 | else: |
|
51 | 52 | cont = tgt.bytes() |
|
52 | 53 | sum = rpt.get(str(tgt), None) |
|
53 | 54 | #print sum |
|
54 | 55 | if sum and md5.new(cont).hexdigest() == sum: |
|
55 | 56 | pr("Unedited, installing new %s" % tgt) |
|
56 | 57 | rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest() |
|
57 | 58 | else: |
|
58 | 59 | pr('Modified, skipping %s, diffs below' % tgt) |
|
59 | 60 | #rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest() |
|
60 | 61 | showdiff(tgt,src) |
|
61 | 62 | pass |
|
62 | 63 | #print rpt |
|
63 | 64 | pickle.dump(rpt, rep.open('w')) |
|
64 | 65 | |
|
65 | 66 | import sys |
|
66 | 67 | upgrade_dir(path(sys.argv[1]), path(sys.argv[2])) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now