Esempio n. 1
0
def member_remove():
    id_struct = check_struct_id(bottle.request.query.id_struct)
    id_member = bottle.request.query.id_member

    if id_member != 0 and not id_member:
        return bottle.template("error", msg="member id missing")

    if id_struct != 0 and not id_struct:
        return bottle.template("error", msg="Bad struct id")
    id_struct = str(id_struct)

    struct = _dynStruct.Struct.get_by_id(id_struct)    
    if not struct:
        return bottle.template("error", msg="bad struct id")

    member = struct.get_member(int(id_member))
    next_member = struct.get_member(int(id_member) + member.size)

    prev_member = None
    if struct.members.index(member) > 0:
        prev_member = struct.members[struct.members.index(member) - 1]

    struct.members.remove(member)

    # by removing the next or previous padding a new padding with the size
    # of the old padding + the size of removed member will be created
    if next_member and next_member.is_padding:
        struct.members.remove(next_member)
    if prev_member and prev_member.is_padding:
        struct.members.remove(prev_member)
    
    struct.add_pad()
    
    _dynStruct.save_modif()
    bottle.redirect("/struct?id=%s" % (id_struct))
Esempio n. 2
0
def member_do_edit():
    id_struct = check_struct_id(bottle.request.query.id_struct)
    id_member = bottle.request.query.id_member

    if id_member != 0 and not id_member:
        return bottle.template("error", msg="member id missing")

    if not id_struct:
        return bottle.template("error", msg="Bad struct id")

    struct = _dynStruct.Struct.get_by_id(id_struct)    
    if not struct:
        return bottle.template("error", msg="bad struct id")

    member = struct.get_member(int(id_member))
    next_member = struct.get_member(int(id_member) + member.size)

    try:
        member.edit(bottle.request.forms, next_member, struct.size)
    except ValueError as err:
        return bottle.template("error", msg=str(err))

    # if next member is padding remove it, add_pad will set a new padding with
    # correct size + offset if needed
    if next_member and next_member.is_padding:
        struct.members.remove(next_member)

    struct.add_pad()
    _dynStruct.save_modif()
    bottle.redirect("/member?id_struct=%s&id_member=%s" % (id_struct, id_member))
Esempio n. 3
0
def member_do_create():
    id_struct = check_struct_id(bottle.request.query.id_struct)
    id_member = bottle.request.query.id_member

    if not id_member:
        return bottle.template("error", msg="member id missing")

    if not id_struct:
        return bottle.template("error", msg="Bad struct id")

    struct = _dynStruct.Struct.get_by_id(id_struct)    
    if not struct:
        return bottle.template("error", msg="bad struct id")

    member = struct.get_member(int(id_member))

    if not member:
        return bottle.template("error", msg="Bad member id")        

    if not member.is_padding:
        return bottle.template("error", msg="To add a member, member_id have to point to a padding member")

    try:
        struct.add_member_from_web_ui(member, bottle.request.forms)
    except ValueError as err:
        struct.add_pad()
        return bottle.template("error", msg=str(err))
        
    struct.members.remove(member)
    struct.add_pad()
    _dynStruct.save_modif()
    if '.' in id_struct:
        bottle.redirect("/member?id_struct=%s&id_member=%s" % (id_struct[:id_struct.rfind('.')], id_struct[id_struct.rfind('.') + 1:]))
    else:
        bottle.redirect("/struct?id=%s" % (id_struct))
Esempio n. 4
0
def member_remove():
    id_struct = check_struct_id(bottle.request.query.id_struct)
    id_member = bottle.request.query.id_member

    if id_member != 0 and not id_member:
        return bottle.template("error", msg="member id missing")

    if id_struct != 0 and not id_struct:
        return bottle.template("error", msg="Bad struct id")
    id_struct = str(id_struct)

    struct = _dynStruct.Struct.get_by_id(id_struct)
    if not struct:
        return bottle.template("error", msg="bad struct id")

    member = struct.get_member(int(id_member))
    next_member = struct.get_member(int(id_member) + member.size)

    prev_member = None
    if struct.members.index(member) > 0:
        prev_member = struct.members[struct.members.index(member) - 1]

    struct.members.remove(member)

    # by removing the next or previous padding a new padding with the size
    # of the old padding + the size of removed member will be created
    if next_member and next_member.is_padding:
        struct.members.remove(next_member)
    if prev_member and prev_member.is_padding:
        struct.members.remove(prev_member)

    struct.add_pad()

    _dynStruct.save_modif()
    bottle.redirect("/struct?id=%s" % (id_struct))
Esempio n. 5
0
def member_do_edit():
    id_struct = check_struct_id(bottle.request.query.id_struct)
    id_member = bottle.request.query.id_member

    if id_member != 0 and not id_member:
        return bottle.template("error", msg="member id missing")

    if not id_struct:
        return bottle.template("error", msg="Bad struct id")

    struct = _dynStruct.Struct.get_by_id(id_struct)
    if not struct:
        return bottle.template("error", msg="bad struct id")

    member = struct.get_member(int(id_member))
    next_member = struct.get_member(int(id_member) + member.size)

    try:
        member.edit(bottle.request.forms, next_member, struct.size)
    except ValueError as err:
        return bottle.template("error", msg=str(err))

    # if next member is padding remove it, add_pad will set a new padding with
    # correct size + offset if needed
    if next_member and next_member.is_padding:
        struct.members.remove(next_member)

    struct.add_pad()
    _dynStruct.save_modif()
    bottle.redirect("/member?id_struct=%s&id_member=%s" %
                    (id_struct, id_member))
