コード例 #1
0
def run_generic_addon_wizard():
    """Ask the user general questions needed to create any addon types."""
    import editor
    from pypsi import wizard
    from pypsi.completers import choice_completer

    package_name_step = wizard.WizardStep(
        'package_name',
        'package_name',
        validators=[
            wizard.required_validator,
            _string_length_validator(1, 200), wizard.lowercase_validator
        ],
        help='The name that this addon should be packaged as.')

    version_step = wizard.WizardStep(
        'version',
        'version',
        default='0.0.1',
        validators=[wizard.required_validator, _setuptools_version_validator],
        help=dedent("""
            The version of the addon.

            Often a simple scheme like a dot separated list of major version,
            minor version and patch number will suffice.

            For inspiration and suggestions about what options are available,
            please see PEP404: https://www.python.org/dev/peps/pep-0440/

            The version number shall be compatible with Python's setuptools.
            """))

    description_step = wizard.WizardStep(
        'description',
        'description',
        validators=[
            wizard.required_validator,
            _string_length_validator(1, 200), _escape_single_quote_validator
        ],
        help='A one-line summary of the addon.')

    long_description_step = wizard.WizardStep(
        'long_description',
        'long_description (press tab to launch editor)',
        validators=[wizard.required_validator, _escape_single_quote_validator],
        completer=lambda shell, path, prefix: [editor.edit().decode('UTF-8')],
        help='A more detailed description of the addon.')

    maintainer_step = wizard.WizardStep(
        'maintainer',
        'maintainer',
        validators=[
            wizard.required_validator,
            _string_length_validator(1, 200)
        ],
        help='Name of the person or group maintaining this addon.')

    maintainer_email_step = wizard.WizardStep(
        'maintainer_email',
        'maintainer_email',
        validators=[
            wizard.required_validator, _email_validator,
            _string_length_validator(1, 200)
        ],
        help='E-mail that can be used to reach the maintainer.')

    install_requires_step = wizard.WizardStep(
        'install_requires',
        'install_requires (may be empty)',
        help=dedent("""
            A comma-separated list of packages that this addon requires.

            Version requirements may be specified using Python logic operations.
            For instance the requirement of a specific version of a package may
            be expressed using the 'package==X.Y.Z' syntax.

            Specifying strict version dependencies should be avoided where
            possible, to avoid the difficult to resolve situation where multiple
            addons depend on different specific versions of the same package.

            If your addon requires a feature that was introduced in a specific
            version, a better solution would be to specify that the addon
            requires a version of the package that is greater than X.Y.Z, using
            the 'package>=X.Y.Z' syntax.

            When in doubt, it is best to leave the version information out.
            """))

    entrypoint_step = wizard.WizardStep(
        'entrypoint',
        'entrypoint (class name, use camelcase)',
        validators=[
            wizard.required_validator,
            _string_length_validator(1, 200), _camel_case_validator
        ],
        help=dedent("""
        Name the entrypoint for this addon.

        The entrypoint will be a class and should have a CamelCased name.

        For more information on naming conventions in K2, please see PEP-8:
        https://www.python.org/dev/peps/pep-0008/
        """))

    addon_path_step = wizard.WizardStep(
        'addon_path',
        'path to K2\'s addons root directory',
        validators=[wizard.directory_validator],
        completer=_path_completer,
        default=os.path.abspath(os.path.join(k2.__path__[0], '..', 'addons')),
        help=
        'Path to the K2 addons directory where this addon should be created.')

    addon_type_step = wizard.WizardStep(
        'addon_type',
        'addon_type',
        validators=[
            wizard.required_validator,
            wizard.choice_validator(['framework', 'command'])
        ],
        completer=choice_completer(['framework', 'command'],
                                   case_sensitive=True),
        help=dedent("""
            Select what type of addon you wish to create.

            There are two choices: framework or command.

            Framework extensions have the ability to extend the functionality of
            the K2 framework. They have the ability to add commands or to
            provide new general functionality to the K2 core framework.

            Command extensions have the ability to extend specific commands.
            """))

    return _run_pypsi_wizard(
        wizard.PromptWizard('Addon Creation',
                            dedent("""
            This wizard will guide you through the creation of a K2 addon.

            Please answer the following questions about your K2 addon:
            """),
                            steps=[
                                addon_type_step,
                                package_name_step,
                                version_step,
                                description_step,
                                long_description_step,
                                maintainer_step,
                                maintainer_email_step,
                                install_requires_step,
                                entrypoint_step,
                                addon_path_step,
                            ]))
コード例 #2
0
ファイル: demo.py プロジェクト: ameily/pypsi
            default=1337
        ),
        wiz.WizardStep(
            id='path',
            name='File path',
            help='File path to log file',
            validators=wiz.file_validator,
            # Tab complete based on path
            completer=path_completer
        ),
        wiz.WizardStep(
            id='mode',
            name='Shell mode',
            help='Mode of the shell',
            default='local',
            validators=(wiz.required_validator, wiz.choice_validator(['local', 'remote']))
        )
    )
)


class DemoShell(Shell):
    '''
    Example demonstration shell.
    '''

    # First, add commands and plugins to the shell
    wizard_cmd = WizardCommand()
    echo_cmd = EchoCommand()
    block_plugin = BlockPlugin()
    hexcode_plugin = HexCodePlugin()
コード例 #3
0
                       validators=(wiz.required_validator,
                                   wiz.int_validator(1024, 65535)),
                       default=1337),
        wiz.WizardStep(
            id='path',
            name='File path',
            help='File path to log file',
            validators=wiz.file_validator,
            # Tab complete based on path
            completer=path_completer),
        wiz.WizardStep(id='mode',
                       name='Shell mode',
                       help='Mode of the shell',
                       default='local',
                       validators=(wiz.required_validator,
                                   wiz.choice_validator(['local',
                                                         'remote'])))))


class DemoShell(Shell):
    '''
    Example demonstration shell.
    '''

    # First, add commands and plugins to the shell
    wizard_cmd = WizardCommand()
    echo_cmd = EchoCommand()
    block_plugin = BlockPlugin()
    hexcode_plugin = HexCodePlugin()
    macro_cmd = MacroCommand()

    # Drop commands to cmd.exe if the platform is Windows
コード例 #4
0
ファイル: test_wizard.py プロジェクト: twisted-fun/pypsi
 def test_choice_validator_int(self):
     validator = wiz.choice_validator(['opt1', 'opt2'])
     assert validator(Namespace(), 10) == 10
コード例 #5
0
ファイル: test_wizard.py プロジェクト: twisted-fun/pypsi
 def test_choice_validator_empty(self):
     validator = wiz.choice_validator(['opt1', 'opt2'])
     assert validator(Namespace(), '   ') == ''
コード例 #6
0
ファイル: test_wizard.py プロジェクト: twisted-fun/pypsi
 def test_choice_validator_invalid(self):
     validator = wiz.choice_validator(['opt1', 'opt2'])
     with pytest.raises(ValueError):
         validator(Namespace(), 'option-1')