renommer le script
This commit is contained in:
parent
f3c028005a
commit
5a3504e141
|
@ -174,15 +174,26 @@ class HostObject(object):
|
|||
def get_attr(self, name): return self.attrs.get(name, None)
|
||||
def set_attr(self, name, value):
|
||||
if name not in self.attrs: self.attrs[name] = []
|
||||
self.attrs[name].append(value)
|
||||
if value not in self.attrs[name]: self.attrs[name].append(value)
|
||||
def reset_attr(self, name, value=None):
|
||||
if name in self.attrs: del self.attrs[name]
|
||||
if value is not None: self.set_attr(name, value)
|
||||
def copy_attrs(self, other, reset=True):
|
||||
def add_attr(self, name, value):
|
||||
if name not in self.attrs: self.attrs[name] = []
|
||||
self.attrs[name].append(value)
|
||||
def del_attr(self, name, value):
|
||||
if name not in self.attrs: return
|
||||
self.attrs[name].remove(value)
|
||||
if not self.attrs[name]: del self.attrs[name]
|
||||
def modify_attr(self, name, value, method='set'):
|
||||
if method == 'set': self.set_attr(name, value)
|
||||
elif method == 'reset': self.reset_attr(name, value)
|
||||
elif method == 'add': self.add_attr(name, value)
|
||||
elif method == 'del': self.del_attr(name, value)
|
||||
def copy_attrs(self, other, method='set'):
|
||||
for name, values in other.attrs.items():
|
||||
for value in values:
|
||||
if reset: self.reset_attr(name, value)
|
||||
else: self.set_attr(name, value)
|
||||
self.modify_attr(name, value, method)
|
||||
|
||||
def split_scalar(arg):
|
||||
if '=' in arg:
|
||||
|
@ -192,10 +203,16 @@ def split_scalar(arg):
|
|||
value = None
|
||||
if name.endswith('%'):
|
||||
name = name[:-1]
|
||||
reset = True
|
||||
method = 'reset'
|
||||
elif name.endswith('+'):
|
||||
name = name[:-1]
|
||||
method = 'add'
|
||||
elif name.endswith('-'):
|
||||
name = name[:-1]
|
||||
method = 'del'
|
||||
else:
|
||||
reset = False
|
||||
return name, reset, value
|
||||
method = 'set'
|
||||
return name, method, value
|
||||
|
||||
def split_list(arg):
|
||||
if '=' in arg:
|
||||
|
@ -259,25 +276,28 @@ class Parser(object):
|
|||
- until: définir un groupe qui va jusqu'à la prochaine ligne 'group'
|
||||
"""
|
||||
otype = args[0:1] and args[0] or 'host'
|
||||
if otype not in self.groups:
|
||||
raise ValueError('%s: invalid object type' % otype)
|
||||
gtype = args[1:2] and args[1] or 'until'
|
||||
self.groups[otype]['type'] = gtype
|
||||
if gtype == 'defaults':
|
||||
self.groups[otype]['current'] = {None: True}
|
||||
elif gtype in ('once', 'until'):
|
||||
self.groups[otype]['current'] = {}
|
||||
else:
|
||||
raise ValueError('%s: invalid group type' % gtype)
|
||||
|
||||
############################################################################
|
||||
def handle_attr(self, args):
|
||||
otype = self.attr_otype
|
||||
assert otype is not None, "attr_otype should not be None"
|
||||
for nv in args:
|
||||
name, reset, value = split_scalar(nv)
|
||||
name, method, value = split_scalar(nv)
|
||||
if value is None:
|
||||
reset = True
|
||||
method = 'set'
|
||||
value = '1'
|
||||
for id in self.groups[otype]['current']:
|
||||
if reset: self.objects[otype][id].reset_attr(name)
|
||||
self.objects[otype][id].set_attr(name, value)
|
||||
self.objects[otype][id].modify_attr(name, value, method)
|
||||
|
||||
############################################################################
|
||||
def handle_default_profile(self, args):
|
||||
|
@ -355,14 +375,14 @@ class Parser(object):
|
|||
for nvs in nvss:
|
||||
name, values = split_list(nvs)
|
||||
for host in values:
|
||||
dir = None
|
||||
if host:
|
||||
if '/' in host:
|
||||
dir, host = path.split(path.abspath(path.expanduser(host)))
|
||||
else:
|
||||
dir = None
|
||||
host = self.__fix_host(host)
|
||||
if name:
|
||||
ho = self.__host_object(name)
|
||||
ho.add_host(host)
|
||||
if host: ho.add_host(host)
|
||||
ho.copy_attrs(default_ho)
|
||||
if dir is not None: ho.reset_attr('dir', dir)
|
||||
self.add_group('host', name)
|
Loading…
Reference in New Issue