Esempio n. 6
0
def struct_do_detect():
    id_struct = check_struct_id(bottle.request.query.id_struct)
    if not id_struct:
        return bottle.template("error", msg="Bad struct id")
    struct = _dynStruct.Struct.get_by_id(id_struct)
    struct.detect(_dynStruct.l_block)
    _dynStruct.save_modif()
    bottle.redirect("/struct?id=%s" % (id_struct))
Esempio n. 7
0
def struct_do_detect():
    id_struct = check_struct_id(bottle.request.query.id_struct)
    if not id_struct:
        return bottle.template("error", msg="Bad struct id")
    struct = _dynStruct.Struct.get_by_id(id_struct)
    struct.detect(_dynStruct.l_block) 
    _dynStruct.save_modif()
    bottle.redirect("/struct?id=%s" % (id_struct))
Esempio n. 8
0
def remove_struct_from_block():
    id_block = check_block_id(bottle.request.query.id_block)

    if id_block != 0 and not id_block:
        return bottle.template("error", msg="Bad block id")

    _dynStruct.l_block[id_block].struct.remove_block(_dynStruct.l_block[id_block])
    _dynStruct.save_modif()
    bottle.redirect("/block?id=%d" % (id_block))
Esempio n. 9
0
def remove_struct_from_block():
    id_block = check_block_id(bottle.request.query.id_block)

    if id_block != 0 and not id_block:
        return bottle.template("error", msg="Bad block id")

    _dynStruct.l_block[id_block].struct.remove_block(
        _dynStruct.l_block[id_block])
    _dynStruct.save_modif()
    bottle.redirect("/block?id=%d" % (id_block))
Esempio n. 10
0
def struct_do_edit():
    struct = _dynStruct.Struct.get_by_id(bottle.request.query.id)

    if not struct:
        return bottle.template("error", msg="Bad struct id")

    struct.name = bottle.request.forms.name
    _dynStruct.save_modif()
    
    bottle.redirect("/struct?id=%d" % (struct.id))
Esempio n. 11
0
def struct_do_edit():
    struct = _dynStruct.Struct.get_by_id(bottle.request.query.id)

    if not struct:
        return bottle.template("error", msg="Bad struct id")

    struct.name = bottle.request.forms.name
    _dynStruct.save_modif()

    bottle.redirect("/struct?id=%d" % (struct.id))
Esempio n. 12
0
def struct_remove():
    struct = _dynStruct.Struct.get_by_id(bottle.request.query.id)

    if not struct:
        return bottle.template("error", msg="Bad struct id")

    struct.remove_all_block()
    _dynStruct.l_struct.remove(struct)
    _dynStruct.save_modif()
    
    bottle.redirect("/struct_search")
Esempio n. 13
0
def struct_remove():
    struct = _dynStruct.Struct.get_by_id(bottle.request.query.id)

    if not struct:
        return bottle.template("error", msg="Bad struct id")

    struct.remove_all_block()
    _dynStruct.l_struct.remove(struct)
    _dynStruct.save_modif()

    bottle.redirect("/struct_search")
Esempio n. 14
0
def add_to_struct_struct_from_block():
    id_block = check_block_id(bottle.request.query.id_block)
    id_struct = check_struct_id(bottle.request.query.id_struct)

    if id_block != 0 and not id_block:
        return bottle.template("error", msg="Bad block id")

    if not id_struct:
        return bottle.template("error", msg="Bad struct id")

    block = _dynStruct.l_block[id_block]
    if block.struct:
        return bottle.template("error", msg="Block already linked")
    struct = _dynStruct.Struct.get_by_id(id_struct)
    struct.add_block(block)
    _dynStruct.save_modif()
    return bottle.template("block_view", block=block)
Esempio n. 15
0
def add_to_struct_struct_from_block():
    id_block = check_block_id(bottle.request.query.id_block)
    id_struct = check_struct_id(bottle.request.query.id_struct)

    if id_block != 0 and not id_block:
        return bottle.template("error", msg="Bad block id")

    if not id_struct:
        return bottle.template("error", msg="Bad struct id")

    block = _dynStruct.l_block[id_block]
    if block.struct:
        return bottle.template("error", msg="Block already linked")
    struct = _dynStruct.Struct.get_by_id(id_struct)
    struct.add_block(block)
    _dynStruct.save_modif()
    return bottle.template("block_view", block=block)
