# coding: utf-8 # Copyright (c) 2015 Fabian Barkhau <*****@*****.**> # License: MIT (see LICENSE file) import apigen class ArgumentsExample(apigen.Definition): def __init__(self, quiet=False, config_path="default/path.json"): self.quiet = quiet self.config_path = config_path @apigen.command() def show_args(self, first, second, optional="Default"): if not self.quiet: print("noise") return { 'first': first, 'second': second, 'optional': optional } @apigen.command() def arg_type(self, arg): return str(type(arg)) def on_stop_server(self): print "called on stop" if __name__ == "__main__": apigen.run(ArgumentsExample)
#!/usr/bin/env python # coding: utf-8 # Copyright (c) 2015 Fabian Barkhau <*****@*****.**> # License: MIT (see LICENSE file) import apigen # automatically added verison command will use module version if present # rpc exceptions will also include module version if persent __version__ = "1.0.0" class Calculator(apigen.Definition): # Programm name taken from class name. """Example Programm""" # Programm help text taken from class doc string. @apigen.command() def add(self, a, b): # Command name and args taken from method. """adds two items""" # Help text taken from method doc string. return a + b # Returned rpc/cli output (must be JSON serializable). if __name__ == "__main__": apigen.run(Calculator) # Run cli interface.
#!/usr/bin/env python # coding: utf-8 # Copyright (c) 2015 Fabian Barkhau <*****@*****.**> # License: MIT (see LICENSE file) import apigen class ReturnNull(apigen.Definition): @apigen.command() def test(self): return None if __name__ == "__main__": apigen.run(ReturnNull)
#!/usr/bin/env python """Script to auto-generate our API docs.""" import apigen import skfuzzy if __name__ == '__main__': apigen.run(skfuzzy)
@apigen.command() def challenge_prepare(self, shardid, challenges): # TODO validate input shard = storjlib.store.manager.open(self._cfg["storage"], shardid) return storjlib.challenge.prepare(shard, challenges) @apigen.command() def store_import(self, paths): raise NotImplementedError() @apigen.command() def store_export(self, shardid, path): raise NotImplementedError() @apigen.command() def store_add(self, shard_path): # TODO validate input shard = open(storjlib.util.full_path(shard_path), "rb") storjlib.store.manager.add(self._cfg["storage"], shard) return storjlib.store.shard.get_id(shard) @apigen.command() def store_remove(self, shardid): # TODO validate input storjlib.store.manager.remove(self._cfg["storage"], shardid) if __name__ == "__main__": apigen.run(Storjlib)
#!/usr/bin/env python # coding: utf-8 # Copyright (c) 2015 Fabian Barkhau <*****@*****.**> # License: MIT (see LICENSE file) import apigen class Ordering(apigen.Definition): @apigen.command() def first(self): return "first" @apigen.command() def second(self): return "second" @apigen.command() def third(self): return "third" @apigen.command() def fourth(self): return "fourth" if __name__ == "__main__": apigen.run(Ordering)
#!/usr/bin/env python # coding: utf-8 # Copyright (c) 2015 Fabian Barkhau <*****@*****.**> # License: MIT (see LICENSE file) import apigen class ArgumentsExample(apigen.Definition): def __init__(self, quiet=False, config_path="default/path.json"): self.quiet = quiet self.config_path = config_path @apigen.command() def show_args(self, first, second, optional="Default"): if not self.quiet: print("noise") return {'first': first, 'second': second, 'optional': optional} @apigen.command() def arg_type(self, arg): return str(type(arg)) def on_shutdown(self): print "called on stop" if __name__ == "__main__": apigen.run(ArgumentsExample)
#!/usr/bin/env python # coding: utf-8 # Copyright (c) 2015 Fabian Barkhau <*****@*****.**> # License: MIT (see LICENSE file) import apigen from decimal import Decimal class Calculator(apigen.Definition): # programm name taken from class name """example programm""" # programm help text taken from class doc string. @apigen.command() def add(self, a, b): # command name and args taken from method definition """adds two numbers""" # help text taken from method doc string result = float(Decimal(a) + Decimal(b)) return result # return rpc and cli output (must be JSON serializable) if __name__ == "__main__": apigen.run(Calculator) # run cli interface
def stop_swarm(nodes): stats = [] for storjnet, user_rpc_thread in nodes: stats.append(storjnet.stop()) if user_rpc_thread is not None: storjnet.stopserver() user_rpc_thread.join() return stats def run_swarm(**kwargs): swarm = start_swarm(**kwargs) # server until killed try: while True: time.sleep(1) # expected exit mode except KeyboardInterrupt: pass finally: stop_swarm(swarm) if __name__ == "__main__": apigen.run(StorjNet)
class ExampleProgramm(apigen.Definition): """Example programm help text from class doc string.""" def __init__(self, config="example.json", quiet=False): # programm positional and optional arguments taken from __init__ method # default argument of value False will be a flag in the cli pass @apigen.command() def example(self, positional_arg, optional_arg="example"): """Example command help text from method doc string.""" # arguments without defaults are required positional arguments in th cli # arguments with default values will be optional in the cli return "positional_arg = %s, optional_arg = %s" % (positional_arg, optional_arg) @apigen.command(rpc=False) # don't show in rpc interface def clionly(self): """Command only visible in cli interface.""" return "clionly" @apigen.command(cli=False) # don't show in cli interface def rpconly(self): """Command only visible in rpc interface.""" return "rpconly" if __name__ == "__main__": apigen.run(ExampleProgramm) # run cli interface
#!/usr/bin/env python import apigen from ngcccbase.api import Ngccc if __name__ == "__main__": apigen.run(Ngccc)