Example #1
0
def run(*args, **kwargs):
    """
    Call to run a GLASS config file within a standard glass 'write' environment

    Args:
        args <str/tuple(str)> - input files for GLASS, e.g. '../src/glass/Examples/B1115.gls'

    Kwargs:
        threads <int> - run with given number of threads
        no_window <bool> - suppress any graphics

    Return:
        None
    """
    Environment.global_opts['ncpus_detected'] = _detect_cpus()
    Environment.global_opts['ncpus'] = 1
    Environment.global_opts['omp_opts'] = _detect_omp()
    Environment.global_opts['withgfx'] = True
    Commands.set_env(Environment())
    if 'thread' in kwargs and kwargs['threads'] > 1:
        Environment.global_opts['ncpus'] = kwargs['threads']
    if 'no_window' in kwargs:
        Environment.global_opts['withgfx'] = kwargs['no_window']

    import glass.glcmds
    import glass.scales
    if Environment.global_opts['withgfx']:
        import glass.plots

    with open(args[0], 'r') as f:
        Commands.get_env().input_file = f.read()

    Environment.global_opts['argv'] = args

    try:
        execfile(args[0])
    except GLInputError as e:
        raise e(
            "An error occurred! Figure out whats wrong and give it another go..."
        )
Example #2
0
            assert ncpus > 0
            #Commands.get_env().ncpus = ncpus
            Environment.global_opts['ncpus'] = ncpus
        elif opt[0] == '--nw':
            #Commands.get_env().withgfx = False
            Environment.global_opts['withgfx'] = False

    if Environment.global_opts['withgfx']:
        import glass.plots

    import glass.glcmds
    import glass.scales
    #import pytipsy

    with open(arglist[0], 'r') as f:
        Commands.get_env().input_file = f.read()

    Environment.global_opts['argv'] = arglist
    #Commands.get_env().argv = arglist

    try:
        execfile(arglist[0])  #, globals(), globals())
    except GLInputError as e:
        tb = traceback.extract_tb(sys.exc_traceback, 2)[1]
        #traceback.print_tb(sys.exc_traceback, 2)
        print >> sys.stderr, "Input error on line %i of file '%s':" % (tb[1],
                                                                       tb[0])
        print >> sys.stderr, "> %s" % tb[3]
        print >> sys.stderr
        print >> sys.stderr, e
        print >> sys.stderr
Example #3
0
            #Commands.get_env().ncpus = ncpus
            Environment.global_opts['ncpus'] = ncpus
        elif opt[0] == '--nw':
            #Commands.get_env().withgfx = False
            Environment.global_opts['withgfx'] = False


    if Environment.global_opts['withgfx']:
        import glass.plots 

    import glass.glcmds
    import glass.scales
    #import pytipsy 

    with open(arglist[0], 'r') as f:
        Commands.get_env().input_file = f.read()

    Environment.global_opts['argv'] = arglist
    #Commands.get_env().argv = arglist


    try:
        execfile(arglist[0]) #, globals(), globals())
    except GLInputError as e:
        tb = traceback.extract_tb(sys.exc_traceback, 2)[1]
        #traceback.print_tb(sys.exc_traceback, 2)
        print >>sys.stderr, "Input error on line %i of file '%s':" % (tb[1], tb[0])
        print >>sys.stderr, "> %s" % tb[3]
        print >>sys.stderr
        print >>sys.stderr, e
        print >>sys.stderr
Example #4
0
def env():
    #return _env
    return Commands.get_env()