Beispiel #1
0
def main():
    quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
    
    print_version(is_server=False)
    print_license()
    print u"Quit by pressing %s" % quit_command
    
    print ''
    
    definitions = Definitions(add_builtin=True)
    
    try:
        while True:
            input = raw_input('>> ')
            
            def out_callback(out):
                print to_output(unicode(out))
                
            evaluation = Evaluation(input, definitions, timeout=30, out_callback=out_callback)
            
            for result in evaluation.results:
                if result.result is not None:
                    print ' = %s' % to_output(unicode(result.result))
    except (KeyboardInterrupt, SystemExit):
        print "\n\nGood bye!\n"
Beispiel #2
0
def main():
    os.environ['DJANGO_SETTINGS_MODULE'] = 'mathics.settings'
    #os.putenv('DJANGO_SETTINGS_MODULE', 'mathics.settings')
    
    from django.conf import settings
    from django.core.servers.basehttp import run, WSGIServerException
    from django.core.handlers.wsgi import WSGIHandler
    
    parser = OptionParser(version='%prog ' + settings.VERSION,
        description="Mathics server for the graphical user interface in Firefox. It is not intended for production use on a public Web server!")
    parser.add_option("-p", "--port", dest="port", metavar="PORT", default=8000, type='int',
        help="use PORT as server port")
    parser.add_option("-e", "--external", dest="external", action="store_true",
        help="allow external access to server")
    options, args = parser.parse_args()
            
    print_version(is_server=True)
    print_license()
    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-C'
    print u"Quit by pressing %s\n" % quit_command
    
    port = options.port
    print u"Open the graphical user interface at\nhttp://localhost:%d\nin Firefox, Chrome, or Safari to use Mathics\n" % port
    
    if options.external:
        addr = '0.0.0.0'
    else:
        addr = ''
    
    try:
        if settings.DJANGO_VERSION < (1, 4):
            from django.core.servers.basehttp import AdminMediaHandler
            handler = AdminMediaHandler(WSGIHandler(), '')
        else:
            from django.core.servers.basehttp import get_internal_wsgi_application
            handler = get_internal_wsgi_application()
        run(addr, port, handler)
    except WSGIServerException, e:
        # Use helpful error messages instead of ugly tracebacks.
        ERRORS = {
            13: "You don't have permission to access that port.",
            98: "That port is already in use.",
            99: "That IP address can't be assigned to.",
        }
        try:
            error_text = ERRORS[e.args[0].args[0]]
        except (AttributeError, KeyError):
            error_text = str(e)
        sys.stderr.write("Error: %s" % error_text + '\n')
        # Need to use an OS exit because sys.exit doesn't work in a thread
        os._exit(1)
Beispiel #3
0
def main():
    os.environ['DJANGO_SETTINGS_MODULE'] = 'mathics.settings'
    #os.putenv('DJANGO_SETTINGS_MODULE', 'mathics.settings')
    
    from django.conf import settings
    from django.core.servers.basehttp import run, AdminMediaHandler, WSGIServerException
    from django.core.handlers.wsgi import WSGIHandler
    
    parser = OptionParser(version='%prog ' + settings.VERSION,
        description="Mathics server for the graphical user interface in Firefox. It is not intended for production use on a public Web server!")
    parser.add_option("-p", "--port", dest="port", metavar="PORT", default=8000, type='int',
        help="use PORT as server port")
    parser.add_option("-e", "--external", dest="external", action="store_true",
        help="allow external access to server")
    options, args = parser.parse_args()
            
    print_version(is_server=True)
    print_license()
    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-C'
    print u"Quit by pressing %s\n" % quit_command
    
    port = options.port
    print u"Open the graphical user interface at\nhttp://localhost:%d\nin Firefox, Chrome, or Safari to use Mathics\n" % port
    
    if options.external:
        addr = '0.0.0.0'
    else:
        addr = ''
    
    try:
        handler = AdminMediaHandler(WSGIHandler(), '')
        run(addr, port, handler)
    except WSGIServerException, e:
        # Use helpful error messages instead of ugly tracebacks.
        ERRORS = {
            13: "You don't have permission to access that port.",
            98: "That port is already in use.",
            99: "That IP address can't be assigned to.",
        }
        try:
            error_text = ERRORS[e.args[0].args[0]]
        except (AttributeError, KeyError):
            error_text = str(e)
        sys.stderr.write("Error: %s" % error_text + '\n')
        # Need to use an OS exit because sys.exit doesn't work in a thread
        os._exit(1)
