Ejemplo n.º 1
0
    def choose_rigging(rigging=None):
        choices = []
        for c_rigging in rigging:
            rigging_name = c_rigging.get("rigging_name")
            platform = c_rigging.get("platform")
            choices.append("[R] %-15s [P] %-s" % (rigging_name, platform))

        questions = [
            {
                'type': 'list',
                'name': 'rigging_choice',
                'message': 'Which rigging would you like to choose?',
                'choices': choices
            }
        ]
        style = style_from_dict({
            Token.Selected: '#00FFFF bold',
        })
        answers = prompt(questions, style=style)
        choice = answers.get('rigging_choice')

        for c_rigging in rigging:
            rigging_name = c_rigging.get("rigging_name")
            platform = c_rigging.get("platform")
            if choice == "[R] %-15s [P] %-s" % (rigging_name, platform):
                return c_rigging
        return None
Ejemplo n.º 2
0
    def what_now(self):
        print(self.counts)

        style = style_from_dict({
            Token.Separator:
            '#6C6C6C',
            Token.QuestionMark:
            '#FF9D00 bold',
            #Token.Selected: '',  # default
            Token.Selected:
            '#5F819D',
            Token.Pointer:
            '#FF9D00 bold',
            Token.Instruction:
            '',  # default
            Token.Answer:
            '#5F819D bold',
            Token.Question:
            '',
        })

        questions = [{
            'type': 'confirm',
            'message': f"Save results to: {self.out_filename}: ",
            'name': 'save',
            'default': 'True'
        }]
Ejemplo n.º 3
0
 def execute(self, context):
     questions = [{
         'type': 'list',
         'name': 'engine',
         'message': 'Which Orchestration Engine would you like to choose?',
         'choices': ["Kubernetes", "Swarm"]
     }]
     style = style_from_dict({
         Token.Selected: '#00FFFF bold',
     })
     answers = prompt(questions, style=style)
     recorder = Derrick().get_recorder()
     try:
         recorder.record(answers)
     except Exception as e:
         Logger.error("Failed to record config, Because of %s" % e)
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-
"""
* Pizza delivery prompt example
* run example by writing `python example/pizza.py` in your console
"""
from __future__ import print_function, unicode_literals
import regex

from whaaaaat import style_from_dict, Token, prompt, print_json
from whaaaaat import Validator, ValidationError

style = style_from_dict({
    Token.QuestionMark: '#FF9D00 bold',
    Token.Selected: '#5F819D bold',
    Token.Instruction: '',  # default
    Token.Answer: '#5F819D bold',
    Token.Question: '',
})


class PhoneNumberValidator(Validator):
    def validate(self, document):
        ok = regex.match(
            '^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$',
            document.text)
        if not ok:
            raise ValidationError(message='Please enter a valid phone number',
                                  cursor_position=len(
                                      document.text))  # Move cursor to end

Ejemplo n.º 5
0
    'contact_info_page_close_button':
    '#app > div > div > div:nth-child(2) > div:last-of-type > span > div > span > div > header > div > div > button',
    'chat_or_message_search':
    '#side > div:nth-child(3) > div > label > div > div:last-child',
    'chats_groups_messages_elements':
    '#side > div:last-child > div > div > div > div',
    'contact_element':
    'span > span > span[class^="matched-text"]',
    'group_element':
    'div:last-child > div:first-child > div:first-child > div > span > span[class^="matched-text"]',
}
# endregion

# region PATHS
data_folder_path = Path.home() / 'wplay'
logs_path = Path.home() / 'wplay' / 'logs'
user_data_folder_path = Path.home() / 'wplay' / '.userData'
# endregion

# region MENU STYLES
menu_style = style_from_dict({
    Token.Separator: '#6C6C6C',
    Token.QuestionMark: '#FF9D00 bold',
    Token.Selected: '#5F819D',
    Token.Pointer: '#FF9D00 bold',
    Token.Instruction: '',  # default
    Token.Answer: '#5F819D bold',
    Token.Question: '',
})
# endregion
Ejemplo n.º 6
0
    def save_results(self):
        style = style_from_dict({
            Token.Separator:
            '#6C6C6C',
            Token.QuestionMark:
            '#FF9D00 bold',
            #Token.Selected: '',  # default
            Token.Selected:
            '#5F819D',
            Token.Pointer:
            '#FF9D00 bold',
            Token.Instruction:
            '',  # default
            Token.Answer:
            '#5F819D bold',
            Token.Question:
            '',
        })

        if self.out_filename != None:

            questions = [{
                'type': 'confirm',
                'message': f"Save results to: {self.out_filename}: ",
                'name': 'save',
                'default': 'True'
            }]
        else:  # NOT DONE

            questions = [{
                'type':
                'expand',
                'message':
                'Save file on `file.js`: ',
                'name':
                'overwrite',
                'default':
                'a',
                'choices': [{
                    'key': 'y',
                    'name': 'Overwrite',
                    'value': 'overwrite'
                }, {
                    'key': 'a',
                    'name': 'Overwrite this one and all next',
                    'value': 'overwrite_all'
                }, {
                    'key': 'd',
                    'name': 'Show diff',
                    'value': 'diff'
                },
                            Separator(), {
                                'key': 'x',
                                'name': 'Abort',
                                'value': 'abort'
                            }]
            }]

        answer = prompt(questions, style=style)
        if answer['save']:
            self.save_json()
Ejemplo n.º 7
0
class BaseCommitizen(object):
    __metaclass__ = ABCMeta
    style = style_from_dict({
        Token.Separator: '#6C6C6C',
        Token.QuestionMark: '#FF9D00 bold',
        Token.Selected: '#5F819D',
        Token.Pointer: '#FF9D00 bold',
        Token.Instruction: '',  # default
        Token.Answer: '#5F819D bold',
        Token.Question: '',
    })

    @abstractmethod
    def questions(self):
        """Questions regarding the commit message.

        Must have 'whaaaaat' format.
        More info: https://github.com/finklabs/whaaaaat/

        :rtype: list
        """

    @abstractmethod
    def message(self, answers):
        """Format your git message.

        :param answers: Use answers
        :type answers: dict

        :rtype: string
        """

    def commit(self, message):
        f = NamedTemporaryFile('wb', delete=False)
        f.write(message.encode('utf-8'))
        f.close()

        c = delegator.run('git commit -a -F {0}'.format(f.name), block=True)
        print(c.out or c.err)

        os.unlink(f.name)
        return c

    def example(self):
        """Example of the commit message.

        :rtype: string
        """
        raise NotImplementedError("Not Implemented yet")

    def schema(self):
        """Schema definition of the commit message.

        :rtype: string
        """
        raise NotImplementedError("Not Implemented yet")

    def info(self):
        """Information about the standardized commit message.

        :rtype: string
        """
        raise NotImplementedError("Not Implemented yet")

    def show_example(self, *args, **kwargs):
        logger.info(self.example())

    def show_schema(self, *args, **kwargs):
        logger.info(self.schema())

    def show_info(self, *args, **kwargs):
        logger.info(self.info())

    def run(self, *args, **kwargs):
        questions = self.questions()
        answers = prompt(questions, style=self.style)
        logger.debug('Answers:\n %s', answers)
        m, change_type = self.message(answers)
        logger.debug('Commit message generated:\n %s', m)

        c = self.commit(m)

        if c.err:
            logger.warning(c.err)
            sys.exit(1)

        if 'nothing added' not in c.out:
            logger.info('Commit successful!')

        return change_type