Beispiel #1
0
        def ok_handler():
            result = add_headers_to_db(event, name)

            if result.get('success'):
                root_container.floats.pop()
                event.app.layout.focus(ButtonManager.prev_button)
                select_item(event)
Beispiel #2
0
        def ok_handler():

            # Simplistic check to see if user forgot to enter something for url
            url = len(self.url.text) > len('https://')

            if not all([self.name.text, url, self.method.text]):
                return ErrorDialog(event, title='Input Error',
                                   text='Name, Url, and Method are required.')

            result = server_to_db()

            if result.get('success'):

                root_container.floats.pop()

                # Rather than inserting a new button into, e.g.,
                # hsplit.children, we recreate the layout since we have to
                # pay attention to sort order here
                event.app.layout = Layout(root_container.create())

                # Find the button in the redrawn layout; then focus on it
                buttons = ButtonManager.update_buttons(event.app)
                for button in buttons:
                    if self.name.text == button.content.text()[1][1].strip():
                        event.app.layout.focus(button)
                        break

                select_item(event)

            else:
                # Add/update server returned an error
                ErrorDialog(event, title='Add/edit server error',
                            text=str(result.get('errors')))
Beispiel #3
0
def update_body(event):
    """Uses external editor to create/update request body."""

    EDITOR = os.environ.get('EDITOR', None)

    if not EDITOR:
        return ErrorDialog(
            event,
            title='Error',
            text='Please set your $EDITOR environement variable')

    tf = tempfile.NamedTemporaryFile()

    name = ButtonManager.current_button

    result = db.fetch_one(name=name)

    if result.body:
        with open(tf.name, 'w') as fout:
            fout.write(result.body)

    j = "+'set ft=json"

    call([EDITOR, j, tf.name])

    with open(tf.name, 'r') as fin:
        body = fin.read()

    db.update_one(values={'name': name, 'body': body})

    event.app.reset()
    select_item(event)
Beispiel #4
0
def delete_server(event, name):

    db.delete_one(name)

    buttons = servers.hsplit.children

    # The server has been removed from the db. Now, we have to remove the
    # button from the layout by iterating over buttons and removing it by index
    for idx, button in enumerate(buttons):
        if name == button.content.text()[1][1].strip():

            del buttons[idx]

            if len(buttons) > 0:

                try:
                    # If the deleted button was not the last button
                    event.app.layout.focus(buttons[idx])
                    ButtonManager.prev_button = buttons[idx]
                    select_item(event)

                except IndexError:
                    # If the deleted button was the last button
                    event.app.layout.focus(buttons[idx - 1])
                    ButtonManager.prev_button = buttons[idx - 1]
                    select_item(event)

            else:
                # Last button was deleted, display message "No servers"

                control = FormattedTextControl('No Servers',
                                               focusable=True,
                                               show_cursor=False)

                window = Window(control,
                                height=1,
                                dont_extend_width=True,
                                dont_extend_height=True)

                buttons.append(window)

                summary_buffer.read_only = to_filter(False)
                summary_buffer.text = ''
                summary_buffer.read_only = to_filter(True)

                ButtonManager.prev_button = None
                ButtonManager.current_button = None

                event.app.layout.focus(servers.content)
Beispiel #5
0
    def ok_handler(self):
        authuser = self.authuser.text
        authpass = self.authpass_one.text

        all_fields = all([authuser, authpass])
        empty_fields = not any([authuser, authpass])

        if authpass != self.authpass_two.text:
            ErrorDialog(self.event,
                        title='Password Error',
                        text='Passwords do not match, please try again')

        elif all_fields or empty_fields:

            if all_fields:
                result = db.update_one({
                    'name':
                    self.name,
                    'auth':
                    json.dumps({
                        'user': authuser,
                        'password': authpass,
                        'type': self.authtype
                    })
                })

            elif empty_fields:
                result = db.update_one(values={
                    'name': self.name,
                    'auth': None
                })

            if result.get('success'):
                root_container.floats.pop()
                self.event.app.layout.focus(ButtonManager.prev_button)
                select_item(self.event)

            else:
                ErrorDialog(self.event,
                            title='Add/edit server error',
                            text=result.get('errors'))

        else:
            ErrorDialog(self.event,
                        title='Input Error',
                        text='Missing one or more fields.')
Beispiel #6
0
 def ok_handler():
     root_container.floats.pop()
     db.update_one(values={'name': name, 'auth': None})
     event.app.layout.focus(ButtonManager.prev_button)
     select_item(event)