本文整理汇总了Python中augeas.Augeas.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Augeas.insert方法的具体用法?Python Augeas.insert怎么用?Python Augeas.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类augeas.Augeas
的用法示例。
在下文中一共展示了Augeas.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import insert [as 别名]
def execute(*args, **kw):
if conf.timezone == None:
print >> sys.stderr, utils.multiline_message(
_("""
Please supply the timezone PHP should be using.
You have to use a Continent or Country / City locality name
like 'Europe/Berlin', but not just 'CEST'.
""")
)
conf.timezone = utils.ask_question(
_("Timezone ID"),
default="UTC"
)
if not conf.php_ini_path == None:
if not os.path.isfile(conf.php_ini_path):
log.error(_("Cannot configure PHP through %r (No such file or directory)") % (conf.php_ini_path))
return
php_ini = conf.php_ini_path
else:
# Search and destroy
php_ini = "/etc/php.ini"
if not os.path.isfile(php_ini):
php_ini = "/etc/php5/apache2/php.ini"
if not os.path.isfile(php_ini):
log.error(_("Could not find PHP configuration file php.ini"))
return
myaugeas = Augeas()
setting_base = '/files%s/' % (php_ini)
setting = os.path.join(setting_base, 'Date', 'date.timezone')
current_value = myaugeas.get(setting)
if current_value == None:
insert_paths = myaugeas.match('/files%s/Date/*' % (php_ini))
insert_path = insert_paths[(len(insert_paths)-1)]
myaugeas.insert(insert_path, 'date.timezone', False)
log.debug(_("Setting key %r to %r") % ('Date/date.timezone', conf.timezone), level=8)
myaugeas.set(setting, conf.timezone)
myaugeas.save()
示例2: execute
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import insert [as 别名]
#.........这里部分代码省略.........
if not os.path.isfile('/etc/postfix/main.cf'):
if os.path.isfile('/usr/share/postfix/main.cf.debian'):
shutil.copy(
'/usr/share/postfix/main.cf.debian',
'/etc/postfix/main.cf'
)
# Copy header checks files
for hc_file in [ 'inbound', 'internal', 'submission' ]:
if not os.path.isfile("/etc/postfix/header_checks.%s" % (hc_file)):
if os.path.isfile('/etc/kolab/templates/header_checks.%s' % (hc_file)):
input_file = '/etc/kolab/templates/header_checks.%s' % (hc_file)
elif os.path.isfile('/usr/share/kolab/templates/header_checks.%s' % (hc_file)):
input_file = '/usr/share/kolab/templates/header_checks.%s' % (hc_file)
elif os.path.isfile(os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'header_checks.%s' % (hc_file)))):
input_file = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'header_checks.%s' % (hc_file)))
shutil.copy(input_file, "/etc/postfix/header_checks.%s" % (hc_file))
subprocess.call(["postmap", "/etc/postfix/header_checks.%s" % (hc_file)])
myaugeas = Augeas()
setting_base = '/files/etc/postfix/main.cf/'
for setting_key in postfix_main_settings.keys():
setting = os.path.join(setting_base,setting_key)
current_value = myaugeas.get(setting)
if current_value == None:
try:
myaugeas.set(setting, postfix_main_settings[setting_key])
except:
insert_paths = myaugeas.match('/files/etc/postfix/main.cf/*')
insert_path = insert_paths[(len(insert_paths)-1)]
myaugeas.insert(insert_path, setting_key, False)
log.debug(_("Setting key %r to %r") % (setting_key, postfix_main_settings[setting_key]), level=8)
myaugeas.set(setting, postfix_main_settings[setting_key])
myaugeas.save()
postfix_master_settings = {
}
if os.path.exists('/usr/lib/postfix/kolab_smtp_access_policy'):
postfix_master_settings['kolab_sap_executable_path'] = '/usr/lib/postfix/kolab_smtp_access_policy'
else:
postfix_master_settings['kolab_sap_executable_path'] = '/usr/libexec/postfix/kolab_smtp_access_policy'
template_file = None
if os.path.isfile('/etc/kolab/templates/master.cf.tpl'):
template_file = '/etc/kolab/templates/master.cf.tpl'
elif os.path.isfile('/usr/share/kolab/templates/master.cf.tpl'):
template_file = '/usr/share/kolab/templates/master.cf.tpl'
elif os.path.isfile(os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'master.cf.tpl'))):
template_file = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'share', 'templates', 'master.cf.tpl'))
if not template_file == None:
fp = open(template_file, 'r')
template_definition = fp.read()
fp.close()
t = Template(template_definition, searchList=[postfix_master_settings])
fp = open('/etc/postfix/master.cf', 'w')