#!/usr/bin/env python

import os, sys, socket

print open(os.environ['SAGE_ROOT'] + '/local/bin/sage-banner').read()

print "Please wait while the Sage Notebook server starts..."

from sage.all import *

def wrap(s):
    """
    INPUT:
        s -- string
    OUTPUT:
        string

    Do nothing to True, False or positive integer.  Wrap everything
    else in a raw triple quoted string.
    """
    if '=' in s:
        v = s.split('=')
        return v[0] + '=' + wrap(v[1])
    if s in ['True', 'False']:
        return s
    if s.isdigit(): return s
    return "r'''%s'''"%s

if len(sys.argv) > 1:
    cmd = "notebook(" + ",".join([wrap(v) for v in sys.argv[1:]]) + ")"
    print cmd
    exec cmd
else:
    notebook()