Beispiel #4
0
def launch_app(args):
    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-C'
    port = args.port

    if not args.quiet:
        print_version(is_server=True)
        print_license()
        print u"Quit by pressing %s\n" % quit_command

        print u"""Open the graphical user interface at
http://localhost:%d\nin Firefox, Chrome, or Safari to use Mathics\n""" % port

    if args.external:
        addr = '0.0.0.0'
    else:
        addr = '127.0.0.1'

    try:
        from django.core.servers.basehttp import (run,
                                                  get_internal_wsgi_application
                                                  )
        handler = get_internal_wsgi_application()
        run(addr, port, handler)
    except socket.error as e:
        # Use helpful error messages instead of ugly tracebacks.
        ERRORS = {
            errno.EACCES: "You don't have permission to access that port.",
            errno.EADDRINUSE: "That port is already in use.",
            errno.EADDRNOTAVAIL: "That IP address can't be assigned to.",
        }
        try:
            error_text = ERRORS[e.errno]
        except KeyError:
            error_text = str(e)
        sys.stderr.write("Error: %s" % error_text + '\n')
        # Need to use an OS exit because sys.exit doesn't work in a thread
        os._exit(1)
    except KeyboardInterrupt:
        print "\nGoodbye!\n"
        sys.exit(0)
Beispiel #5
0
def launch_app(args):
    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-C'
    port = args.port

    if not args.quiet:
        print_version(is_server=True)
        print_license()
        print u"Quit by pressing %s\n" % quit_command

        print u"""Open the graphical user interface at
http://localhost:%d\nin Firefox, Chrome, or Safari to use Mathics\n""" % port

    if args.external:
        addr = '0.0.0.0'
    else:
        addr = '127.0.0.1'

    try:
        from django.core.servers.basehttp import (
            run, get_internal_wsgi_application)
        handler = get_internal_wsgi_application()
        run(addr, port, handler)
    except socket.error as e:
        # Use helpful error messages instead of ugly tracebacks.
        ERRORS = {
            errno.EACCES: "You don't have permission to access that port.",
            errno.EADDRINUSE: "That port is already in use.",
            errno.EADDRNOTAVAIL: "That IP address can't be assigned to.",
        }
        try:
            error_text = ERRORS[e.errno]
        except KeyError:
            error_text = str(e)
        sys.stderr.write("Error: %s" % error_text + '\n')
        # Need to use an OS exit because sys.exit doesn't work in a thread
        os._exit(1)
    except KeyboardInterrupt:
        print "\nGoodbye!\n"
        sys.exit(0)
Beispiel #6
0
def main():
    argparser = argparse.ArgumentParser(
        prog='mathics',
        usage='%(prog)s [options] [FILE]',
        add_help=False,
        description="Mathics is a general-purpose computer algebra system.",
        epilog="""Please feel encouraged to contribute to Mathics! Create
            your own fork, make the desired changes, commit, and make a pull 
            request.""")

    argparser.add_argument('FILE',
                           nargs='?',
                           type=argparse.FileType('r'),
                           help='execute commands from FILE')
    argparser.add_argument('--help',
                           '-h',
                           help='show this help message and exit',
                           action='help')
    argparser.add_argument(
        '--persist',
        help='go to interactive shell after evaluating FILE',
        action='store_true')
    argparser.add_argument('--quiet',
                           '-q',
                           help='don\'t print message at startup',
                           action='store_true')
    argparser.add_argument('-script',
                           help='run a mathics file in script mode',
                           action='store_true')
    argparser.add_argument('--execute',
                           '-e',
                           nargs='?',
                           help='execute a command')
    argparser.add_argument('--colors',
                           nargs='?',
                           help='interactive shell colors')
    argparser.add_argument('--version',
                           '-v',
                           action='version',
                           version=get_version_string(False))
    args = argparser.parse_args()

    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D'

    definitions = Definitions(add_builtin=True)
    definitions.set_ownvalue('$Line', Integer(1))  #Reset the line number to 1

    shell = TerminalShell(definitions, args.colors)

    if not (args.quiet or args.script):
        print_version(is_server=False)
        print_license()
        print u"Quit by pressing {0}\n".format(quit_command)

    if args.execute:
        total_input = args.execute.decode(sys.stdin.encoding)  # check encoding
        print shell.get_in_prompt() + total_input
        shell.evaluate(total_input)
        return

    if args.FILE is not None:
        total_input = ''
        for line_no, line in enumerate(args.FILE):
            try:
                line = line.decode('utf-8')  # TODO: other encodings
                if args.script and line_no == 0 and line.startswith('#!'):
                    continue
                print shell.get_in_prompt(
                    continued=(total_input != '')) + line,
                total_input += ' ' + line
                if line != "" and wait_for_line(total_input):
                    continue
                shell.evaluate(total_input)
                total_input = ""
            except (KeyboardInterrupt):
                print '\nKeyboardInterrupt'
            except (SystemExit, EOFError):
                print "\n\nGood bye!\n"
                break
        if not args.persist:
            return

    total_input = ""
    while True:
        try:
            line = raw_input(shell.get_in_prompt(continued=total_input != ''))
            line = line.decode(sys.stdin.encoding)
            total_input += line
            if line != "" and wait_for_line(total_input):
                continue
            shell.evaluate(total_input)
            total_input = ""
        except (KeyboardInterrupt):
            print '\nKeyboardInterrupt'
        except (SystemExit, EOFError):
            print "\n\nGood bye!\n"
            break
