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

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

Same thing, without actually checking if the Twistd process is running

  • 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:
    16         s -- string
     8    s -- string
    179    OUTPUT:
    18         string
     10    string
    1911
    2012    Do nothing to True, False or positive integer.  Wrap everything
    2113    else in a raw triple quoted string.
     
    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)
     23def launch_browser_to_nb():
     24    from sage.misc.viewer import viewer, browser
     25    viewer()
     26    os.system(browser() + ' http://localhost:%s' % SAGENB_PORT)
     27    exit(0)
     28   
     29if __name__ == '__main__':
     30    DOT_SAGENB = os.environ.get('DOT_SAGENB', os.path.join(os.environ['HOME'], '.sage', 'sage_notebook.sagenb'))
     31    SAGENB_PORT = os.environ.get('SAGENB_PORT', '8000')
     32    twistd_pid_path = os.path.join(DOT_SAGENB, 'twistd.pid')
     33    if os.path.exists(twistd_pid_path):
     34        launch_browser_to_nb()
     35       
     36    print open(os.environ['SAGE_ROOT'] + '/local/bin/sage-banner').read()
     37    print "Please wait while the Sage Notebook server starts..."
     38    from sage.server.notebook.all import notebook
     39    print "..."
     40    if len(sys.argv) > 1:
     41        cmd = "notebook(" + ",".join([wrap(v) for v in sys.argv[1:]]) + ",port=" + SAGENB_PORT + ")"   
     42        print cmd
     43        exec cmd
     44    else:
     45        notebook(port=int(SAGENB_PORT))
     46
  • 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 &