Example #1
0
def send_data(text, full_info, subject="", network_send=True):
    '''
    Sends the data to our servers through a post request
    '''
    files = {}
    # packs all the information into 'files'
    if full_info:
        files['report'] = get_metadata_archive()
    # This is the actual info: subject, text, email, username
    payload = {
        "text": text,
        "email": get_email(),
        "username": get_mixed_username(),
        "category": "os",
        "subject": subject
    }

    if not network_send:
        return True, None

    # send the bug report and remove all the created files
    success, error, data = request_wrapper('post', '/feedback',
                                           data=payload, files=files)
    delete_tmp_dir()

    if not success:
        return False, error
    if full_info:
        # kano-profile stat collection
        increment_app_state_variable_with_dialog('kano-feedback',
                                                 'bugs_submitted', 1)
        # logs were sent, clean up
        logging.cleanup()

    return True, None
def send_data(text, full_info, subject='', network_send=True, logs_path=''):
    """Sends the data to our servers through a post request.

    It uses :func:`~get_metadata_archive` to gather all the logs on
    the system.

    Args:
        text (str): The description of the email when sending the logs
        full_info (bool): Whether to attach all logs to the payload
        subject (str): The title of the email when sending the logs
        network_send (bool): Whether to send the data to our servers
        logs_path (str): Path to an existing logs archive to use instead

    Returns:
        bool, error: Whether the operation was successful or there was
        an error as returned by :func:`kano_world.functions.request_wrapper`
    """

    from kano_world.functions import get_email, get_mixed_username

    files = {}
    # packs all the information into 'files'
    if full_info:
        if logs_path and os.path.exists(logs_path):
            files['report'] = open(logs_path, 'rb')
        else:
            files['report'] = get_metadata_archive(title=subject, desc=text)
    # This is the actual info: subject, text, email, username
    payload = {
        "text": text,
        "email": get_email(),
        "username": get_mixed_username(),
        "category": "os",
        "subject": subject
    }

    if not network_send:
        return True, None

    # send the bug report and remove all the created files
    success, error, data = request_wrapper('post',
                                           '/feedback',
                                           data=payload,
                                           files=files)
    delete_tmp_dir()

    if not success:
        return False, error
    if full_info:
        # kano-profile stat collection
        from kano_profile.badges import increment_app_state_variable_with_dialog
        increment_app_state_variable_with_dialog('kano-feedback',
                                                 'bugs_submitted', 1)
        # logs were sent, clean up
        logging.cleanup()

    return True, None
def send_data(text, full_info, subject='', network_send=True, logs_path=''):
    """Sends the data to our servers through a post request.

    It uses :func:`~get_metadata_archive` to gather all the logs on
    the system.

    Args:
        text (str): The description of the email when sending the logs
        full_info (bool): Whether to attach all logs to the payload
        subject (str): The title of the email when sending the logs
        network_send (bool): Whether to send the data to our servers
        logs_path (str): Path to an existing logs archive to use instead

    Returns:
        bool, error: Whether the operation was successful or there was
        an error as returned by :func:`kano_world.functions.request_wrapper`
    """

    from kano_world.functions import get_email, get_mixed_username

    files = {}
    # packs all the information into 'files'
    if full_info:
        if logs_path and os.path.exists(logs_path):
            files['report'] = open(logs_path, 'rb')
        else:
            files['report'] = get_metadata_archive(title=subject, desc=text)
    # This is the actual info: subject, text, email, username
    payload = {
        "text": text,
        "email": get_email(),
        "username": get_mixed_username(),
        "category": "os",
        "subject": subject
    }

    if not network_send:
        return True, None

    # send the bug report and remove all the created files
    success, error, data = request_wrapper('post', '/feedback',
                                           data=payload, files=files)
    delete_tmp_dir()

    if not success:
        return False, error
    if full_info:
        # kano-profile stat collection
        from kano_profile.badges import increment_app_state_variable_with_dialog
        increment_app_state_variable_with_dialog('kano-feedback',
                                                 'bugs_submitted', 1)
        # logs were sent, clean up
        logging.cleanup()

    return True, None
Example #4
0
    def __init__(self, win):
        Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)

        self.win = win
        self.win.set_decorated(False)
        self.win.set_main_widget(self)

        self.heading = Heading(
            _("Reset your password"),
            _("We'll send a new password to your email")
        )
        self.pack_start(self.heading.container, False, False, 10)

        self.labelled_entries = LabelledEntries([
            {"heading": _("Email"), "subheading": ""}
        ])
        align = Gtk.Alignment(xscale=0, xalign=0.5)
        self.pack_start(align, False, False, 15)

        self.labelled_entries.set(0, 0, 1, 1)
        self.labelled_entries.set_hexpand(True)

        align.add(self.labelled_entries)

        # Read email from file
        user_email = get_email()

        self.email_entry = self.labelled_entries.get_entry(0)
        self.email_entry.set_text(user_email)
        self.email_entry.connect("key-release-event", self.activate)

        self.button = KanoButton(_("Reset password").upper())
        self.button.pack_and_align()
        self.button.connect("button-release-event", self.activate)
        self.button.connect("key-release-event", self.activate)
        self.button.set_padding(30, 30, 0, 0)

        self.pack_start(self.button.align, False, False, 0)
        self.win.show_all()