Beispiel #7
0
def main():
    # Check for the database
    database_file = mathics_settings.DATABASES['default']['NAME']
    if not os.path.exists(database_file):
        print "Error: Mathics database not found!"
        print "Please change to the mathics install directory and run:\n"
        print "   $> python setup.py initialize\n"
        print "as the current user"
        sys.exit(-1)

    os.environ['DJANGO_SETTINGS_MODULE'] = 'mathics.settings'
    # os.putenv('DJANGO_SETTINGS_MODULE', 'mathics.settings')

    from django.conf import settings
    from django.core.servers.basehttp import run
    from django.core.handlers.wsgi import WSGIHandler

    argparser = argparse.ArgumentParser(
        prog='mathicsserver',
        usage='%(prog)s [options]',
        add_help=False,
        description="""Mathics server for the graphical user interface in a
            web browser. It is not intended for production use on a public Web
            server!""",
        epilog="""Please feel encouraged to contribute to Mathics! Create
            your own fork, make the desired changes, commit, and make a pull
            request.""")

    argparser.add_argument('--help',
                           '-h',
                           help='show this help message and exit',
                           action='help')
    argparser.add_argument('--quiet',
                           '-q',
                           help='don\'t print message at startup',
                           action='store_true')
    argparser.add_argument('--version',
                           '-v',
                           action='version',
                           version='%(prog)s ' + mathics.__version__)
    argparser.add_argument("--port",
                           "-p",
                           dest="port",
                           metavar="PORT",
                           default=8000,
                           type=int,
                           help="use PORT as server port")
    argparser.add_argument("--external",
                           "-e",
                           dest="external",
                           action="store_true",
                           help="allow external access to server")

    args = argparser.parse_args()

    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-C'
    port = args.port

    if not args.quiet:
        print_version(is_server=True)
        print_license()
        print u"Quit by pressing %s\n" % quit_command

        print u"""Open the graphical user interface at
http://localhost:%d\nin Firefox, Chrome, or Safari to use Mathics\n""" % port

    if args.external:
        addr = '0.0.0.0'
    else:
        addr = ''

    try:
        if settings.DJANGO_VERSION < (1, 4):
            from django.core.servers.basehttp import AdminMediaHandler
            handler = AdminMediaHandler(WSGIHandler(), '')
        else:
            from django.core.servers.basehttp import (
                get_internal_wsgi_application)
            handler = get_internal_wsgi_application()
        run(addr, port, handler)
    except socket.error as e:
        # Use helpful error messages instead of ugly tracebacks.
        ERRORS = {
            errno.EACCES: "You don't have permission to access that port.",
            errno.EADDRINUSE: "That port is already in use.",
            errno.EADDRNOTAVAIL: "That IP address can't be assigned to.",
        }
        try:
            error_text = ERRORS[e.errno]
        except KeyError:
            error_text = str(e)
        sys.stderr.write("Error: %s" % error_text + '\n')
        # Need to use an OS exit because sys.exit doesn't work in a thread
        os._exit(1)
    except KeyboardInterrupt:
        print "\nGoodbye!\n"
        sys.exit(0)
