예제 #1
0
def operation(op, name, options=None):
    if options is None:
        options = {}
    if name:
        vmx = utils.locate_vmx(name)
        if vmx:
            mechfile = utils.load_mechfile(name)
            m = Mech()
            m.vmx = vmx
            m.user = mechfile['user']
            for key, value in options.iteritems():
                setattr(m, key, value)
            method = getattr(m, op)
            method()
        else:
            puts(colored.red("Couldn't find a VMX in the specified directory"))
    else:
        mechfile = utils.load_mechfile()
        vmx = mechfile.get('vmx')
        if vmx:
            m = Mech()
            m.vmx = vmx
            m.user = mechfile.get('user')
            for key, value in options.iteritems():
                setattr(m, key, value)
            method = getattr(m, op)
            method()
        else:
            puts(colored.red("Couldn't find a VMX in the mechfile"))
예제 #2
0
def main():
    try:
        import os
        import sys

        from mech import Mech

        HOME = os.path.expanduser('~/.mech')
        if not os.path.exists(HOME):
            os.makedirs(HOME)

        arguments = Mech.docopt(Mech.__doc__, argv=sys.argv[1:], version=__version__)
        return Mech(arguments)()
    except KeyboardInterrupt:
        sys.stderr.write('\n')
예제 #3
0
def operation(op, name, options=None, kwargs=None):
    if options is None:
        options = {}
    if name:
        vmx = utils.locate_vmx(name)
        if vmx:
            mechfile = utils.load_mechfile(name)
            m = Mech()
            m.vmx = vmx
            m.user = mechfile['user']
            for key, value in options.iteritems():
                setattr(m, key, value)
            method = getattr(m, op)
            if kwargs:
                method(**kwargs)
            else:
                method()
        else:
            puts(colored.red("Couldn't find a VMX in the specified directory"))
            return
    else:
        mechfile = utils.load_mechfile()
        if mechfile is None:
            puts(
                colored.red(
                    "Couldn't find a mechfile in the current directory any deeper directories"
                ))
            puts(
                colored.red(
                    "You can specify the name of the VM you'd like to start with mech up <name>"
                ))
            puts(
                colored.red(
                    "Or run mech init to setup a tarball of your VM or download the VM"
                ))
            return
        vmx = mechfile.get('vmx')
        if vmx:
            m = Mech()
            m.vmx = vmx
            m.user = mechfile.get('user')
            for key, value in options.iteritems():
                setattr(m, key, value)
            method = getattr(m, op)
            if kwargs:
                method(**kwargs)
            else:
                method()
        else:
            puts(colored.red("Couldn't find a VMX in the mechfile"))
            return
예제 #4
0
파일: __main__.py 프로젝트: ColdHeat/mech
def operation(op, name, options=None):
    if options is None:
        options = {}
    if name:
        vmx = utils.locate_vmx(name)
        if vmx:
            mechfile = utils.load_mechfile(name)
            m = Mech()
            m.vmx = vmx
            m.user = mechfile['user']
            for key, value in options.iteritems():
                setattr(m, key, value)
            method = getattr(m, op)
            method()
        else:
            puts(colored.red("Couldn't find a VMX in the specified directory"))
    else:
        mechfile = utils.load_mechfile()
        vmx = mechfile.get('vmx')
        if vmx:
            m = Mech()
            m.vmx = vmx
            m.user = mechfile.get('user')
            for key, value in options.iteritems():
                setattr(m, key, value)
            method = getattr(m, op)
            method()
        else:
            puts(colored.red("Couldn't find a VMX in the mechfile"))
예제 #5
0
파일: __main__.py 프로젝트: merlinWiz/mech
def operation(op, name, options=None, kwargs=None):
    if options is None:
        options = {}
    if name:
        vmx = utils.locate_vmx(name)
        if vmx:
            mechfile = utils.load_mechfile(name)
            m = Mech()
            m.vmx = vmx
            m.user = mechfile['user']
            for key, value in options.iteritems():
                setattr(m, key, value)
            method = getattr(m, op)
            if kwargs:
                method(**kwargs)
            else:
                method()
        else:
            puts(colored.red("Couldn't find a VMX in the specified directory"))
            return
    else:
        mechfile = utils.load_mechfile()
        if mechfile is None:
            puts(colored.red("Couldn't find a mechfile in the current directory any deeper directories"))
            puts(colored.red("You can specify the name of the VM you'd like to start with mech up <name>"))
            puts(colored.red("Or run mech init to setup a tarball of your VM or download the VM"))
            return
        vmx = mechfile.get('vmx')
        if vmx:
            m = Mech()
            m.vmx = vmx
            m.user = mechfile.get('user')
            for key, value in options.iteritems():
                setattr(m, key, value)
            method = getattr(m, op)
            if kwargs:
                method(**kwargs)
            else:
                method()
        else:
            puts(colored.red("Couldn't find a VMX in the mechfile"))
            return
예제 #6
0
파일: __main__.py 프로젝트: envhyf/pykpp
parser.add_option("-k", "--keywords", dest = "keywords", type="string", default = 'hv,PROD,EMISSION', help = "List of keywords to be ignored in reactants or products (comma delimited; default='hv')")

parser.add_option("-o", "--outpath", dest = "outpath", type="string", default = None, help = "Output path.")

parser.add_option("-m", "--monitor", dest = "monitor", type="string", default = None, help = "Extra monitor values (comma separated string).")

