本文整理汇总了Python中users.Users.user_exists方法的典型用法代码示例。如果您正苦于以下问题:Python Users.user_exists方法的具体用法?Python Users.user_exists怎么用?Python Users.user_exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.Users
的用法示例。
在下文中一共展示了Users.user_exists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_users
# 需要导入模块: from users import Users [as 别名]
# 或者: from users.Users import user_exists [as 别名]
def setup_users(self):
"""
add/modify configured users
"""
system_users = Users(self.root_dir)
for users in self.xml_state.get_users():
for user in users.user_sections:
log.info('Setting up user %s', user.get_name())
password = user.get_password()
password_format = user.get_pwdformat()
home_path = user.get_home()
user_name = user.get_name()
user_id = user.get_id()
user_realname = user.get_realname()
user_shell = user.get_shell()
user_exists = system_users.user_exists(user_name)
options = []
if password_format == 'plain':
password = self.__create_passwd_hash(password)
if password:
options.append('-p')
options.append(password)
if user_shell:
options.append('-s')
options.append(user_shell)
if users.group_id or users.group_name:
options.append('-g')
if users.group_id:
options.append(users.group_id)
else:
options.append(users.group_name)
if user_id:
options.append('-u')
options.append(user_id)
if user_realname:
options.append('-c')
options.append(user_realname)
if not user_exists and home_path:
options.append('-m')
options.append('-d')
options.append(home_path)
if user_exists:
log.info(
'--> Modifying user: %s [%s]',
user_name, users.group_name
)
system_users.user_modify(user_name, options)
else:
log.info(
'--> Adding user: %s [%s]',
user_name, users.group_name
)
system_users.user_add(user_name, options)
if home_path:
log.info(
'--> Setting permissions for %s', home_path
)
system_users.setup_home_for_user(
user_name, users.group_name, home_path
)