Beispiel #8
0
def main():
    argparser = argparse.ArgumentParser(
        prog='mathics',
        usage='%(prog)s [options] [FILE]',
        add_help=False,
        description = "Mathics is a general-purpose computer algebra system.",
        epilog = """Please feel encouraged to contribute to Mathics! Create
            your own fork, make the desired changes, commit, and make a pull 
            request.""")

    argparser.add_argument('FILE',  nargs='?', type=argparse.FileType('r'), help='execute commands from FILE')

    argparser.add_argument('--help', '-h', help='show this help message and exit', action='help')
    argparser.add_argument('--persist',  help='go to interactive shell after evaluating FILE', action='store_true')
    argparser.add_argument('--quiet', '-q', help='don\'t print message at startup', action='store_true')
    argparser.add_argument('-script', help='run a mathics file in script mode', action='store_true')
    argparser.add_argument('--version', '-v', action='version', version=get_version_string(False))

    args = argparser.parse_args()

    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D'
    
    if not (args.quiet or args.script):
        print_version(is_server=False)
        print_license()
        print u"Quit by pressing %s" % quit_command
    
        print ''

    definitions = Definitions(add_builtin=True)

    trailing_ops = ['+', '-', '/', '*'] # TODO all binary operators?

    if args.FILE is not None:
        total_input = ""
        for line in args.FILE:

            if args.script and line.startswith('#!'):
                continue

            if total_input == "":
                print '>> ', line,
            else:
                print '       ', line,

            total_input += line

            if line == "":
                pass
            elif any(line.rstrip().endswith(op) for op in trailing_ops) or not brackets_balanced(total_input):
                continue

            evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback)
            for result in evaluation.results:
                    if result.result is not None:
                        print ' = %s' % to_output(unicode(result.result))           
            total_input = ""
        if not args.persist:
            return

    while True:
        try: 
            total_input = ""
            line_input = raw_input('>> ')
            while line_input != "":
                total_input += ' ' + line_input
                if any([line_input.rstrip().endswith(op) for op in trailing_ops]):
                    pass
                elif brackets_balanced(total_input):
                    break
                line_input = raw_input('       ')
        
            evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback)
        
            for result in evaluation.results:
                if result.result is not None:
                    print ' = %s' % to_output(unicode(result.result))
        except (KeyboardInterrupt):
            print '\nKeyboardInterrupt'
        except (SystemExit, EOFError):
            print "\n\nGood bye!\n"
            break
Beispiel #9
0
def main():
    # Check for the database
    database_file = mathics_settings.DATABASES['default']['NAME']
    if not os.path.exists(database_file):
        print "Error: Mathics database not found!"
        print "Please change to the mathics install directory and run:\n"
        print "   $> python setup.py initialize\n"
        print "as the current user"
        sys.exit(-1)

    os.environ['DJANGO_SETTINGS_MODULE'] = 'mathics.settings'
    # os.putenv('DJANGO_SETTINGS_MODULE', 'mathics.settings')

    from django.conf import settings
    from django.core.servers.basehttp import run, WSGIServerException
    from django.core.handlers.wsgi import WSGIHandler

    argparser = argparse.ArgumentParser(
        prog='mathicsserver',
        usage='%(prog)s [options]',
        add_help=False,
        description="""Mathics server for the graphical user interface in a
            web browser. It is not intended for production use on a public Web
            server!""",
        epilog="""Please feel encouraged to contribute to Mathics! Create
            your own fork, make the desired changes, commit, and make a pull
            request.""")

    argparser.add_argument(
        '--help', '-h', help='show this help message and exit', action='help')
    argparser.add_argument(
        '--quiet', '-q', help='don\'t print message at startup',
        action='store_true')
    argparser.add_argument(
        '--version', '-v', action='version',
        version='%(prog)s ' + mathics.__version__)
    argparser.add_argument(
        "--port", "-p", dest="port", metavar="PORT", default=8000, type=int,
        help="use PORT as server port")
    argparser.add_argument(
        "--external", "-e", dest="external", action="store_true",
        help="allow external access to server")

    args = argparser.parse_args()

    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-C'
    port = args.port

    if not args.quiet:
        print_version(is_server=True)
        print_license()
        print u"Quit by pressing %s\n" % quit_command

        print u"""Open the graphical user interface at
http://localhost:%d\n in Firefox, Chrome, or Safari to use Mathics\n""" % port

    if args.external:
        addr = '0.0.0.0'
    else:
        addr = ''

    try:
        if settings.DJANGO_VERSION < (1, 4):
            from django.core.servers.basehttp import AdminMediaHandler
            handler = AdminMediaHandler(WSGIHandler(), '')
        else:
            from django.core.servers.basehttp import (
                get_internal_wsgi_application)
            handler = get_internal_wsgi_application()
        run(addr, port, handler)
    except WSGIServerException, e:
        # Use helpful error messages instead of ugly tracebacks.
        ERRORS = {
            13: "You don't have permission to access that port.",
            98: "That port is already in use.",
            99: "That IP address can't be assigned to.",
        }
        try:
            error_text = ERRORS[e.args[0].args[0]]
        except (AttributeError, KeyError):
            error_text = str(e)
        sys.stderr.write("Error: %s" % error_text + '\n')
        # Need to use an OS exit because sys.exit doesn't work in a thread
        os._exit(1)
