Beispiel #1
0
def proceed_file(entity):
    # TODO: add database exception
    proceed_user(entity['owner'])
    user = db.User.get_or_none(uid=entity['owner'])
    upper_parent = db.Directory.get_or_none(
        name=general.name_from_path(entity['directory']))
    db.File.get_or_create(owner=user,
                          name=general.name_from_path(entity['path']),
                          inode=entity['info'].inode,
                          parent_id=upper_parent,
                          time_update=entity['info'].lastChangeData,
                          size=entity['size'])
Beispiel #2
0
def get_file_path(event):
    if event.file_name[0] == '/':
        return event.file_name
    elif event.file_name[0] == '.':
        return event.dir_path + general.name_from_path(event.file_name)
    else:
        return event.dir_path + "/" + event.file_name
Beispiel #3
0
def instance_file_dir_rename_or_move(db_model, old_event_inode,
                                     new_event_inode, event_path_to,
                                     parent_dir_to, time_update, info):
    inst, create_flag = db_create_or_get_ins_file_or_dir_from_event(
        db_model, old_event_inode, event_path_to, parent_dir_to, info)
    if old_event_inode != new_event_inode:
        inst.inode = new_event_inode
    if not create_flag:
        inst.name = general.name_from_path(event_path_to)
        inst.parent = parent_dir_to
    inst.time_update = time_update

    return (inst, create_flag)
Beispiel #4
0
def db_create_or_get_ins_file_or_dir_from_event(db_model,
                                                event_inode,
                                                event_path,
                                                event_parent=None,
                                                info=None):
    instance_of_model_file_dir = db_model.get_or_none(inode=event_inode)
    create_flag = False
    if not instance_of_model_file_dir:
        create_flag = True
        # uid, inode , isdir, size, date of modify
        if info:
            info_of_file_or_dir = info
        else:
            info_of_file_or_dir = get_info_by_event(None, event_path,
                                                    event_inode)
        # Create new instance
        instance_of_model_file_dir = db_model.create(inode=event_inode)
        # Set owner
        instance_of_model_file_dir.owner = db_get_or_create_user(
            info_of_file_or_dir.uid,
            general.uid_to_usr_str(info_of_file_or_dir.uid))
        # Set name
        name = general.name_from_path(event_path)
        if not name:
            logging.warning("Name will not set, inode:" + str(event_inode))
            return -1
        instance_of_model_file_dir.name = name
        # Set initial size 0
        instance_of_model_file_dir.size = info_of_file_or_dir.size
        # Set time update
        instance_of_model_file_dir.time_update = info_of_file_or_dir.date_change
        # Set parent
        if not event_parent:
            # uid, inode , isdir, size, date of modify
            parent_info = get_info_by_event(
                None, general.parent_path_from_path(event_path))
            parent_directory = db.Directory.get_or_none(
                inode=parent_info.inode)
            if parent_directory:
                instance_of_model_file_dir.parent = parent_directory
        else:
            instance_of_model_file_dir.parent = event_parent
        #instance_of_model_file_dir.save()
    return (instance_of_model_file_dir, create_flag)