Пример #1
0
def has_parent(parent, parent_id, children):
    """List the children of a given parent with its id"""
    args = get_args(request.args)
    if request.method == 'GET':
        #Something like /api/domains/<id>/virtualmachines will be equivalent to listVirtualMachines?domainid=<id>
        verb = "list"
        subject = children
        #If parent is 'domains' it is added into args as domainid, i.e singular[domains] + 'id'
        args[singular[parent] + 'id'] = parent_id
    return apicall(verb, subject, args)
Пример #2
0
def collection(subject):
    """Operations on a collection of entities, list them or add an entity to collection"""
    if request.method == 'GET':
        args = get_args(request.args)
        verb = "list"
    if request.method == 'POST':
        args = get_args(request.json)
        verb = "create"
        subject = singular[subject];
    return apicall(verb, subject, args)
Пример #3
0
def has_id(subject, id):
    """Operation on an entity with given id, list its properties, update its properties, delete it"""
    if request.method == 'GET':
        args = get_args(request.args)
        verb = "list"
        args["id"] = id
    if request.method == 'PUT':
        args = get_args(request.json)
        verb = "update"
        subject = singular[subject];
        args["id"] = id
    if request.method == 'DELETE':
        verb = "delete"
        subject = singular[subject];
    return apicall(verb, subject, args);
Пример #4
0
def prepare_image():
    img = Image.open("chuck.jpg", 'r')
    width_img, height_img = img.size
    imgdraw = ImageDraw.Draw(img)
    text = api.apicall()
    lines = textwrap.wrap(text, width=40)
    y_text = 100
    y_text = (height_img - y_text) / 2
    font = ImageFont.truetype("JosefinSans-SemiBold.ttf", size=30)

    for line in lines:
        width, height = font.getsize(line)
        imgdraw.text(((width_img - width) / 2, y_text),
                     line,
                     font=font,
                     fill="white",
                     shadow=(1.0, 1.0),
                     width=60,
                     align="center")
        y_text += height
    img.save("image.png")
Пример #5
0
def rawapi(command):
    if request.method == 'GET':
        return apicall(command, get_args(request.args))
Пример #6
0
def rawapi(command):
    if request.method == 'GET':
        return apicall(command, get_args(request.args))