本文整理汇总了Python中template.Template.replace方法的典型用法代码示例。如果您正苦于以下问题:Python Template.replace方法的具体用法?Python Template.replace怎么用?Python Template.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类template.Template
的用法示例。
在下文中一共展示了Template.replace方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import replace [as 别名]
def create_user(ldap_server, user):
old_user = find_user(ldap_server, config, user['USER_NAME'])
if old_user is None:
user['USER_ID'] = str(get_free_user_id(ldap_server))
user['USER_UID'] = str(uuid.uuid4())
else:
user['USER_ID'] = old_user['uidNumber'][0]
user['USER_UID'] = old_user['apple-generateduid'][0]
group = find_group(l, config, user['USER_GROUP_NAME'])
user['USER_GROUP_ID'] = group['gidNumber'][0]
user['USER_PASSWORD_HASH'] = "{KERBEROS} " + user['USER_NAME']
t = Template("../../config/plab-ldap/templates/user.ldif")
t.replace(config)
t.replace(user)
insert_ldif(ldap_server, str(t))
add_to_group(ldap_server, config, user['USER_NAME'], user['USER_GROUP_NAME'])
# Get user and show details
group = find_group(ldap_server, config, user['USER_GROUP_NAME'])
user = find_user(ldap_server, config, user['USER_NAME'])
pp = pprint.PrettyPrinter(indent = 4)
print "Added user (" + user['uid'][0] + ") with id (" + str(user['uidNumber']) + ")"
示例2: Samba
# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import replace [as 别名]
#
# This script sets up Kerberos on the client and joins
# the active directory domain to obtain a keytab file.
#
import sys
sys.path.append("..")
from config import config
from template import Template
import os
# Install Samba (for the net command) and Kerberos
os.system("apt-get install samba krb5-config krb5-user")
# Setup configuration
print "Installing Kerberos client configuration"
template = Template("../../config/shared/krb5.conf")
template.replace(config)
template.write("/etc/krb5.conf")
template = Template("../../config/shared/ad.conf")
template.replace(config)
template.write("/etc/ad.conf")
print "Joining system to Active Directory domain"
os.system("net ads join -s /etc/ad.conf -U " + config['AD_USERNAME'])
示例3: str
# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import replace [as 别名]
if old_user is None:
user['USER_ID'] = '1000'
user['USER_UID'] = str(uuid.uuid4())
else:
user['USER_ID'] = old_user['uidNumber'][0]
user['USER_UID'] = old_user['apple-generateduid'][0]
group = find_group(l, config, user['USER_GROUP_NAME'])
user['USER_GROUP_ID'] = group['gidNumber'][0]
user['USER_PASSWORD_HASH'] = "{KERBEROS} " + user['USER_NAME']
#hash_password(user['USER_PASSWORD'])
t = Template("user.ldif")
t.replace(config)
t.replace(user)
insert_ldif(l, str(t))
add_to_group(l, config, user['USER_NAME'], user['USER_GROUP_NAME'])
# Get user and show details
group = find_group(l, config, user['USER_GROUP_NAME'])
user = find_user(l, config, user['USER_NAME'])
pp = pprint.PrettyPrinter(indent = 4)
print "User added:"
pp.pprint(user)
pp.pprint(group)
示例4: init_ldap
# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import replace [as 别名]
from config import config
from template import Template
from ldap_utils import init_ldap, insert_ldif, add_to_group, find_user, find_group
import uuid
l = init_ldap(config)
group = {}
group['GROUP_NAME'] = 'admin'
group['GROUP_ID'] = '1100'
group['GROUP_LONGNAME'] = 'Administrators'
group['GROUP_UID'] = str(uuid.uuid4())
t = Template("../../config/plab-ldap/templates/group.ldif")
t.replace(config)
t.replace(group)
insert_ldif(l, str(t))
group = {}
group['GROUP_NAME'] = 'user'
group['GROUP_ID'] = '1101'
group['GROUP_LONGNAME'] = 'Users'
group['GROUP_UID'] = str(uuid.uuid4())
t = Template("../../config/plab-ldap/templates/group.ldif")
t.replace(config)
t.replace(group)
insert_ldif(l, str(t))
示例5: init_ldap
# 需要导入模块: from template import Template [as 别名]
# 或者: from template.Template import replace [as 别名]
#
# This script creates the users and groups OUs in your LDAP database.
#
import sys
sys.path.append("..")
from config import config
from template import Template
from ldap_utils import init_ldap, insert_ldif
import ldap
import base64
l = init_ldap(config)
# Build odconfig for Mac
t = Template("../../config/plab-ldap/templates/odconfig")
t.replace({'HOMEDIRECTORY': '#/Users/$uid$'})
t.replace(config)
odconfig = base64.b64encode(str(t).replace('\n', ''))
for item in ["ou=groups.ldif", "ou=users.ldif", "ou=macosx.ldif"]:
t = Template("../../config/plab-ldap/templates/" + item)
t.replace(config)
t.replace({"ODCONFIG": odconfig})
insert_ldif(l, str(t))
l.unbind_s()