本文整理匯總了Python中users.Users.user_add方法的典型用法代碼示例。如果您正苦於以下問題:Python Users.user_add方法的具體用法?Python Users.user_add怎麽用?Python Users.user_add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類users.Users
的用法示例。
在下文中一共展示了Users.user_add方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup_users
# 需要導入模塊: from users import Users [as 別名]
# 或者: from users.Users import user_add [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
)