Beispiel #10
0
def main():
    argparser = argparse.ArgumentParser(
        prog="mathics",
        usage="%(prog)s [options] [FILE]",
        add_help=False,
        description="Mathics is a general-purpose computer algebra system.",
        epilog="""Please feel encouraged to contribute to Mathics! Create
            your own fork, make the desired changes, commit, and make a pull 
            request.""",
    )

    argparser.add_argument("FILE", nargs="?", type=argparse.FileType("r"), help="execute commands from FILE")

    argparser.add_argument("--help", "-h", help="show this help message and exit", action="help")
    argparser.add_argument("--persist", help="go to interactive shell after evaluating FILE", action="store_true")
    argparser.add_argument("--quiet", "-q", help="don't print message at startup", action="store_true")
    argparser.add_argument("-script", help="run a mathics file in script mode", action="store_true")
    argparser.add_argument("--execute", "-e", nargs="?", help="execute a command")
    argparser.add_argument("--version", "-v", action="version", version=get_version_string(False))

    args = argparser.parse_args()

    quit_command = "CTRL-BREAK" if sys.platform == "win32" else "CONTROL-D"

    definitions = Definitions(add_builtin=True)

    trailing_ops = ["+", "-", "/", "*"]  # TODO all binary operators?

    if args.execute:
        print ">> %s" % args.execute
        evaluation = Evaluation(args.execute, definitions, timeout=30, out_callback=out_callback)
        for result in evaluation.results:
            if result.result is not None:
                print " = %s" % to_output(unicode(result.result))
        return

    if not (args.quiet or args.script):
        print_version(is_server=False)
        print_license()
        print u"Quit by pressing %s" % quit_command

        print ""

    if args.FILE is not None:
        total_input = ""
        for line in args.FILE:

            if args.script and line.startswith("#!"):
                continue

            if total_input == "":
                print ">> ", line,
            else:
                print "       ", line,

            total_input += line

            if line == "":
                pass
            elif any(line.rstrip().endswith(op) for op in trailing_ops) or not brackets_balanced(total_input):
                continue

            evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback)
            for result in evaluation.results:
                if result.result is not None:
                    print " = %s" % to_output(unicode(result.result))
            total_input = ""
        if not args.persist:
            return

    while True:
        try:
            total_input = ""
            line_input = raw_input(">> ")
            while line_input != "":
                total_input += " " + line_input
                if any([line_input.rstrip().endswith(op) for op in trailing_ops]):
                    pass
                elif brackets_balanced(total_input):
                    break
                line_input = raw_input("       ")

            evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback)

            for result in evaluation.results:
                if result.result is not None:
                    print " = %s" % to_output(unicode(result.result))
        except (KeyboardInterrupt):
            print "\nKeyboardInterrupt"
        except (SystemExit, EOFError):
            print "\n\nGood bye!\n"
            break
Beispiel #11
0
def main():
    argparser = argparse.ArgumentParser(
        prog='mathics',
        usage='%(prog)s [options] [FILE]',
        add_help=False,
        description="Mathics is a general-purpose computer algebra system.",
        epilog="""Please feel encouraged to contribute to Mathics! Create
            your own fork, make the desired changes, commit, and make a pull 
            request.""")

    argparser.add_argument('FILE',
                           nargs='?',
                           type=argparse.FileType('r'),
                           help='execute commands from FILE')

    argparser.add_argument('--help',
                           '-h',
                           help='show this help message and exit',
                           action='help')
    argparser.add_argument(
        '--persist',
        help='go to interactive shell after evaluating FILE',
        action='store_true')
    argparser.add_argument('--quiet',
                           '-q',
                           help='don\'t print message at startup',
                           action='store_true')
    argparser.add_argument('-script',
                           help='run a mathics file in script mode',
                           action='store_true')
    argparser.add_argument('--version',
                           '-v',
                           action='version',
                           version=get_version_string(False))

    args = argparser.parse_args()

    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D'

    if not (args.quiet or args.script):
        print_version(is_server=False)
        print_license()
        print u"Quit by pressing %s" % quit_command

        print ''

    definitions = Definitions(add_builtin=True)

    trailing_ops = ['+', '-', '/', '*']  # TODO all binary operators?

    if args.FILE is not None:
        total_input = ""
        for line in args.FILE:

            if args.script and line.startswith('#!'):
                continue

            if total_input == "":
                print '>> ', line,
            else:
                print '       ', line,

            total_input += line

            if line == "":
                pass
            elif any(line.rstrip().endswith(op) for op in
                     trailing_ops) or not brackets_balanced(total_input):
                continue

            evaluation = Evaluation(total_input,
                                    definitions,
                                    timeout=30,
                                    out_callback=out_callback)
            for result in evaluation.results:
                if result.result is not None:
                    print ' = %s' % to_output(unicode(result.result))
            total_input = ""
        if not args.persist:
            return

    while True:
        try:
            total_input = ""
            line_input = raw_input('>> ')
            while line_input != "":
                total_input += ' ' + line_input
                if any(
                    [line_input.rstrip().endswith(op) for op in trailing_ops]):
                    pass
                elif brackets_balanced(total_input):
                    break
                line_input = raw_input('       ')

            evaluation = Evaluation(total_input,
                                    definitions,
                                    timeout=30,
                                    out_callback=out_callback)

            for result in evaluation.results:
                if result.result is not None:
                    print ' = %s' % to_output(unicode(result.result))
        except (KeyboardInterrupt):
            print '\nKeyboardInterrupt'
        except (SystemExit, EOFError):
            print "\n\nGood bye!\n"
            break
