Exemple #1
0
    def select(self, choices):
        if not choices:
            raise Error("Internal error: no choices!")

        if len(choices) == 1 or self.batch:
            result = 1

        else:
            just = len(str(len(choices)))
            index = 1
            for choice in choices:
                echo(str(index).rjust(just), ':', choice)
                index += 1

            while True:
                answer = input('[1] > ')
                if not answer:
                    result = 1

                else:
                    try:
                        result = int(answer)

                    except ValueError:
                        result = None

                if result and 1 <= result <= len(choices):
                    break

                else:
                    echo("Bad response")

        result = choices[result - 1]
        echo(result)
        return result
Exemple #2
0
    def select(self, choices):
        if not choices:
            raise Error("Internal error: no choices!")

        if len(choices) == 1 or self.batch:
            result = 1

        else:
            just = len(str(len(choices)))
            index = 1
            for choice in choices:
                echo(str(index).rjust(just), ':', choice)
                index += 1

            while True:
                answer = input('[1] > ')
                if not answer:
                    result = 1

                else:
                    try:
                        result = int(answer)

                    except ValueError:
                        result = None

                if result and 1 <= result <= len(choices):
                    break

                else:
                    echo("Bad response")

        result = choices[result - 1]
        echo(result)
        return result
Exemple #3
0
    def select(self, choices):
        if not choices:
            raise Error("Internal error: no choices!")

        chosen_index = None
        skipping = False

        if len(choices) == 1 or self.batch:
            chosen_index = 1

        else:
            just = len(str(len(choices)))
            index = 1
            for choice in choices:
                echo(" {} : {}".format(str(index).rjust(just), choice))
                index += 1

            echo(" S : Skip")

            while True:
                answer = input('[1] > ')

                if not answer:
                    chosen_index = 1

                elif answer.lower() == "s":
                    skipping = True

                else:
                    try:
                        chosen_index = int(answer)

                    except ValueError:
                        pass

                if skipping or (chosen_index
                                and 1 <= chosen_index <= len(choices)):
                    break

                else:
                    echo("Bad response")

        if skipping:
            echo("Skipping")
            return None

        result = choices[chosen_index - 1]
        echo("{}".format(result))
        return result
Exemple #4
0
    def select(self, choices):
        if not choices:
            raise Error("Internal error: no choices!")

        chosen_index = None
        skipping = False

        if len(choices) == 1 or self.batch:
            chosen_index = 1

        else:
            just = len(str(len(choices)))
            index = 1
            for choice in choices:
                echo(" {} : {}".format(str(index).rjust(just), choice))
                index += 1

            echo(" S : Skip")

            while True:
                answer = input('[1] > ')

                if not answer:
                    chosen_index = 1

                elif answer.lower() == "s":
                    skipping = True

                else:
                    try:
                        chosen_index = int(answer)

                    except ValueError:
                        pass

                if skipping or (chosen_index and
                                1 <= chosen_index <= len(choices)):
                    break

                else:
                    echo("Bad response")

        if skipping:
            echo("Skipping")
            return None

        result = choices[chosen_index - 1]
        echo(result)
        return result
Exemple #5
0
    def confirm(self, question, default=None):
        responses = 'yn' if default is None else 'Yn' if default else 'yN'
        question += ' [{}] > '.format(responses)

        if self.batch:
            return True

        while True:
            answer = input(question).lower()
            if answer in ('y', 'n'):
                return answer == 'y'

            elif answer == '' and default is not None:
                return default

            else:
                echo('Bad answer')
Exemple #6
0
    def confirm(self, question, default=None):
        responses = 'yn' if default is None else 'Yn' if default else 'yN'
        question += ' [{}] > '.format(responses)

        if self.batch:
            return True

        while True:
            answer = input(question).lower()
            if answer in ('y', 'n'):
                return answer == 'y'

            elif answer == '' and default is not None:
                return default

            else:
                echo('Bad answer')
Exemple #7
0
    def launch(self):
        user = input('User: '******'Password: ')

        self.args.session = login(user, password)
        self.args.save_session()
Exemple #8
0
    def launch(self):
        user = input('User: '******'Password: ')

        self.args.session = login(user, password)
        self.args.save_session()