"""create a WaveSolver in the engine namespace""" global solver solver = WaveSolver(*args, **kwargs) def wave_saver(u, x, y, t): """save the wave log""" global u_hist global t_hist t_hist.append(t) u_hist.append(1.0*u) # main program: if __name__ == '__main__': parser = argparse.ArgumentParser() paa = parser.add_argument paa('--grid', '-g', type=int, nargs=2, default=[100,100], dest='grid', help="Cells in the grid, e.g. --grid 100 200") paa('--partition', '-p', type=int, nargs=2, default=None, help="Process partition grid, e.g. --partition 4 2 for 4x2") paa('-c', type=float, default=1., help="Wave speed (I think)") paa('-Ly', type=float, default=1., help="system size (in y)") paa('-Lx', type=float, default=1.,
def main(): # This main is just simple enough that it is not worth the # complexity of argparse # What directory is mathjax in? parser = argparse.ArgumentParser( description="""Install mathjax from internet or local archive""", ) parser.add_argument('-i', '--install-dir', default=default_dest, help='installation directory (by default : %s)' % (default_dest)) parser.add_argument( '-d', '--dest', action='store_true', help='print where is current mathjax would be installed and exit') parser.add_argument( '-r', '--replace', action='store_true', help='Wether to replace current mathjax if already exist') parser.add_argument('-t', '--test', action='store_true') parser.add_argument('tarball', type=int, help="the local tar/zip-ball containing mathjax", nargs='?', metavar='tarball') pargs = parser.parse_args() dest = pargs.install_dir if pargs.dest: print dest return # remove/replace existing mathjax? if pargs.replace: replace = True else: replace = False # undocumented test interface if pargs.test: return test_func(replace, dest) # do it if pargs.tarball: fname = pargs.tarball # automatically detect zip/tar - could do something based # on file content, but really not cost-effective here. if fname.endswith('.zip'): extractor = extract_zip else: extractor = extract_tar # do it install_mathjax(file=open(fname, "r"), replace=replace, extractor=extractor, dest=dest) else: install_mathjax(replace=replace, dest=dest)
def _create_parser(self): self.parser = argparse.ArgumentParser(*self.args, **self.kw) self._add_arguments() self._add_other_arguments()
"""Convert a notebook to html in one step""" try: ConverterClass = converters[format] except KeyError: raise SystemExit("Unknown format '%s', " % format + "known formats are: " + known_formats) converter = ConverterClass(infile) converter.render() #----------------------------------------------------------------------------- # Script main #----------------------------------------------------------------------------- if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter) # TODO: consider passing file like object around, rather than filenames # would allow us to process stdin, or even http streams #parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), # default=sys.stdin) #Require a filename as a positional argument parser.add_argument('infile', nargs=1) parser.add_argument('-f', '--format', default='rst', help='Output format. Supported formats: \n' + known_formats) parser.add_argument('-p', '--preamble', help='Path to a user-specified preamble file') parser.add_argument('-e', '--exclude', default='', help='Comma-separated list of cells to exclude')
def get_args(): base_parser = argparse.ArgumentParser(add_help=False) base_parser.add_argument( '-r', action='store_true', dest='r', help= 'try to reuse FURL files. Use with --client-port and --engine-port') base_parser.add_argument( '--client-port', type=int, dest='client_port', help='the port the controller will listen on for client connections', default=0) base_parser.add_argument( '--engine-port', type=int, dest='engine_port', help='the port the controller will listen on for engine connections', default=0) base_parser.add_argument('-x', action='store_true', dest='x', help='turn off client security') base_parser.add_argument('-y', action='store_true', dest='y', help='turn off engine security') base_parser.add_argument( "--logdir", type=str, dest="logdir", help="directory to put log files (default=$IPYTHONDIR/log)", default=pjoin(get_ipython_dir(), 'log')) base_parser.add_argument("-n", "--num", type=int, dest="n", default=2, help="the number of engines to start") parser = argparse.ArgumentParser( description='IPython cluster startup. This starts a controller and\ engines using various approaches. Use the IPYTHONDIR environment\ variable to change your IPython directory from the default of\ .ipython or _ipython. The log and security subdirectories of your\ IPython directory will be used by this script for log files and\ security files.') subparsers = parser.add_subparsers( help='available cluster types. For help, do "ipcluster TYPE --help"') parser_local = subparsers.add_parser('local', help='run a local cluster', parents=[base_parser]) parser_local.set_defaults(func=main_local) parser_mpirun = subparsers.add_parser( 'mpirun', help='run a cluster using mpirun (mpiexec also works)', parents=[base_parser]) parser_mpirun.add_argument( "--mpi", type=str, dest="mpi", # Don't put a default here to allow no MPI support help="how to call MPI_Init (default=mpi4py)") parser_mpirun.set_defaults(func=main_mpi, cmd='mpirun') parser_mpiexec = subparsers.add_parser( 'mpiexec', help='run a cluster using mpiexec (mpirun also works)', parents=[base_parser]) parser_mpiexec.add_argument( "--mpi", type=str, dest="mpi", # Don't put a default here to allow no MPI support help="how to call MPI_Init (default=mpi4py)") parser_mpiexec.set_defaults(func=main_mpi, cmd='mpiexec') parser_pbs = subparsers.add_parser('pbs', help='run a pbs cluster', parents=[base_parser]) parser_pbs.add_argument('--pbs-script', type=str, dest='pbsscript', help='PBS script template', default='pbs.template') parser_pbs.set_defaults(func=main_pbs) parser_ssh = subparsers.add_parser( 'ssh', help='run a cluster using ssh, should have ssh-keys setup', parents=[base_parser]) parser_ssh.add_argument( '--clusterfile', type=str, dest='clusterfile', help='python file describing the cluster', default='clusterfile.py', ) parser_ssh.add_argument('--sshx', type=str, dest='sshx', help='sshx launcher helper') parser_ssh.set_defaults(func=main_ssh) args = parser.parse_args() return args