Ticket #693: trac_693-spawn-browser-start-nb.patch

File trac_693-spawn-browser-start-nb.patch, 2.8 KB (added by timdumol, 12 years ago)

Modifies sage -notebook to launch a browser window if the notebook is already started. Also adds a sage -nb shortcut.

  • sage-notebook

    #693 Script to spawn a browser/start notebook.
    
    diff -r d0d2608c899a sage-notebook
    a b  
    22
    33import os, sys, socket
    44
    5 print open(os.environ['SAGE_ROOT'] + '/local/bin/sage-banner').read()
    6 
    7 print "Please wait while the Sage Notebook server starts..."
    8 
    9 from sage.server.notebook.all import notebook
    10 
    11 print "..."
    12 
    135def wrap(s):
    146    """
    157    INPUT:
     
    2820    if s.isdigit(): return s
    2921    return "r'''%s'''"%s
    3022
    31 if len(sys.argv) > 1:
    32     cmd = "notebook(" + ",".join([wrap(v) for v in sys.argv[1:]]) + ")"   
    33     print cmd
    34     exec cmd
    35 else:
    36     notebook(port=8000)
     23if __name__ == '__main__':
     24    DOT_SAGENB = os.environ.get('DOT_SAGENB', os.path.join(os.environ['HOME'], '.sage', 'sage_notebook.sagenb'))
     25    SAGENB_PORT = os.environ.get('SAGENB_PORT', '8000')
     26    if os.path.exists(os.path.join(DOT_SAGENB, 'twistd.pid')):
     27       from sage.misc.viewer import viewer, browser
     28       viewer()
     29       os.system(browser() + ' http://localhost:%s' % SAGENB_PORT)
     30       exit(0)
     31
     32    print open(os.environ['SAGE_ROOT'] + '/local/bin/sage-banner').read()
     33    print "Please wait while the Sage Notebook server starts..."
     34    from sage.server.notebook.all import notebook
     35    print "..."
     36    if len(sys.argv) > 1:
     37        cmd = "notebook(port=" + SAGENB_PORT + ",".join([wrap(v) for v in sys.argv[1:]]) + ")"   
     38        print cmd
     39        exec cmd
     40    else:
     41        notebook(port=int(SAGENB_PORT))
     42
  • sage-sage

    diff -r d0d2608c899a sage-sage
    a b  
    88    echo "  -coverage <files>  -- give info about doctest coverage of files"
    99    echo "  -h            -- print this help message"
    1010    echo "  -v, -version  -- print the Sage version"
    11     echo "  -notebook [options] -- start the Sage notebook (options are"
    12     echo "                   the same as to the notebook command in Sage)"
     11    echo "  -notebook [options], -nb [options] -- start the Sage notebook (options are"
     12    echo "                   the same as to the notebook command in Sage)."
     13    echo "                   Opens a browser window with the notebook if the notebook has already started."
    1314    echo "  -inotebook [options] -- start the *insecure* Sage notebook "
    1415    echo "  -i [packages] -- install the given Sage packages"
    1516    echo "  -min ...      -- do not populate global namespace (must be first option)"
     
    510511# Run Sage's versions of the standard Algebra/Geometry etc. software
    511512#####################################################################
    512513
    513 if [ $1 = "-notebook"  -o $1 = '--notebook' ]; then
     514if [ $1 = "-notebook"  -o $1 = '--notebook' -o $1 = '-nb' ]; then
    514515   cd "$CUR"
    515516   shift
    516517   sage-cleaner &