def send_question_response(answers, interactive=True, tags=['os', 'feedback-widget'],
                           debug=False, dry_run=False):
    '''
    This function is used by the Feedback widget to network-send the responses.
    The information (question_id, answer, username and email) is sent to a Kano API endpoint.

    answers is a list of tuples each having a Question ID and an Answer literal.

    The answers will be all packed into a payload object and sent in one single network transaction.
    '''

    from kano_world.functions import get_email, get_mixed_username

    ok_msg_title = _('Thank you')  # noqa: F821
    ok_msg_body = _(  # noqa: F821
        'We will use your feedback to improve your experience'
    )

    if interactive and not try_connect() or not try_login():
        # The answer will be saved as offline, act as if it was sent correctly
        thank_you = KanoDialog(ok_msg_title, ok_msg_body)
        thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        thank_you.run()

        return False

    payload = {
        'email': get_email(),
        'username': get_mixed_username(),
        'answers': [
            {
                'question_id': answer[0],
                'text': answer[1],
                'tags': tags
            } for answer in answers
        ]
    }

    if debug:
        print 'PAYLOAD construction:'
        print json.dumps(payload, sort_keys=True,
                         indent=4, separators=(',', ': '))

    # Send the answers unless we are testing the API
    if dry_run:
        return True

    success, error, dummy = request_wrapper('post', '/questions/responses',
                                            data=json.dumps(payload),
                                            headers=content_type_json)

    # Retry on error only if in GUI mode
    if not success:
        logger.error('Error while sending feedback: {}'.format(error))

        if not interactive:
            return False

        retry = KanoDialog(
            title_text=_('Unable to send'),  # noqa: F821
            description_text=_(  # noqa: F821
                'Error while sending your feedback. Do you want to retry?'
            ),
            button_dict={
                _('Close feedback').upper(): {  # noqa: F821
                    'return_value': False,
                    'color': 'red'
                },
                _('Retry').upper(): {  # noqa: F821
                    'return_value': True,
                    'color': 'green'
                }
            }
        )

        if retry.run():
            # Try again until they say no
            return send_question_response([(answer[0], answer)], interactive=interactive)

        return False

    if interactive:
        thank_you = KanoDialog(ok_msg_title, ok_msg_body)
        thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        thank_you.run()

    return True
Example #6
0
def send_question_response(answers, interactive=True, tags=['os', 'feedback-widget'],
                           debug=False, dry_run=False):
    '''
    This function is used by the Feedback widget to network-send the responses.
    The information (question_id, answer, username and email) is sent to a Kano API endpoint.

    answers is a list of tuples each having a Question ID and an Answer literal.

    The answers will be all packed into a payload object and sent in one single network transaction.
    '''

    ok_msg_title = _('Thank you')
    ok_msg_body = _('We will use your feedback to improve your experience')

    if interactive and not try_connect() or not try_login():
        # The answer will be saved as offline, act as if it was sent correctly
        thank_you = KanoDialog(ok_msg_title, ok_msg_body)
        thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        thank_you.run()

        return False

    payload = {
        'email': get_email(),
        'username': get_mixed_username(),
        'answers': [
            { 'question_id': answer[0],
              'text': answer[1],
              'tags': tags } for answer in answers
        ]
    }

    if debug:
        print 'PAYLOAD construction:'
        print json.dumps(payload, sort_keys=True,
                         indent=4, separators=(',', ': '))

    # Send the answers unless we are testing the API
    if dry_run:
        return True

    success, error, dummy = request_wrapper('post', '/questions/responses',
                                            data=json.dumps(payload),
                                            headers=content_type_json)

    # Retry on error only if in GUI mode
    if not success:
        logger.error('Error while sending feedback: {}'.format(error))

        if not interactive:
            return False

        retry = KanoDialog(
            title_text=_('Unable to send'),
            description_text=_('Error while sending your feedback. Do you want to retry?'),
            button_dict={
                _('Close feedback').upper():
                    {
                        'return_value': False,
                        'color': 'red'
                    },
                _('Retry').upper():
                    {
                        'return_value': True,
                        'color': 'green'
                    }
            }
        )

        if retry.run():
            # Try again until they say no
            return send_question_response([(answer[0], answer)], interactive=interactive)

        return False

    if interactive:
        thank_you = KanoDialog(ok_msg_title, ok_msg_body)
        thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        thank_you.run()

    return True
Example #7
0
def send_question_response(question_id, answer, interactive=True):
    '''
    This function is used by the Feedback widget.
    The information (question_id, answer, username and email) is sent to an API
    endpoint.
    '''

    ok_msg_title = 'Thank you'
    ok_msg_body = 'We will use your feedback to improve your experience'

    if interactive and not try_connect() or not try_login():
        # The answer will be saved as offline, act as if it was sent correctly
        thank_you = KanoDialog(ok_msg_title, ok_msg_body)
        thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        thank_you.run()

        return False

    payload = {
        'email': get_email(),
        'username': get_mixed_username(),
        'answers': [
            {
                'question_id': question_id,
                'text': answer,
                'tags': ['os', 'feedback-widget']
            }
        ]
    }

    # Send data
    success, error, dummy = request_wrapper('post', '/questions/responses',
                                            data=json.dumps(payload),
                                            headers=content_type_json)

    if not success:
        logger.error('Error while sending feedback: {}'.format(error))

        retry = KanoDialog(
            title_text='Unable to send',
            description_text=('Error while sending your feedback. ' \
                              'Do you want to retry?'),
            button_dict={
                'Close feedback'.upper():
                    {
                        'return_value': False,
                        'color': 'red'
                    },
                'Retry'.upper():
                    {
                        'return_value': True,
                        'color': 'green'
                    }
            }
        )

        if retry.run():
            # Try again until they say no
            return send_question_response(question_id=question_id,
                                          answer=answer,
                                          interactive=interactive)

        return False


    thank_you = KanoDialog(ok_msg_title, ok_msg_body)
    thank_you.dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
    thank_you.run()

    return True