def command(options=None, usage=None, name=None, shortlist=False, hide=False, aliases=()): global _dispatcher if not _dispatcher: _dispatcher = Dispatcher() return _dispatcher.command(options=options, usage=usage, name=name, shortlist=shortlist, hide=hide, aliases=aliases)
def dispatch(args=None, cmdtable=None, globaloptions=None, middleware=None, scriptname=None): global _dispatcher if not _dispatcher: _dispatcher = Dispatcher(cmdtable, globaloptions, middleware) else: if cmdtable: _dispatcher._cmdtable = CmdTable(cmdtable) if globaloptions: _dispatcher._globaloptions = [Option(o) for o in globaloptions] if middleware: _dispatcher.middleware = middleware return _dispatcher.dispatch(args, scriptname)
#!/usr/bin/env python from __future__ import print_function from opster import Dispatcher d = Dispatcher() @d.command() def cmd2(showhelp=('h', False, 'Print the help message')): if showhelp: print('Showing the help:') cmd2.help() d2 = Dispatcher() @d2.command() def subcmd1(quiet=('q', False, 'quietly'), showhelp=('h', False, 'Print the help message')): '''Help for subcmd1''' if not quiet: print('running subcmd1') if showhelp: print('Showing the help:') subcmd1.help() @d2.command() def subcmd2(number): '''Help for subcmd2''' print('running subcmd2', number) d3 = Dispatcher()
def extract_dict(source, *keys): dest = {} for k in keys: dest[k] = source.pop(k, None) return dest def inner(*args, **kwargs): opts = extract_dict(kwargs, 'host', 'port', 'color', 'timeout', 'debug') if func.__name__ == 'help_inner': return func(*args, **kwargs) locator = Global(**opts) return func(locator, *args, **kwargs) return inner d = Dispatcher(globaloptions=Global.options, middleware=middleware) appDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) class dispatcher(object): group = Dispatcher(globaloptions=Global.options, middleware=middleware) profileDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) runlistDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) crashlogDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) tracingDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) @d.command(name='locate', usage='[--name=NAME]') def locate(options,
def extract_dict(source, *keys): dest = {} for k in keys: dest[k] = source.pop(k, None) return dest def inner(*args, **kwargs): opts = extract_dict(kwargs, 'host', 'port', 'color', 'timeout', 'debug') if func.__name__ == 'help_inner': return func(*args, **kwargs) locator = Global(**opts) return func(locator, *args, **kwargs) return inner d = Dispatcher(globaloptions=Global.options, middleware=middleware) appDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) class dispatcher: group = Dispatcher(globaloptions=Global.options, middleware=middleware) profileDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) runlistDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) crashlogDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) proxyDispatcher = Dispatcher() @d.command() def info(options):
import gzip import sys from collections import OrderedDict from itertools import islice from opster import Dispatcher from py.path import local from .util import iter_google_store, readline_google_store, count_coccurrence dispatcher = Dispatcher() command = dispatcher.command @command() def download( ngram_len=('n', 1, 'The length of ngrams to be downloaded.'), output=('o', 'downloads/google_ngrams/{ngram_len}', 'The destination folder for downloaded files.'), verbose=('v', False, 'Be verbose.'), lang=( 'l', 'eng', 'Language. [eng|eng-us|eng-gb|eng-fiction|chi-sim|fre|ger|heb|ita|rus|spa]', ), ): """Download The Google Books Ngram Viewer dataset version 20120701.""" output = local(output.format(ngram_len=ngram_len)) output.ensure_dir() for fname, url, request in iter_google_store(ngram_len,
def inner(*args, **kwargs): try: repo = Repository(kwargs['config'], kwargs['define']) except NomadIniNotFound as e: sys.stderr.write("Create '%s' to use nomad, example:\n%s\n" % (e, EXAMPLE_INI)) abort('config file not found') except (IOError, NomadError) as e: abort(e) return func(repo=repo, *args, **kwargs) return inner app = Dispatcher(globaloptions=GLOBAL, middleware=getconfig) @app.command() def init(**opts): '''Initialize database migration management ''' try: opts['repo'].init_db() except DBError as e: abort(e) print('Versioning table initialized successfully') @app.command(name='list', aliases=('ls', )) def list_(all=('a', False, 'show all migrations (default: only non-applied)'),
dest = {} for k in keys: dest[k] = source.pop(k, None) return dest def inner(*args, **kwargs): opts = extract_dict(kwargs, "host", "port", "color", "timeout", "debug") if func.__name__ == "help_inner": return func(*args, **kwargs) locator = Global(**opts) return func(locator, *args, **kwargs) return inner d = Dispatcher(globaloptions=Global.options, middleware=middleware) appDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) class dispatcher: group = Dispatcher(globaloptions=Global.options, middleware=middleware) profileDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) runlistDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) crashlogDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) proxyDispatcher = Dispatcher() @d.command() def info(options):
class dispatcher: group = Dispatcher(globaloptions=Global.options, middleware=middleware)
for k in keys: dest[k] = source.pop(k, None) return dest def inner(*args, **kwargs): opts = extract_dict(kwargs, 'host', 'port', 'color', 'timeout', 'debug') if func.__name__ == 'help_inner': return func(*args, **kwargs) locator = Global(**opts) return func(locator, *args, **kwargs) return inner d = Dispatcher(globaloptions=Global.options, middleware=middleware) appDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) class dispatcher: group = Dispatcher(globaloptions=Global.options, middleware=middleware) profileDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) runlistDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) crashlogDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) proxyDispatcher = Dispatcher()
if func.__name__.startswith('help') or func.__name__ in ('version',): return func def inner(*args, **kwargs): try: repo = Repository(kwargs['config'], kwargs['define']) except NomadIniNotFound, e: sys.stderr.write("Create '%s' to use nomad, example:\n%s\n" % (e, EXAMPLE_INI)) abort('config file not found') except (IOError, NomadError), e: abort(e) return func(repo=repo, *args, **kwargs) return inner app = Dispatcher(globaloptions=GLOBAL, middleware=getconfig) @app.command() def init(**opts): '''Initialize database migration management ''' try: opts['repo'].init_db() except DBError, e: abort(e) print 'Versioning table initialized successfully' @app.command(name='list', aliases=('ls',)) def list_(all=('a', False, 'show all migrations (default: only non-applied)'),
selfhelp.help() else: print('no help for you!') if __name__ == '__main__': selfhelp.command(scriptname='selfhelp') ########NEW FILE######## __FILENAME__ = subcmds #!/usr/bin/env python from __future__ import print_function from opster import Dispatcher d = Dispatcher() @d.command() def cmd2(showhelp=('h', False, 'Print the help message')): if showhelp: print('Showing the help:') cmd2.help() d2 = Dispatcher() @d2.command() def subcmd1(quiet=('q', False, 'quietly'), showhelp=('h', False, 'Print the help message')): '''Help for subcmd1''' if not quiet: print('running subcmd1') if showhelp:
for k in keys: dest[k] = source.pop(k, None) return dest def inner(*args, **kwargs): opts = extract_dict(kwargs, 'host', 'port', 'color', 'timeout', 'debug') if func.__name__ == 'help_inner': return func(*args, **kwargs) locator = Global(**opts) return func(locator, *args, **kwargs) return inner d = Dispatcher(globaloptions=Global.options, middleware=middleware) appDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) class dispatcher(object): group = Dispatcher(globaloptions=Global.options, middleware=middleware) profileDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) runlistDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) crashlogDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware) tracingDispatcher = Dispatcher(globaloptions=Global.options, middleware=middleware)