Beispiel #12
0
def main():
    # Check for the database
    database_file = mathics_settings.DATABASES['default']['NAME']
    if not os.path.exists(database_file):
        print("warning: database file %s not found\n" % database_file)
        import subprocess
        if not os.path.exists(mathics_settings.DATA_DIR):
            print("Creating data directory %s" % mathics_settings.DATA_DIR)
            os.makedirs(mathics_settings.DATA_DIR)
        print("Creating database %s" % database_file)
        manage_file = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "manage.py")
        try:
            subprocess.check_call(
                [sys.executable, manage_file, 'migrate', '--noinput'])
            print("\ndatabase initialized sucessfully")
        except subprocess.CalledProcessError:
            print("error: failed to create database")
            sys.exit(1)

    os.environ['DJANGO_SETTINGS_MODULE'] = 'mathics.settings'
    # os.putenv('DJANGO_SETTINGS_MODULE', 'mathics.settings')

    from django.conf import settings
    from django.core.servers.basehttp import run
    from django.core.handlers.wsgi import WSGIHandler

    argparser = argparse.ArgumentParser(
        prog='mathicsserver',
        usage='%(prog)s [options]',
        add_help=False,
        description="""Mathics server for the graphical user interface in a
            web browser. It is not intended for production use on a public Web
            server!""",
        epilog="""Please feel encouraged to contribute to Mathics! Create
            your own fork, make the desired changes, commit, and make a pull
            request.""")

    argparser.add_argument(
        '--help', '-h', help='show this help message and exit', action='help')
    argparser.add_argument(
        '--quiet', '-q', help='don\'t print message at startup',
        action='store_true')
    argparser.add_argument(
        '--version', '-v', action='version',
        version='%(prog)s ' + mathics.__version__)
    argparser.add_argument(
        "--port", "-p", dest="port", metavar="PORT", default=8000, type=int,
        help="use PORT as server port")
    argparser.add_argument(
        "--external", "-e", dest="external", action="store_true",
        help="allow external access to server")

    args = argparser.parse_args()

    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-C'
    port = args.port

    if not args.quiet:
        print_version(is_server=True)
        print_license()
        print u"Quit by pressing %s\n" % quit_command

        print u"""Open the graphical user interface at
http://localhost:%d\nin Firefox, Chrome, or Safari to use Mathics\n""" % port

    if args.external:
        addr = '0.0.0.0'
    else:
        addr = '127.0.0.1'

    try:
        if settings.DJANGO_VERSION < (1, 4):
            from django.core.servers.basehttp import AdminMediaHandler
            handler = AdminMediaHandler(WSGIHandler(), '')
        else:
            from django.core.servers.basehttp import (
                get_internal_wsgi_application)
            handler = get_internal_wsgi_application()
        run(addr, port, handler)
    except socket.error as e:
        # Use helpful error messages instead of ugly tracebacks.
        ERRORS = {
            errno.EACCES: "You don't have permission to access that port.",
            errno.EADDRINUSE: "That port is already in use.",
            errno.EADDRNOTAVAIL: "That IP address can't be assigned to.",
        }
        try:
            error_text = ERRORS[e.errno]
        except KeyError:
            error_text = str(e)
        sys.stderr.write("Error: %s" % error_text + '\n')
        # Need to use an OS exit because sys.exit doesn't work in a thread
        os._exit(1)
    except KeyboardInterrupt:
        print "\nGoodbye!\n"
        sys.exit(0)
