コード例 #1
0
ファイル: utils.py プロジェクト: rranshous/imagecomment
def set_image_comment(path,*args,**kwargs):
    """
    takes any kwarg, to use as a labeled part of the comment.
    can also take single arg to use as body of comment
    """
    if args and not kwargs:
        kwargs['body'] = '\n'.join(args)

    image = Image(path)
    image.readMetadata()
    # append is a possible kwarg
    append = True
    existing = image.getComment() or "" if append else ""
    comment_parts = [COMMENT_DELIMINATOR] if existing else []
    for k,v in kwargs.iteritems():
        if v is None:
            continue
        if k == 'append':
            append = v
        else:
            template = TEMPLATES.get(k,"%s:%s" % (k,v))
            comment_parts.append(template % v)
    image.setComment(existing + "\n".join(comment_parts))
    image.writeMetadata()