générifier au maxium handle_*

This commit is contained in:
Jephté Clain 2017-06-18 08:53:34 +04:00
parent 41f4e724bd
commit f0de1213f6
1 changed files with 45 additions and 45 deletions

View File

@ -642,29 +642,29 @@ class Parser(object):
# traiter les hôtes # traiter les hôtes
for nvs in nvss: for nvs in nvss:
name, values = split_nlist(nvs) name, values = split_nlist(nvs)
for host in values: for value in values:
dir = None dir = None
if host: if value:
if '/' in host: if '/' in value:
dir, host = path.split(path.abspath(path.expanduser(host))) dir, value = path.split(path.abspath(path.expanduser(value)))
host = self.__fix_host(host) value = self.__fix_host(value)
if name: if name:
o = self.db.get_object(otype, name) o = self.db.get_object(otype, name)
if host: o.add_value(host) if value: o.add_value(value)
o.merge_attrs(defaulto) o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir) if dir is not None: o.set_attr('dir', dir)
self.add_group(otype, name) self.add_group(otype, name)
else: else:
id = HostObject.genid(host) id = HostObject.genid(value)
o = self.db.get_object(otype, id) o = self.db.get_object(otype, id)
o.add_value(host) o.add_value(value)
o.merge_attrs(defaulto) o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir) if dir is not None: o.set_attr('dir', dir)
self.add_group(otype, id) self.add_group(otype, id)
ib = HostObject.genib(id) ib = HostObject.genib(id)
o = self.db.get_object(otype, ib) o = self.db.get_object(otype, ib)
o.add_value(host) o.add_value(value)
o.merge_attrs(defaulto) o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir) if dir is not None: o.set_attr('dir', dir)
self.add_group(otype, ib) self.add_group(otype, ib)
@ -721,29 +721,29 @@ class Parser(object):
# traiter les modules # traiter les modules
for nvs in nvss: for nvs in nvss:
name, values = split_nlist(nvs) name, values = split_nlist(nvs)
for module in values: for value in values:
dir = None dir = None
modulep = None valuep = None
if module: if value:
if '/' in module: if '/' in value:
dir, module = path.split(path.abspath(path.expanduser(module))) dir, value = path.split(path.abspath(path.expanduser(value)))
module = self.__fix_module(module) value = self.__fix_module(value)
if dir is not None: if dir is not None:
modulep = path.join(dir, module) valuep = path.join(dir, value)
if name: if name:
o = self.db.get_object(otype, name) o = self.db.get_object(otype, name)
if module: o.add_value(module) if value: o.add_value(value)
o.merge_attrs(defaulto) o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir) if dir is not None: o.set_attr('dir', dir)
if modulep is not None: o.set_attr('path', modulep) if valuep is not None: o.set_attr('path', valuep)
self.add_group(otype, name) self.add_group(otype, name)
else: else:
id = ModuleObject.genid(module) id = ModuleObject.genid(value)
o = self.db.get_object(otype, id) o = self.db.get_object(otype, id)
if module: o.add_value(module) if value: o.add_value(value)
o.merge_attrs(defaulto) o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir) if dir is not None: o.set_attr('dir', dir)
if modulep is not None: o.set_attr('path', modulep) if valuep is not None: o.set_attr('path', valuep)
self.add_group(otype, id) self.add_group(otype, id)
def handle_xuinst(self, ltype, *args): def handle_xuinst(self, ltype, *args):
@ -837,29 +837,29 @@ class Parser(object):
# traiter les wobundles # traiter les wobundles
for nvs in nvss: for nvs in nvss:
name, values = split_nlist(nvs) name, values = split_nlist(nvs)
for wobundle in values: for value in values:
dir = None dir = None
wobundlep = None valuep = None
if wobundle: if value:
if '/' in wobundle: if '/' in value:
dir, wobundle = path.split(path.abspath(path.expanduser(wobundle))) dir, value = path.split(path.abspath(path.expanduser(value)))
wobundle = self.__fix_wobundle(wobundle) value = self.__fix_wobundle(value)
if dir is not None: if dir is not None:
wobundlep = path.join(dir, wobundle) valuep = path.join(dir, value)
if name: if name:
o = self.db.get_object(otype, name) o = self.db.get_object(otype, name)
if wobundle: o.add_value(wobundle) if value: o.add_value(value)
o.merge_attrs(defaulto) o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir) if dir is not None: o.set_attr('dir', dir)
if wobundlep is not None: o.set_attr('path', wobundlep) if valuep is not None: o.set_attr('path', valuep)
self.add_group(otype, name) self.add_group(otype, name)
else: else:
id = WobundleObject.genid(wobundle) id = WobundleObject.genid(value)
o = self.db.get_object(otype, id) o = self.db.get_object(otype, id)
if wobundle: o.add_value(wobundle) if value: o.add_value(value)
o.merge_attrs(defaulto) o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir) if dir is not None: o.set_attr('dir', dir)
if wobundlep is not None: o.set_attr('path', wobundlep) if valuep is not None: o.set_attr('path', valuep)
self.add_group(otype, id) self.add_group(otype, id)
def handle_rwoinst(self, cmd, *args): def handle_rwoinst(self, cmd, *args):
@ -914,29 +914,29 @@ class Parser(object):
# traiter les webapps # traiter les webapps
for nvs in nvss: for nvs in nvss:
name, values = split_nlist(nvs) name, values = split_nlist(nvs)
for webapp in values: for value in values:
dir = None dir = None
webappp = None valuep = None
if webapp: if value:
if '/' in webapp: if '/' in value:
dir, webapp = path.split(path.abspath(path.expanduser(webapp))) dir, value = path.split(path.abspath(path.expanduser(value)))
webapp = self.__fix_webapp(webapp) value = self.__fix_webapp(value)
if dir is not None: if dir is not None:
webappp = path.join(dir, webapp) valuep = path.join(dir, value)
if name: if name:
o = self.db.get_object(otype, name) o = self.db.get_object(otype, name)
if webapp: o.add_value(webapp) if value: o.add_value(value)
o.merge_attrs(defaulto) o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir) if dir is not None: o.set_attr('dir', dir)
if webappp is not None: o.set_attr('path', webappp) if valuep is not None: o.set_attr('path', valuep)
self.add_group(otype, name) self.add_group(otype, name)
else: else:
id = WebappObject.genid(webapp) id = WebappObject.genid(value)
o = self.db.get_object(otype, id) o = self.db.get_object(otype, id)
if webapp: o.add_value(webapp) if value: o.add_value(value)
o.merge_attrs(defaulto) o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir) if dir is not None: o.set_attr('dir', dir)
if webappp is not None: o.set_attr('path', webappp) if valuep is not None: o.set_attr('path', valuep)
self.add_group(otype, id) self.add_group(otype, id)
def handle_rtoinst(self, cmd, *args): def handle_rtoinst(self, cmd, *args):