Beispiel #13
0
def main():
    argparser = argparse.ArgumentParser(
        prog='mathics',
        usage='%(prog)s [options] [FILE]',
        add_help=False,
        description="Mathics is a general-purpose computer algebra system.",
        epilog="""Please feel encouraged to contribute to Mathics! Create
            your own fork, make the desired changes, commit, and make a pull
            request.""")

    argparser.add_argument(
        'FILE', nargs='?', type=argparse.FileType('r'),
        help='execute commands from FILE')

    argparser.add_argument(
        '--help', '-h', help='show this help message and exit', action='help')

    argparser.add_argument(
        '--persist', help='go to interactive shell after evaluating FILE',
        action='store_true')

    argparser.add_argument(
        '--quiet', '-q', help='don\'t print message at startup',
        action='store_true')

    argparser.add_argument(
        '-script', help='run a mathics file in script mode',
        action='store_true')

    argparser.add_argument(
        '--execute', '-e', nargs='?', help='execute a command')

    argparser.add_argument(
        '--colors', nargs='?', help='interactive shell colors')

    argparser.add_argument(
        '--version', '-v', action='version', version=get_version_string(False))

    args = argparser.parse_args()

    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D'

    definitions = Definitions(add_builtin=True)

    definitions.set_ownvalue('$Line', Integer(0))  # Reset the line number

    shell = TerminalShell(definitions, args.colors)

    if not (args.quiet or args.script):
        print_version(is_server=False)
        print_license()
        print u"Quit by pressing {0}\n".format(quit_command)

    if args.execute:
        total_input = args.execute.decode(shell.input_encoding)
        print shell.get_in_prompt() + total_input
        shell.evaluate(total_input)
        return

    if args.FILE is not None:
        total_input = ''
        for line_no, line in enumerate(args.FILE):
            try:
                line = line.decode('utf-8')     # TODO: other encodings
                if args.script and line_no == 0 and line.startswith('#!'):
                    continue
                print shell.get_in_prompt(continued=total_input != '') + line,
                total_input += ' ' + line
                if line != "" and wait_for_line(total_input):
                    continue
                shell.evaluate(total_input)
                total_input = ""
            except (KeyboardInterrupt):
                print '\nKeyboardInterrupt'
            except (SystemExit, EOFError):
                print "\n\nGood bye!\n"
                break
        if not args.persist:
            return

    total_input = ""
    while True:
        try:
            line = shell.read_line(
                shell.get_in_prompt(continued=total_input != ''))
            line = line.decode(shell.input_encoding)
            total_input += line
            if line != "" and wait_for_line(total_input):
                continue
            shell.evaluate(total_input)
            total_input = ""
        except (KeyboardInterrupt):
            print '\nKeyboardInterrupt'
        except (SystemExit, EOFError):
            print "\n\nGood bye!\n"
            break
Beispiel #14
0
def main():
    argparser = argparse.ArgumentParser(
        prog='mathics',
        usage='%(prog)s [options] [FILE]',
        add_help=False,
        description = "Mathics is a general-purpose computer algebra system.",
        epilog = """Please feel encouraged to contribute to Mathics! Create
            your own fork, make the desired changes, commit, and make a pull 
            request.""")

    argparser.add_argument('FILE',  nargs='?', type=argparse.FileType('r'), help='execute commands from FILE')

    argparser.add_argument('--help', '-h', help='show this help message and exit', action='help')
    argparser.add_argument('--persist',  help='go to interactive shell after evaluating FILE', action='store_true')
    argparser.add_argument('--quiet', '-q', help='don\'t print message at startup', action='store_true')
    argparser.add_argument('-script', help='run a mathics file in script mode', action='store_true')
    argparser.add_argument('--execute', '-e', nargs='?', help='execute a command')
    argparser.add_argument('--colors', nargs='?', help='interactive shell colors')
    argparser.add_argument('--version', '-v', action='version', version=get_version_string(False))

    args = argparser.parse_args()

    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D'
    
    definitions = Definitions(add_builtin=True)

    # TODO all binary operators?

    #Reset the line number to 1
    definitions.set_ownvalue('$Line', Integer(1))

    shell = TerminalShell(definitions, args.colors)

    if args.execute:
        total_input = args.execute.decode(sys.stdin.encoding)  # check encoding
        print shell.get_in_prompt() + total_input
        evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback)
        for result in evaluation.results:
            if result.result is not None:
                print shell.get_out_prompt() + to_output(unicode(result.result)) + '\n'
        return

    if not (args.quiet or args.script):
        print_version(is_server=False)
        print_license()
        print u"Quit by pressing %s" % quit_command
    
        print ''


    if args.FILE is not None:
        total_input = ""
        for line in args.FILE:
            line = line.decode('utf-8')     # TODO: other encodings

            if args.script and line.startswith('#!'):
                continue

            if total_input == "":
                print shell.get_in_prompt() + line,
            else:
                print '       ', line,

            total_input += line

            if line == "":
                pass
            elif wait_for_line(total_input):
                continue

            evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback)
            for result in evaluation.results:
                if result.result is not None:
                    print shell.get_out_prompt() + to_output(unicode(result.result)) + '\n'
            total_input = ""
        if not args.persist:
            return

    while True:
        try: 
            total_input = ""
            line_input = raw_input(shell.get_in_prompt())
            line_input = line_input.decode(sys.stdin.encoding)
            while line_input != "":
                total_input += ' ' + line_input
                if not wait_for_line(total_input):
                    break
                line_input = raw_input('        ')
                line_input = line_input.decode(sys.stdin.encoding)

            evaluation = Evaluation(total_input, definitions, timeout=30, out_callback=out_callback)
        
            for result in evaluation.results:
                if result.result is not None:
                    print shell.get_out_prompt() + to_output(unicode(result.result)) + '\n'

        except (KeyboardInterrupt):
            print '\nKeyboardInterrupt'
        except (SystemExit, EOFError):
            print "\n\nGood bye!\n"
            break
