示例#1
0
def save_communities(clist=None):
    if clist == None:
        clist = communities.values()
    for community in clist:
        fname = get_community_fname(community)
        if fname == None:
            warning('Can not save community %s (%s)\n' %(community.get('name'), community.get('cid')))
            continue
        community.save_to_python_file(fname)

        # XXX: remove this logic with get_community_icon_name legacy removal
        newname = get_community_icon_name(community, legacyname=False)
        if not os.path.exists(newname):
            xrename(get_community_icon_name(community, legacyname=True), newname)
示例#2
0
def save_user(saveuser=None):
    if proximatedir == None:
        warning('Can not write users: no .proximate directory\n')
        return

    if saveuser == None:
        userlist = get_users()
    else:
        userlist = [saveuser]

    for user in userlist:
        userdir = get_user_dir(user)
        if not xmkdir(userdir):
            warning('Can not create directory for %s\n' %(user.get('uid')))
            continue
        fname = '%s/profile' %(userdir)
        user.save_to_python_file(fname)

        # XXX: remove this logic with get_face_name legacy name removal
        newname = get_face_name(user, legacyname=False)
        if not os.path.exists(newname):
            xrename(get_face_name(user, legacyname=True), newname)
示例#3
0
        return False
    basename = os.path.basename(fname)
    tmpname = fname + '.tmp'
    try:
        f = open(tmpname, 'w')
    except IOError, (errno, strerror):
        warning('Can not save face to %s: %s\n' %(tmpname, strerror))
        return False
    f.write(image)
    f.close()

    if not check_image(tmpname):
        xremove(tmpname)
        return False

    if not xrename(tmpname, fname):
        xremove(tmpname)
        warning('Can not rename: %s -> %s\n' %(tmpname, fname))
        return False

    return True

def save_community_icon(com, icon):
    # personal communities can have arbitary large icons because the picture
    # is not sent over network
    if com.get('peer') and len(icon) > TP_MAX_FACE_SIZE:
        warning('Community %s has too large icon picture: %d\n' %(com.get('name'), len(icon)))
        return False
    return save_image(get_community_icon_name(com, legacyname=False), icon)

def save_face(user, face):