Example #1
0
File: main.py Project: Cynary/xonsh
def main(argv=None):
    """Main entry point for xonsh cli."""
    args = parser.parse_args()
    shell = Shell() if not args.norc else Shell(ctx={})
    from xonsh import imphooks
    env = builtins.__xonsh_env__
    if args.defines is not None:
        env.update([x.split('=', 1) for x in args.defines])
    env['XONSH_INTERACTIVE'] = False
    if args.command is not None:
        # run a single command and exit
        shell.default(args.command)
    elif args.file is not None:
        # run a script contained in a file
        if os.path.isfile(args.file):
            with open(args.file) as f:
                code = f.read()
            code = code if code.endswith('\n') else code + '\n'
            env['ARGS'] = [args.file] + args.args
            code = shell.execer.compile(code, mode='exec', glbs=shell.ctx)
            shell.execer.exec(code, mode='exec', glbs=shell.ctx)
        else:
            print('xonsh: {0}: No such file or directory.'.format(args.file))
    elif not sys.stdin.isatty():
        # run a script given on stdin
        code = sys.stdin.read()
        code = code if code.endswith('\n') else code + '\n'
        code = shell.execer.compile(code, mode='exec', glbs=shell.ctx)
        shell.execer.exec(code, mode='exec', glbs=shell.ctx)
    else:
        # otherwise, enter the shell
        env['XONSH_INTERACTIVE'] = True
        ignore_sigtstp()
        shell.cmdloop()
Example #2
0
def main(argv):
    global ROOT
    parser = argparse.ArgumentParser(
        description='An automatic programming contest judge.')
    parser.add_argument('contest', help='the contest directory')
    parser.add_argument('-d',
                        "--directory",
                        default=None,
                        help="The root directory")
    opts = parser.parse_args(argv)

    sh_parser = Parser(lexer_table='lexer_table',
                       yacc_table='parser_table',
                       outputdir=os.path.join(BASE_DIR, "xonsh", "xonsh"))
    if opts.directory:
        ROOT = opts.directory
    else:
        ROOT = tempfile.mkdtemp(prefix="epsilon")
    os.chdir(ROOT)
    os.environ["USER"] = "******"

    shell.load_contest(opts.contest)

    cmd = Shell()
    cmd.execer.parser = sh_parser
    setup_shortcuts()
    setup_aliases()
    setup_env()
    cmd.cmdloop()
Example #3
0
def main(argv=None):
    """Main entry point for xonsh cli."""
    args = parser.parse_args()
    shell_kwargs = {"shell_type": args.shell_type}
    if args.norc:
        shell_kwargs["ctx"] = {}
    setattr(sys, "displayhook", _pprint_displayhook)
    shell = Shell(**shell_kwargs)
    from xonsh import imphooks

    env = builtins.__xonsh_env__
    if args.defines is not None:
        env.update([x.split("=", 1) for x in args.defines])
    env["XONSH_INTERACTIVE"] = False
    if args.command is not None:
        # run a single command and exit
        shell.default(args.command)
    elif args.file is not None:
        # run a script contained in a file
        if os.path.isfile(args.file):
            with open(args.file) as f:
                code = f.read()
            code = code if code.endswith("\n") else code + "\n"
            env["ARGS"] = [args.file] + args.args
            code = shell.execer.compile(code, mode="exec", glbs=shell.ctx)
            shell.execer.exec(code, mode="exec", glbs=shell.ctx)
        else:
            print("xonsh: {0}: No such file or directory.".format(args.file))
    elif not sys.stdin.isatty():
        # run a script given on stdin
        code = sys.stdin.read()
        code = code if code.endswith("\n") else code + "\n"
        code = shell.execer.compile(code, mode="exec", glbs=shell.ctx)
        shell.execer.exec(code, mode="exec", glbs=shell.ctx)
    else:
        # otherwise, enter the shell
        env["XONSH_INTERACTIVE"] = True
        ignore_sigtstp()
        shell.cmdloop()
Example #4
0
def main(argv=None):
    """Main entry point for xonsh cli."""
    args = parser.parse_args()
    shell_kwargs = {'shell_type': args.shell_type}
    if args.norc:
        shell_kwargs['ctx'] = {}
    setattr(sys, 'displayhook', _pprint_displayhook)
    shell = Shell(**shell_kwargs)
    from xonsh import imphooks
    env = builtins.__xonsh_env__
    if args.defines is not None:
        env.update([x.split('=', 1) for x in args.defines])
    env['XONSH_INTERACTIVE'] = False
    if args.command is not None:
        # run a single command and exit
        shell.default(args.command)
    elif args.file is not None:
        # run a script contained in a file
        if os.path.isfile(args.file):
            with open(args.file) as f:
                code = f.read()
            code = code if code.endswith('\n') else code + '\n'
            env['ARGS'] = [args.file] + args.args
            code = shell.execer.compile(code, mode='exec', glbs=shell.ctx)
            shell.execer.exec(code, mode='exec', glbs=shell.ctx)
        else:
            print('xonsh: {0}: No such file or directory.'.format(args.file))
    elif not sys.stdin.isatty():
        # run a script given on stdin
        code = sys.stdin.read()
        code = code if code.endswith('\n') else code + '\n'
        code = shell.execer.compile(code, mode='exec', glbs=shell.ctx)
        shell.execer.exec(code, mode='exec', glbs=shell.ctx)
    else:
        # otherwise, enter the shell
        env['XONSH_INTERACTIVE'] = True
        ignore_sigtstp()
        shell.cmdloop()