Beispiel #15
0
def main():
    argparser = argparse.ArgumentParser(
        prog='mathics',
        usage='%(prog)s [options] [FILE]',
        add_help=False,
        description="Mathics is a general-purpose computer algebra system.",
        epilog="""Please feel encouraged to contribute to Mathics! Create
            your own fork, make the desired changes, commit, and make a pull 
            request.""")

    argparser.add_argument('FILE',
                           nargs='?',
                           type=argparse.FileType('r'),
                           help='execute commands from FILE')

    argparser.add_argument('--help',
                           '-h',
                           help='show this help message and exit',
                           action='help')
    argparser.add_argument(
        '--persist',
        help='go to interactive shell after evaluating FILE',
        action='store_true')
    argparser.add_argument('--quiet',
                           '-q',
                           help='don\'t print message at startup',
                           action='store_true')
    argparser.add_argument('-script',
                           help='run a mathics file in script mode',
                           action='store_true')
    argparser.add_argument('--execute',
                           '-e',
                           nargs='?',
                           help='execute a command')
    argparser.add_argument('--colors',
                           nargs='?',
                           help='interactive shell colors')
    argparser.add_argument('--version',
                           '-v',
                           action='version',
                           version=get_version_string(False))

    args = argparser.parse_args()

    quit_command = 'CTRL-BREAK' if sys.platform == 'win32' else 'CONTROL-D'

    definitions = Definitions(add_builtin=True)

    # TODO all binary operators?

    #Reset the line number to 1
    definitions.set_ownvalue('$Line', Integer(1))

    shell = TerminalShell(definitions, args.colors)

    if args.execute:
        print get_in_prompt() + args.execute
        evaluation = Evaluation(args.execute,
                                definitions,
                                timeout=30,
                                out_callback=out_callback)
        for result in evaluation.results:
            if result.result is not None:
                print shell.get_out_prompt() + to_output(unicode(
                    result.result)) + '\n'
        return

    if not (args.quiet or args.script):
        print_version(is_server=False)
        print_license()
        print u"Quit by pressing %s" % quit_command

        print ''

    if args.FILE is not None:
        total_input = ""
        for line in args.FILE:

            if args.script and line.startswith('#!'):
                continue

            if total_input == "":
                print shell.get_in_prompt() + line,
            else:
                print '       ', line,

            total_input += line

            if line == "":
                pass
            elif wait_for_line(total_input):
                continue

            evaluation = Evaluation(total_input,
                                    definitions,
                                    timeout=30,
                                    out_callback=out_callback)
            for result in evaluation.results:
                if result.result is not None:
                    print shell.get_out_prompt() + to_output(
                        unicode(result.result)) + '\n'
            total_input = ""
        if not args.persist:
            return

    while True:
        try:
            total_input = ""
            line_input = raw_input(shell.get_in_prompt())
            while line_input != "":
                total_input += ' ' + line_input
                if not wait_for_line(total_input):
                    break
                line_input = raw_input('        ')

            evaluation = Evaluation(total_input,
                                    definitions,
                                    timeout=30,
                                    out_callback=out_callback)

            for result in evaluation.results:
                if result.result is not None:
                    print shell.get_out_prompt() + to_output(
                        unicode(result.result)) + '\n'

        except (KeyboardInterrupt):
            print '\nKeyboardInterrupt'
        except (SystemExit, EOFError):
            print "\n\nGood bye!\n"
            break