I wrote StdOutContext for use cases like this actually. Particularly, to capture the protocol of a GB computation:
in sage.rings.polynomial.multi_polynomial_ideal: from sage.interfaces.magma import MagmaGBLogPrettyPrinter if prot: log_parser = MagmaGBLogPrettyPrinter(verbosity=get_verbose()+ 1, style="sage" if prot=="sage" else "magma") else: log_parser = None ctx = StdOutContext(magma, silent=False if prot else True, stdout=log_parser) if prot: magma.SetVerbose('Groebner',1) with ctx: if deg_bound: mgb = mself.GroebnerBasis(deg_bound) else: mgb = mself.GroebnerBasis() if prot == "sage": print print "Highest degree reached during computation: %2d."%log_parser.max_deg The idea is to have StdOutContext to dump everything on whatever is given as the stdout parameter which can then perform further postprocessing. The GB pretty printer actually almost does what you want I think: sage: magma.SetVerbose("Factorization",1) sage: from sage.interfaces.magma import MagmaGBLogPrettyPrinter sage: log_parser = MagmaGBLogPrettyPrinter(verbosity=1,style='magma') sage: ctx = StdOutContext(magma,stdout=log_parser) sage: with ctx: ....: magma.Factorization( 56654654654464) ....: _sage_ := [* *]; _sage_ := [* *]; Integer main factorization (primality of factors will be proved) Effort: 3 Seed: 3463036751 0 Number: 56654654654464 Entering SQUFOF 27663405593 [ <2, 11>, <1289, 1>, <21461137, 1> ] [ <2, 11>, <1289, 1>, <21461137, 1> ] Perhaps there should be MagmaLogPrettyPrinter which does the filtering from which MagmaGBLogPrettyPrinter then inherits and to which it adds its parsing? On Thursday 15 December 2011, William Stein wrote: > On Wed, Dec 14, 2011 at 4:13 PM, David Roe <r...@math.harvard.edu> wrote: > > I helping a colleague try to wrap some magma code that uses verbose > > print statements. Apparently, just setting the verbose flag is not > > enough: > > > > sage: magma.SetVerbose("Factorization",1) > > sage: magma.Factorization(56654654654464) > > [ <2, 11>, <1289, 1>, <21461137, 1> ] > > > > Instead, you have to use StdOutContext, which prints a whole bunch of > > > extra stuff: > What is "StdOutContext"? > > wstein@ubuntu:chow_heeegner$ sage > ---------------------------------------------------------------------- > > | Sage Version 4.8.alpha5, Release Date: 2011-12-13 | > | Type notebook() for the GUI, and license() for information. | > > ---------------------------------------------------------------------- > ********************************************************************** > * * > * Warning: this is a prerelease version, and it may be unstable. * > * * > ********************************************************************** > Loading Sage library. Current Mercurial branch is: pre4260 > sage: StdOutContext > NameError: name 'StdOutContext' is not defined > > -- > > sage: from sage.interfaces.expect import StdOutContext > sage: StdOutContext? > ... > Construct a new context in which all communation between Sage and a > subprocess interfaced via pexpect is printed to stdout. > > ----------- > > Wow, that's pretty cool. I didn't know about this feature. Anyway, > here is how to get what you want to work: > > sage: magma.SetVerbose("Factorization",1) > sage: print magma.eval('Factorization(56654654654464)') > Integer main factorization (primality of factors will be proved) > Effort: 3 > Seed: 2503141013 0 > Number: 56654654654464 > Entering SQUFOF 27663405593 > [ <2, 11>, <1289, 1>, <21461137, 1> ] > > -- > > Using this doesn't work > > sage: magma.Factorization(56654654654464) > [ <2, 11>, <1289, 1>, <21461137, 1> ] > > ... since it really (1) makes the variable _sage_[3] in the Magma > session, ignoring all printed output: > > sage: s = magma.Factorization(56654654654464) > sage: s.name() > '_sage_[3]' > > ... *then*, prints out the string repr of _sage_[3] > > sage: s > [ <2, 11>, <1289, 1>, <21461137, 1> ] > > > It would be interesting and desirable to make SetVerbose somehow do > something differently, but I have no idea how this could be made to > fit into the current expect framework. Nobody has ever requested > this before, as far as I know, so it's probably not a huge issue. > > -- William > > > sage: with StdOutContext(magma): > > ....: magma.Factorization( 56654654654464) > > ....: > > Append(~_sage_, 0); > > Append(~_sage_, 0); > > > >>>>_sage_[5]:=56654654654464; > > > > _sage_[5]:=56654654654464; > > > >>>>Append(~_sage_, 0); > > > > Append(~_sage_, 0); > > > >>>>_sage_[9]:=Factorization(_sage_[5]); > > > > _sage_[9]:=Factorization(_sage_[5]); > > Integer main factorization (primality of factors will be proved) > > Effort: 3 > > Seed: 1 168527 > > Number: 56654654654464 > > Entering SQUFOF 27663405593 > > > >>>>_sage_[5]:=0; > > > > _sage_[5]:=0; > > > >>>>_sage_[9]; > > > > _sage_[9]; > > [ <2, 11>, <1289, 1>, <21461137, 1> ] > > > >>>>[ <2, 11>, <1289, 1>, <21461137, 1> ] > > > > It seems like SetVerbose for magma is broken; is there something I'm > > missing? David > > > > -- > > To post to this group, send an email to sage-devel@googlegroups.com > > To unsubscribe from this group, send an email to > > sage-devel+unsubscr...@googlegroups.com For more options, visit this > > group at http://groups.google.com/group/sage-devel URL: > > http://www.sagemath.org Cheers, Martin -- name: Martin Albrecht _pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99 _otr: 47F43D1A 5D68C36F 468BAEBA 640E8856 D7951CCF _www: http://martinralbrecht.wordpress.com/ _jab: martinralbre...@jabber.ccc.de -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org