def sync(users, existing_user_names=user_names()): user_names = [user['name'] for user in users] for user in users: if user['name'] not in existing_user_names: add(user) elif user['name'] in existing_user_names: update(user) for user_name in existing_user_names: if not user_name in user_names: remove({ 'name': user_name })
def sync(user_info, existing_users=helpers.user_names()): existing_users = (existing_users or _user_names()) user_names = [user['name'] for user in user_info] for user in user_info: if user['name'] not in existing_users: add(user) elif user['name'] in existing_users: update(user) for user_name in existing_users: if not user_name in user_names: remove({'name': user_name})
def dump(path, user_names=user_names()): users = [] for user_name in user_names: password = spwd.getspnam(user_name).sp_pwd groups = _groups_for_user(user_name) users.append({ 'name': user_name, 'groups': groups, 'password': password }) with open(path, 'w') as f: json.dump(users, f)