本文整理汇总了Python中augeas.Augeas.match方法的典型用法代码示例。如果您正苦于以下问题:Python Augeas.match方法的具体用法?Python Augeas.match怎么用?Python Augeas.match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类augeas.Augeas
的用法示例。
在下文中一共展示了Augeas.match方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
def get(path, value=''):
'''
Get a value for a specific augeas path
CLI Example:
.. code-block:: bash
salt '*' augeas.get /files/etc/hosts/1/ ipaddr
'''
aug = Augeas()
ret = {}
path = path.rstrip('/')
if value:
path += '/{0}'.format(value.strip('/'))
try:
_match = aug.match(path)
except RuntimeError as err:
return {'error': str(err)}
if _match:
ret[path] = aug.get(path)
else:
ret[path] = '' # node does not exist
return ret
示例2: get
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
def get(self,entryPath,param='',hierarchy='/files'):
"""Get a value for a config. parameter in a config. file,
with the help of Augeas, a configuration API (cf http://augeas.net)"""
try:
from augeas import Augeas
aug=Augeas()
except Exception, e: return str(e)
# yes, entryPath.rstrip('/')+'/' is really needed (i.e. entryPath=/)
path=(hierarchy+entryPath.rstrip('/')+'/'+param).rstrip('/')
try:
matchtest=aug.match(path)
except Exception, e: return str(e)
if matchtest:
try:
pvalue=aug.get(path)
#aug.close()
except Exception, e: return str(e)
else:
# The node doesn't exist
pvalue='(o)'
if not pvalue:
# The node doesn't have a value
pvalue='(none)'
return { 'path': entryPath, 'parameter': param, 'value': pvalue, 'hierarchy': hierarchy }
示例3: match
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
def match(path, value=''):
'''
Get matches for path expression
CLI Example::
salt '*' augeas.match /files/etc/services/service-name ssh
'''
from augeas import Augeas
aug = Augeas()
ret = {}
try:
matches = aug.match(path)
except RuntimeError:
return ret
for _match in matches:
if value and aug.get(_match) == value:
ret[_match] = value
elif not value:
ret[_match] = aug.get(_match)
return ret
示例4: get
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
def get(path, value=""):
"""
Get a value for a specific augeas path
CLI Example::
salt '*' augeas.get /files/etc/hosts/1/ ipaddr
"""
from augeas import Augeas
aug = Augeas()
ret = {}
path = path.rstrip("/")
if value:
path += "/{0}".format(value.strip("/"))
try:
_match = aug.match(path)
except RuntimeError as err:
return {"error": str(err)}
if _match:
ret[path] = aug.get(path)
else:
ret[path] = "" # node does not exist
return ret
示例5: get_configured_ifaces
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
def get_configured_ifaces():
aug = Augeas(flags=Augeas.NO_MODL_AUTOLOAD)
aug.add_transform('interfaces', '/etc/network/interfaces')
aug.load()
base = '/files/etc/network/interfaces'
for m in aug.match('%s/iface' % base):
yield aug.get(m)
aug.close()
示例6: set_api_timeouts
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
def set_api_timeouts(self, timeout):
# Determine the file to change
if self.https:
config_file = self.abiquo_ssl_conf
else:
config_file = self.abiquo_conf
logging.info("Setting Proxy timeouts in %s" % config_file)
# Set timeout using Augeas
a = Augeas()
for loc in a.match("/files%s/VirtualHost/*[arg='/api']" % config_file):
proxy_pass = a.match("%s/*[self::directive='ProxyPass']" % loc)
if len(proxy_pass) == 1:
# Proxy timeout already exists
logging.info("ProxyPass found")
arg1 = a.get("%s/arg" % proxy_pass[0])
arg2 = "timeout=%s" % timeout
a.set("%s/arg[1]" % proxy_pass[0], arg1)
a.set("%s/arg[2]" % proxy_pass[0], arg2)
a.save()
a.close()
示例7: match
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
def match(self,entryPath,param='',pvalue='',hierarchy='/files'):
"""Match a value for a config. parameter in a config. file,
with the help of Augeas, a configuration API (cf http://augeas.net)"""
try:
from augeas import Augeas
aug=Augeas()
except Exception, e: return str(e)
path=(hierarchy+entryPath.rstrip('/')+'/'+param).rstrip('/')
childpath=(hierarchy+entryPath.rstrip('/')+'/*/'+param).rstrip('/')
if pvalue:
try:
matchlist = [ ospath.dirname(lstripstr(item,'/files')) for item in aug.match(path) + aug.match(childpath) if ( aug.get(item) == pvalue ) ]
#aug.close()
except Exception, e: return str(e)
else:
try:
matchlist = [ ospath.dirname(lstripstr(item,'/files')) for item in aug.match(path) + aug.match(childpath) ]
#aug.close()
except Exception, e: return str(e)
return matchlist
示例8: execute
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [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()
示例9: get_augeas
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
def get_augeas(self, entry):
""" Get an augeas object for the given entry. """
if entry.get("name") not in self._augeas:
aug = Augeas()
if entry.get("lens"):
self.logger.debug("Augeas: Adding %s to include path for %s" %
(entry.get("name"), entry.get("lens")))
incl = "/augeas/load/%s/incl" % entry.get("lens")
ilen = len(aug.match(incl))
if ilen == 0:
self.logger.error("Augeas: Lens %s does not exist" %
entry.get("lens"))
else:
aug.set("%s[%s]" % (incl, ilen + 1), entry.get("name"))
aug.load()
self._augeas[entry.get("name")] = aug
return self._augeas[entry.get("name")]
示例10: ls
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
def ls(self,entryPath,hierarchy='/files'):
"""List the direct children of an entry in a config. file,
with the help of Augeas, a configuration API (cf http://augeas.net)"""
try:
from augeas import Augeas
aug=Augeas()
except Exception, e: return str(e)
path=hierarchy+entryPath.rstrip('/')+'/*'
# We can't use a dict here because the same key can appear many times.
nodes=[]
try:
for match in aug.match(path):
pvalue=aug.get(match)
if not pvalue:
pvalue='(none)'
nodes.append([ospath.basename(match),pvalue])
except Exception, e: return str(e)
#try:
# aug.close()
#except Exception, e: return str(e)
return { 'path': entryPath, 'nodes': nodes, 'hierarchy': hierarchy }
示例11: LVMConfig
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
class LVMConfig(object):
def __init__(self, path="/etc/lvm/lvm.conf"):
self.path = path
# Augeas loads by default tons of unneeded lenses and configuration
# files. On my test host, it fails to load, trying to read my 500 MiB
# /etc/lvm/archive/.
#
# These are the standard LVM lens includes:
# /augeas/load/LVM/incl[1] /etc/lvm/lvm.conf
# /augeas/load/LVM/incl[2] /etc/lvm/backup/*
# /augeas/load/LVM/incl[3] /etc/lvm/archive/*.vg
#
# We need only the first entry to work with lvm.conf. Using customized
# load setup, as explained in
# https://github.com/hercules-team/augeas/wiki/Loading-specific-files
#
# Removing the archive and backup entries, we can load augeas in 0.7
# seconds on my test vm. Removing all other lenses shorten the time to
# 0.04 seconds.
log.debug("Loading LVM configuration from %r", path)
self.aug = Augeas(flags=Augeas.NO_MODL_AUTOLOAD | Augeas.SAVE_BACKUP)
self.aug.add_transform("lvm.lns", [path])
self.aug.load()
# Context manager interface
def __enter__(self):
return self
def __exit__(self, t, v, tb):
try:
self.close()
except Exception as e:
# Caller succeeded, raise the close error.
if t is None:
raise
# Caller has failed, do not hide the original error.
log.exception("Error closing %s: %s" % (self, e))
# Accessing list of strings
def getlist(self, section, option):
pat = "/files%s/%s/dict/%s/list/*/str" % (self.path, section, option)
matches = self.aug.match(pat)
if not matches:
return None # Cannot store/read empty list
return [self.aug.get(m) for m in matches]
def setlist(self, section, option, value):
log.debug("Setting %s/%s to %s", section, option, value)
opt_path = "/files%s/%s/dict/%s" % (self.path, section, option)
self.aug.remove(opt_path)
item_path = opt_path + "/list/%d/str"
for i, item in enumerate(value, 1):
self.aug.set(item_path % i, item)
# Accessing flat values (int, string)
def getint(self, section, option):
val = self._get_flat(section, option, "int")
return int(val) if val is not None else None
def setint(self, section, option, value):
self._set_flat(section, option, "int", str(value))
def getstr(self, section, option):
return self._get_flat(section, option, "str")
def setstr(self, section, option, value):
self._set_flat(section, option, "str", value)
def _get_flat(self, section, option, opt_type):
path = self._flat_path(section, option, opt_type)
return self.aug.get(path)
def _set_flat(self, section, option, opt_type, value):
log.debug("Setting %s/%s to %r", section, option, value)
path = self._flat_path(section, option, opt_type)
return self.aug.set(path, value)
def _flat_path(self, section, option, opt_type):
return "/files%s/%s/dict/%s/%s" % (
self.path, section, option, opt_type)
# Removing options
def remove(self, section, option):
log.debug("Removing %s/%s", section, option)
path = "/files%s/%s/dict/%s" % (self.path, section, option)
self.aug.remove(path)
# File operations
def save(self):
log.info("Saving new LVM configuration to %r, previous configuration "
"saved to %r",
self.path, self.path + ".augsave")
#.........这里部分代码省略.........
示例12: execute
# 需要导入模块: from augeas import Augeas [as 别名]
# 或者: from augeas.Augeas import match [as 别名]
#.........这里部分代码省略.........
"base_dn": conf.get('ldap', 'base_dn'),
"server_host": server_host,
"service_bind_dn": conf.get('ldap', 'service_bind_dn'),
"service_bind_pw": conf.get('ldap', 'service_bind_pw'),
},
}
if not os.path.isdir('/etc/postfix/ldap'):
os.mkdir('/etc/postfix/ldap/', 0770)
for filename in files.keys():
fp = open(filename, 'w')
fp.write(files[filename])
fp.close()
fp = open('/etc/postfix/transport', 'a')
fp.write("\n# Shared Folder Delivery for %(domain)s:\[email protected]%(domain)s\t\tlmtp:unix:/var/lib/imap/socket/lmtp\n" % {'domain': conf.get('kolab', 'primary_domain')})
fp.close()
subprocess.call(["postmap", "/etc/postfix/transport"])
postfix_main_settings = {
"inet_interfaces": "all",
"recipient_delimiter": "+",
"local_recipient_maps": "ldap:/etc/postfix/ldap/local_recipient_maps.cf",
"mydestination": "ldap:/etc/postfix/ldap/mydestination.cf",
"transport_maps": "ldap:/etc/postfix/ldap/transport_maps.cf, hash:/etc/postfix/transport",
"virtual_alias_maps": "$alias_maps, ldap:/etc/postfix/ldap/virtual_alias_maps.cf, ldap:/etc/postfix/ldap/virtual_alias_maps_mailforwarding.cf, ldap:/etc/postfix/ldap/virtual_alias_maps_sharedfolders.cf, ldap:/etc/postfix/ldap/mailenabled_distgroups.cf, ldap:/etc/postfix/ldap/mailenabled_dynamic_distgroups.cf",
"smtpd_tls_auth_only": "yes",
"smtpd_tls_security_level": "may",
"smtp_tls_security_level": "may",
"smtpd_sasl_auth_enable": "yes",
"smtpd_sender_login_maps": "$local_recipient_maps",
"smtpd_sender_restrictions": "permit_mynetworks, reject_sender_login_mismatch",
"smtpd_recipient_restrictions": "permit_mynetworks, reject_unauth_pipelining, reject_rbl_client zen.spamhaus.org, reject_non_fqdn_recipient, reject_invalid_helo_hostname, reject_unknown_recipient_domain, reject_unauth_destination, check_policy_service unix:private/recipient_policy_incoming, permit",
"smtpd_sender_restrictions": "permit_mynetworks, check_policy_service unix:private/sender_policy_incoming",
"submission_recipient_restrictions": "check_policy_service unix:private/submission_policy, permit_sasl_authenticated, reject",
"submission_sender_restrictions": "reject_non_fqdn_sender, check_policy_service unix:private/submission_policy, permit_sasl_authenticated, reject",
"submission_data_restrictions": "check_policy_service unix:private/submission_policy",
"content_filter": "smtp-amavis:[127.0.0.1]:10024"
}
if os.path.isfile('/etc/pki/tls/certs/make-dummy-cert') and not os.path.isfile('/etc/pki/tls/private/localhost.pem'):
subprocess.call(['/etc/pki/tls/certs/make-dummy-cert', '/etc/pki/tls/private/localhost.pem'])
if os.path.isfile('/etc/pki/tls/private/localhost.pem'):
postfix_main_settings['smtpd_tls_cert_file'] = "/etc/pki/tls/private/localhost.pem"
postfix_main_settings['smtpd_tls_key_file'] = "/etc/pki/tls/private/localhost.pem"
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)))