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"))
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
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')
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)