diff --git a/IPython/Magic.py b/IPython/Magic.py index 4811d91..37bf234 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 1173 2006-02-21 16:24:01Z vivainio $""" +$Id: Magic.py 1175 2006-02-24 16:34:07Z vivainio $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -43,6 +43,7 @@ except ImportError: profile = pstats = None # Homebrewed +import IPython from IPython import Debugger, OInspect, wildcard from IPython.FakeModule import FakeModule from IPython.Itpl import Itpl, itpl, printpl,itplns @@ -2800,9 +2801,29 @@ Defaulting color scheme to 'NoColor'""" self.user_ns[par] = block print "Block assigned to '%s'" % par def magic_quickref(self,arg): + """ Show a quick reference sheet """ import IPython.usage page(IPython.usage.quick_reference) + def magic_upgrade(self,arg): + """ Upgrade your IPython installation + + This will copy the config files that don't yet exist in your + ipython dir from the system config dir. Use this after upgrading + IPython if you don't wish to delete your .ipython dir. + + """ + ip = self.getapi() + ipinstallation = path(IPython.__file__).dirname() + upgrade_script = ipinstallation / 'upgrade_dir.py' + src_config = ipinstallation / 'UserConfig' + cmd = upgrade_script + " " + src_config + " " + ip.options().ipythondir + print ">",cmd + shell(cmd) + + + + # end Magic diff --git a/IPython/upgrade_dir.py b/IPython/upgrade_dir.py index c8f2d81..3025716 100644 --- a/IPython/upgrade_dir.py +++ b/IPython/upgrade_dir.py @@ -11,7 +11,13 @@ import md5,pickle def showdiff(old,new): import difflib d = difflib.Differ() - print "".join(d.compare(old.lines(),new.lines())) + lines = d.compare(old.lines(),new.lines()) + realdiff = False + for l in lines: + print l, + if not realdiff and not l[0].isspace(): + realdiff = True + return realdiff def upgrade_dir(srcdir, tgtdir): """ Copy over all files in srcdir to tgtdir w/ native line endings @@ -24,12 +30,12 @@ def upgrade_dir(srcdir, tgtdir): print s def ignorable(p): - if p.lower().startswith('.svn') or p.startswith('ipythonrc'): return True return False + modded = [] files = [path(srcdir).relpathto(p) for p in path(srcdir).walkfiles()] #print files rep = tgtdir / '.upgrade_report' @@ -47,21 +53,34 @@ def upgrade_dir(srcdir, tgtdir): pr("Creating %s" % str(tgt)) tgt.write_text(src.text()) - rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest() + rpt[str(tgt)] = md5.new(tgt.text()).hexdigest() else: - cont = tgt.bytes() + cont = tgt.text() sum = rpt.get(str(tgt), None) #print sum if sum and md5.new(cont).hexdigest() == sum: pr("Unedited, installing new %s" % tgt) - rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest() + rpt[str(tgt)] = md5.new(tgt.text()).hexdigest() else: - pr('Modified, skipping %s, diffs below' % tgt) + pr(' == Modified, skipping %s, diffs below == ' % tgt) #rpt[str(tgt)] = md5.new(tgt.bytes()).hexdigest() - showdiff(tgt,src) - pass + real = showdiff(tgt,src) + if not real: + print "(Ok, it wasn't that different at all, upgrading checksum)" + rpt[str(tgt)] = md5.new(tgt.text()).hexdigest() + else: + modded.append(tgt) + #print rpt pickle.dump(rpt, rep.open('w')) + if modded: + print "\n\nDelete the following files manually if you need a full upgrade:" + for m in modded: + print m + import sys -upgrade_dir(path(sys.argv[1]), path(sys.argv[2])) \ No newline at end of file +if __name__ == "__main__": + upgrade_dir(path(sys.argv[1]), path(sys.argv[2])) + + \ No newline at end of file