Esempio n. 16
0
def do_recovery():
    block_id = check_block_id(bottle.request.query.id_block)
    if not block_id and block_id != 0:
        return bottle.template("error", msg="Bad block id")
    block = _dynStruct.l_block[block_id]
    if not block.struct:
        new_struct = _dynStruct.Struct(block)
        new_struct.clean_struct()
        try:
            new_struct.id = _dynStruct.l_struct[-1].id + 1;
        except IndexError:
            new_struct.id = 1
        new_struct.set_default_name()
        _dynStruct.l_struct.append(new_struct)
        _dynStruct.save_modif()
    else:
        return bottle.template("error", msg="Block already linked")
    bottle.redirect("/block?id=%d" % (block_id))
Esempio n. 17
0
def do_recovery():
    block_id = check_block_id(bottle.request.query.id_block)
    if not block_id and block_id != 0:
        return bottle.template("error", msg="Bad block id")
    block = _dynStruct.l_block[block_id]
    if not block.struct:
        new_struct = _dynStruct.Struct(block)
        new_struct.clean_struct()
        try:
            new_struct.id = _dynStruct.l_struct[-1].id + 1
        except IndexError:
            new_struct.id = 1
        new_struct.set_default_name()
        _dynStruct.l_struct.append(new_struct)
        _dynStruct.save_modif()
    else:
        return bottle.template("error", msg="Block already linked")
    bottle.redirect("/block?id=%d" % (block_id))
Esempio n. 18
0
def struct_instance_do_edit():
    id_struct = check_struct_id(bottle.request.query.id)

    if not id_struct:
        return bottle.template("error", msg="Bad struct id")

    struct = _dynStruct.Struct.get_by_id(id_struct)
    if not struct:
        return bottle.template("error", msg="bad struct id")

    if bottle.request.forms.add != '':
        for add in bottle.request.forms.add.split(','):
            struct.add_block(_dynStruct.l_block[int(add)])

    if bottle.request.forms.remove != '':
        for remove in bottle.request.forms.remove.split(','):
            struct.remove_block(_dynStruct.l_block[int(remove)])

    _dynStruct.save_modif()
Esempio n. 19
0
def struct_instance_do_edit():
    id_struct = check_struct_id(bottle.request.query.id)

    if not id_struct:
        return bottle.template("error", msg="Bad struct id")

    struct = _dynStruct.Struct.get_by_id(id_struct)
    if not struct:
        return bottle.template("error", msg="bad struct id")

    if bottle.request.forms.add != '':
        for add in bottle.request.forms.add.split(','):
            struct.add_block(_dynStruct.l_block[int(add)])

    if bottle.request.forms.remove != '':
        for remove in bottle.request.forms.remove.split(','):
            struct.remove_block(_dynStruct.l_block[int(remove)])

    _dynStruct.save_modif()
Esempio n. 20
0
def struct_do_create():
    size = bottle.request.forms.size
    try:
        size = int(size)
    except ValueError:
        return bottle.template("error", msg="Size is not in integer")

    if size <= 0:
        return bottle.template("error", msg="Size have to be positive")

    new_struct = _dynStruct.Struct(None)
    new_struct.id = _dynStruct.l_struct[-1].id + 1
    new_struct.name = bottle.request.forms.name
    new_struct.size = size
    new_struct.add_pad()

    _dynStruct.l_struct.append(new_struct)
    _dynStruct.save_modif()

    bottle.redirect("/struct?id=%d" % (new_struct.id))
Esempio n. 21
0
def struct_do_create():
    size = bottle.request.forms.size
    try:
        size = int(size)
    except ValueError:
        return bottle.template("error", msg="Size is not in integer")

    if size <= 0:
        return bottle.template("error", msg="Size have to be positive")

    new_struct = _dynStruct.Struct(None)
    new_struct.id = _dynStruct.l_struct[-1].id + 1
    new_struct.name = bottle.request.forms.name
    new_struct.size = size
    new_struct.add_pad()

    _dynStruct.l_struct.append(new_struct)
    _dynStruct.save_modif()
    
    bottle.redirect("/struct?id=%d" % (new_struct.id))
Esempio n. 22
0
def member_do_create():
    id_struct = check_struct_id(bottle.request.query.id_struct)
    id_member = bottle.request.query.id_member

    if not id_member:
        return bottle.template("error", msg="member id missing")

    if not id_struct:
        return bottle.template("error", msg="Bad struct id")

    struct = _dynStruct.Struct.get_by_id(id_struct)
    if not struct:
        return bottle.template("error", msg="bad struct id")

    member = struct.get_member(int(id_member))

    if not member:
        return bottle.template("error", msg="Bad member id")

    if not member.is_padding:
        return bottle.template(
            "error",
            msg="To add a member, member_id have to point to a padding member")

    try:
        struct.add_member_from_web_ui(member, bottle.request.forms)
    except ValueError as err:
        struct.add_pad()
        return bottle.template("error", msg=str(err))

    struct.members.remove(member)
    struct.add_pad()
    _dynStruct.save_modif()
    if '.' in id_struct:
        bottle.redirect("/member?id_struct=%s&id_member=%s" %
                        (id_struct[:id_struct.rfind('.')],
                         id_struct[id_struct.rfind('.') + 1:]))
    else:
        bottle.redirect("/struct?id=%s" % (id_struct))