Example #1
0
def backup_outgoing_message(private_message_object, message_id):
    """
    """
    if not driver.is_on('service_backups'):
        lg.warn('service_backups is not started')
        return False
    serialized_message = private_message_object.serialize()
    local_msg_folder = os.path.join(settings.ChatChannelsDir(),
                                    private_message_object.recipient, 'out')
    if not bpio._dir_exist(local_msg_folder):
        bpio._dirs_make(local_msg_folder)
    local_msg_filename = os.path.join(local_msg_folder, message_id)
    if not bpio.WriteBinaryFile(local_msg_filename, serialized_message):
        lg.warn('failed writing outgoing message locally')
        return False
    remote_path_for_message = os.path.join('.messages', 'out',
                                           private_message_object.recipient,
                                           message_id)
    global_message_path = global_id.MakeGlobalID(customer=messages_key_id(),
                                                 path=remote_path_for_message)
    res = api.file_create(global_message_path)
    if res['status'] != 'OK':
        lg.warn('failed to create path "%s" in the catalog: %s' %
                (global_message_path, res['errors']))
        return False
    res = api.file_upload_start(local_msg_filename,
                                global_message_path,
                                wait_result=False)
    if res['status'] != 'OK':
        lg.warn('failed to upload message "%s": %s' %
                (global_message_path, res['errors']))
        return False
    return True
Example #2
0
def exist_rating_dir(idurl):
    return bpio._dir_exist(rating_dir(idurl))