##// END OF EJS Templates
%upgrade
vivainio -
Show More
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 1173 2006-02-21 16:24:01Z vivainio $"""
4 $Id: Magic.py 1175 2006-02-24 16:34:07Z vivainio $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -43,6 +43,7 b' except ImportError:'
43 profile = pstats = None
43 profile = pstats = None
44
44
45 # Homebrewed
45 # Homebrewed
46 import IPython
46 from IPython import Debugger, OInspect, wildcard
47 from IPython import Debugger, OInspect, wildcard
47 from IPython.FakeModule import FakeModule
48 from IPython.FakeModule import FakeModule
48 from IPython.Itpl import Itpl, itpl, printpl,itplns
49 from IPython.Itpl import Itpl, itpl, printpl,itplns
@@ -2800,9 +2801,29 b' Defaulting color scheme to \'NoColor\'"""'
2800 self.user_ns[par] = block
2801 self.user_ns[par] = block
2801 print "Block assigned to '%s'" % par
2802 print "Block assigned to '%s'" % par
2802 def magic_quickref(self,arg):
2803 def magic_quickref(self,arg):
2804 """ Show a quick reference sheet """
2803 import IPython.usage
2805 import IPython.usage
2804 page(IPython.usage.quick_reference)
2806 page(IPython.usage.quick_reference)
2805
2807
2808 def magic_upgrade(self,arg):
2809 """ Upgrade your IPython installation
2810
2811 This will copy the config files that don't yet exist in your
2812 ipython dir from the system config dir. Use this after upgrading
2813 IPython if you don't wish to delete your .ipython dir.
2814
2815 """
2816 ip = self.getapi()
2817 ipinstallation = path(IPython.__file__).dirname()
2818 upgrade_script = ipinstallation / 'upgrade_dir.py'
2819 src_config = ipinstallation / 'UserConfig'
2820 cmd = upgrade_script + " " + src_config + " " + ip.options().ipythondir
2821 print ">",cmd
2822 shell(cmd)
2823
2824
2825
2826
2806
2827
2807
2828
2808 # end Magic
2829 # end Magic
@@ -11,7 +11,13 b' import md5,pickle'
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 lines = d.compare(old.lines(),new.lines())
15 realdiff = False
16 for l in lines:
17 print l,
18 if not realdiff and not l[0].isspace():
19 realdiff = True
20 return realdiff
15
21
16 def upgrade_dir(srcdir, tgtdir):
22 def upgrade_dir(srcdir, tgtdir):
17 """ Copy over all files in srcdir to tgtdir w/ native line endings
23 """ Copy over all files in srcdir to tgtdir w/ native line endings
@@ -24,12 +30,12 b' def upgrade_dir(srcdir, tgtdir):'
24 print s
30 print s
25
31
26 def ignorable(p):
32 def ignorable(p):
27
28 if p.lower().startswith('.svn') or p.startswith('ipythonrc'):
33 if p.lower().startswith('.svn') or p.startswith('ipythonrc'):
29 return True
34 return True
30 return False
35 return False
31
36
32
37
38 modded = []
33 files = [path(srcdir).relpathto(p) for p in path(srcdir).walkfiles()]
39 files = [path(srcdir).relpathto(p) for p in path(srcdir).walkfiles()]
34 #print files
40 #print files
35 rep = tgtdir / '.upgrade_report'
41 rep = tgtdir / '.upgrade_report'
@@ -47,21 +53,34 b' def upgrade_dir(srcdir, tgtdir):'
47 pr("Creating %s" % str(tgt))
53 pr("Creating %s" % str(tgt))
48
54
49 tgt.write_text(src.text())
55 tgt.write_text(src.text())
50 rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest()
56 rpt[str(tgt)] = md5.new(tgt.text()).hexdigest()
51 else:
57 else:
52 cont = tgt.bytes()
58 cont = tgt.text()
53 sum = rpt.get(str(tgt), None)
59 sum = rpt.get(str(tgt), None)
54 #print sum
60 #print sum
55 if sum and md5.new(cont).hexdigest() == sum:
61 if sum and md5.new(cont).hexdigest() == sum:
56 pr("Unedited, installing new %s" % tgt)
62 pr("Unedited, installing new %s" % tgt)
57 rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest()
63 rpt[str(tgt)] = md5.new(tgt.text()).hexdigest()
58 else:
64 else:
59 pr('Modified, skipping %s, diffs below' % tgt)
65 pr(' == Modified, skipping %s, diffs below == ' % tgt)
60 #rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest()
66 #rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest()
61 showdiff(tgt,src)
67 real = showdiff(tgt,src)
62 pass
68 if not real:
69 print "(Ok, it wasn't that different at all, upgrading checksum)"
70 rpt[str(tgt)] = md5.new(tgt.text()).hexdigest()
71 else:
72 modded.append(tgt)
73
63 #print rpt
74 #print rpt
64 pickle.dump(rpt, rep.open('w'))
75 pickle.dump(rpt, rep.open('w'))
76 if modded:
77 print "\n\nDelete the following files manually if you need a full upgrade:"
78 for m in modded:
79 print m
80
65
81
66 import sys
82 import sys
67 upgrade_dir(path(sys.argv[1]), path(sys.argv[2])) No newline at end of file
83 if __name__ == "__main__":
84 upgrade_dir(path(sys.argv[1]), path(sys.argv[2]))
85
86 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now