parser.add_option("-s", "--solver", dest = "solver", default = None, help = "solver (default: lsoda; vode; zvode; dopri5; dop853)")

parser.add_option("-c", "--code", dest = "code", default = "", help = "code to solve (exec) after model is compiled and run (unless --norun); out is a keyword for the mechanism that has been generated")

(options, args) = parser.parse_args()

if len(args) == 0:
    parser.print_help()
    exit()
    
outs = []
for arg in args:
    out = Mech(arg, verbose = options.verbose, keywords = [k_.strip() for k_ in options.keywords.split(',')])
    if options.monitor is not None:
        out.monitor = tuple([(None if k not in out.allspcs else out.allspcs.index(k), k) for k in options.monitor.split(',')]) + out.monitor
    if not options.norun:
        runtime = out.run(tstart = options.tstart, tend = options.tend, dt = options.dt, solver = options.solver, jac = options.jacobian, atol = options.atol, rtol = options.rtol)
        print 'Solved in %f seconds' % runtime
        out.output(options.outpath)
    outs.append(out)

if os.path.exists(options.code):
    options.code = file(options.code, 'r').read()
exec(options.code)
예제 #7
0
def main(args=None):
    arguments = docopt(__doc__, version='mech 0.3')

    DEBUG = arguments['--debug']

    if not os.path.exists(HOME):
        os.makedirs(HOME)

    if arguments['init']:
        puts(colored.green("Initializing mech"))
        url = arguments['<url>']
        name = arguments['--name']
        Mech.setup(url, name)
        exit()

    elif arguments['list'] or arguments['ls']:
        Mech.list()
        exit()

    elif arguments['status'] or arguments['ps']:
        Mech.status()
        exit()

    elif arguments['up'] or arguments['start']:
        name = arguments['<name>']
        gui = arguments['--gui']
        operation(op='start', name=name, options={'gui': gui})
        exit()

    elif arguments['down'] or arguments['stop']:
        name = arguments['<name>']
        operation(op='stop', name=name)
        exit()

    elif arguments['pause']:
        name = arguments['<name>']
        operation(op='pause', name=name)
        exit()

    elif arguments['suspend']:
        name = arguments['<name>']
        operation(op='suspend', name=name)
        exit()

    elif arguments['ssh']:
        name = arguments['<name>']
        user = arguments.get("--user")
        if user:
            options = {'user': user}
        else:
            options = {}
        operation(op='ssh', name=name, options=options)
        exit()

    elif arguments['scp']:
        name = arguments['<name>']
        name = arguments.get("--user")
        operation(op='scp', name=name, options={'user': user})
        exit()

    elif arguments['ip']:
        name = arguments['<name>']
        operation(op='ip', name=name, options={'user': user})
        exit()
예제 #8
0
    dest="code",
    default="",
    help=
    "code to solve (exec) after model is compiled and run (unless --norun); out is a keyword for the mechanism that has been generated"
)

(options, args) = parser.parse_args()

if len(args) == 0:
    parser.print_help()
    exit()

outs = []
for arg in args:
    out = Mech(arg,
               verbose=options.verbose,
               keywords=[k_.strip() for k_ in options.keywords.split(',')])
    if options.monitor is not None:
        out.monitor = tuple(
            [(None if k not in out.allspcs else out.allspcs.index(k), k)
             for k in options.monitor.split(',')]) + out.monitor
    if not options.norun:
        runtime = out.run(tstart=options.tstart,
                          tend=options.tend,
                          dt=options.dt,
                          solver=options.solver,
                          jac=options.jacobian,
                          atol=options.atol,
                          rtol=options.rtol)
        print 'Solved in %f seconds' % runtime
        out.output(options.outpath)
예제 #9
0
파일: __main__.py 프로젝트: ColdHeat/mech
def main(args=None):
    arguments = docopt(__doc__, version='mech 0.3')

    DEBUG = arguments['--debug']

    if not os.path.exists(HOME):
        os.makedirs(HOME)

    if arguments['init']:
        puts(colored.green("Initializing mech"))
        url = arguments['<url>']
        name = arguments['--name']
        Mech.setup(url, name)
        exit()

    elif arguments['list'] or arguments['ls']:
        Mech.list()
        exit()

    elif arguments['status'] or arguments['ps']:
        Mech.status()
        exit()

    elif arguments['up'] or arguments['start']:
        name = arguments['<name>']
        gui = arguments['--gui']
        operation(op='start', name=name, options={'gui':gui})
        exit()

    elif arguments['down'] or arguments['stop']:
        name = arguments['<name>']
        operation(op='stop', name=name)
        exit()

    elif arguments['pause']:
        name = arguments['<name>']
        operation(op='pause', name=name)
        exit()

    elif arguments['suspend']:
        name = arguments['<name>']
        operation(op='suspend', name=name)
        exit()

    elif arguments['ssh']:
        name = arguments['<name>']
        user = arguments.get("--user")
        if user:
            options = {'user':user}
        else:
            options = {}
        operation(op='ssh', name=name, options=options)
        exit()

    elif arguments['scp']:
        name = arguments['<name>']
        name = arguments.get("--user")
        operation(op='scp', name=name, options={'user':user})
        exit()

    elif arguments['ip']:
        name = arguments['<name>']
        operation(op='ip', name=name, options={'user':user})
        exit()