jayze help


Create your own generator module

1. Create module file / code

Create the file lib/generator/gen_example.py and add the following code:

from lib.helper import *

class JayzeExample:
    """Minimal generator module example.
    def gen_example(self, foo, **options):
        """Example output.

        foo (str): some value.

        **options (kwargs):
            delay (float|int): how many seconds to idle after each output iteration.
            eol (str): which characters to add at the end of a output iteration.
        jayze_output('It is alive!', end=options['eol'])

        jayze_output('foo =', foo, end=options['eol'])

        jayze_output('options =', options, end=options['eol'])

2. Add your generator to jayze

Open lib/conf.py.

Import your generator at the top of the file:

from lib.generator.gen_example import JayzeExample

Add your generator argument to jayze_conf.args:

jayze_conf = {
    'args': [
        # Generator arguments
            'arg': '--gen-example',
            'metavar': 'FOO',
            'type': str,
            'default': False,

Generator arguments are parsed by lib/vendor/cliparser.py, which is just a simple argparse wrapper. Hence you can pretty much follow the docs from argparse to create the generator argument - with the exception that our default value should be False.

In jayze_conf.arg_map, add:

jayze_conf = {
    'arg_map': {
        # --gen-example
        # the key must match the argument arg key translation,
        # e.g. "--gen-example" will become "gen_example".
        'gen_example': {
            'class': JayzeExample,      # (object) class object
            'method': 'gen_example',    # (str) method to run
            # options the method accepts, these will be passed as kwargs to the method:
            'options': {
                # method key: args key
                'foo': 'gen_example',   # foo, gets value from args.gen_example (--gen-example)
                'delay': 'delay',       # delay, gets value from args.delay (--delay)
                'eol': 'eol',           # eol, gets value from args.eol (--eol)

3. Use your generator

jayze.py --verbose --gen-example yay

↑ top