def run(self, loop=True):
        while True:
            logger.debug('Syncing messages.')
            submissions = storage.find_new_submissions(self.session)

            for db_submission in submissions:
                try:
                    sdk_submission = sdkobjects.Submission(
                        uuid=db_submission.uuid)
                    sdk_submission.source_uuid = db_submission.source.uuid
                    # Need to set filename on non-Qubes platforms
                    sdk_submission.filename = db_submission.filename

                    if self.api:
                        self.fetch_the_thing(sdk_submission, db_submission,
                                             self.api.download_submission,
                                             storage.mark_file_as_downloaded)
                        self.message_downloaded.emit(
                            db_submission.uuid,
                            get_data(self.home, db_submission.filename))
                except Exception as e:
                    logger.critical(
                        "Exception while downloading submission! {}".format(e))

            logger.debug('Completed message sync.')

            if not loop:
                break
            else:
                time.sleep(5)  # pragma: no cover
    def run(self, loop=True):
        while True:
            logger.debug('Syncing replies.')
            replies = storage.find_new_replies(self.session)

            for db_reply in replies:
                try:
                    # the API wants API objects. here in the client,
                    # we have client objects. let's take care of that
                    # here
                    sdk_reply = sdkobjects.Reply(uuid=db_reply.uuid)
                    sdk_reply.source_uuid = db_reply.source.uuid
                    # Need to set filename on non-Qubes platforms
                    sdk_reply.filename = db_reply.filename

                    if self.api:
                        self.fetch_the_thing(sdk_reply, db_reply,
                                             self.api.download_reply,
                                             storage.mark_reply_as_downloaded)
                        self.reply_downloaded.emit(
                            db_reply.uuid,
                            get_data(self.home, db_reply.filename))
                except Exception as e:
                    logger.critical(
                        "Exception while downloading reply! {}".format(e))

            logger.debug('Completed reply sync.')

            if not loop:
                break
            else:
                time.sleep(5)  # pragma: no cover
Exemplo n.º 3
0
 def add_item_content_or(self, adder, item, default):
     """
     Private helper function to add correct message to conversation widgets
     """
     if item.is_downloaded is False:
         adder(item.uuid, default)
     else:
         adder(item.uuid, get_data(self.sdc_home, item.filename))
Exemplo n.º 4
0
def test_get_data_success(homedir):
    orig_filename = 'foo.txt'
    filename, _ = os.path.splitext(orig_filename)
    contents = 'bar'
    with open(os.path.join(homedir, 'data', filename), 'w') as f:
        f.write(contents)
    out = get_data(homedir, orig_filename)
    assert out == contents
Exemplo n.º 5
0
def test_get_data_missing_data(homedir):
    orig_filename = 'foo.txt'
    out = get_data(homedir, orig_filename)
    assert out == '<Content deleted>'