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