commencer à générifier un peu le code

This commit is contained in:
Jephté Clain 2017-06-16 07:36:13 +04:00
parent 8e48af9373
commit 41f4e724bd
1 changed files with 35 additions and 35 deletions

View File

@ -527,7 +527,7 @@ class Parser(object):
elif cmd == 'default_domain': self.handle_default_domain(args)
elif cmd == 'group': self.handle_group(args)
elif cmd == 'attr': self.handle_attr(args)
elif cmd == 'host': self.handle_host(args)
elif cmd == 'host': self.handle_host(*p)
elif cmd in self.commands: self.commands[cmd](*p)
return self
@ -604,7 +604,7 @@ class Parser(object):
host = '%s.%s' % (host, self.db.default_domain)
return host
def handle_host(self, args):
def handle_host(self, otype, *args):
"""host [id=]host,...
host -b [id=]basedir
host -d [id=]dirspec
@ -636,9 +636,9 @@ class Parser(object):
if path.isdir(dir)])
nvss.extend(o.nvss)
# préparer la mise à jour du groupe courant
self.reset_group_maybe('host')
self.attr_otype = 'host'
defaulto = self.db.get_object('host', None)
self.reset_group_maybe(otype)
self.attr_otype = otype
defaulto = self.db.get_object(otype, None)
# traiter les hôtes
for nvs in nvss:
name, values = split_nlist(nvs)
@ -649,25 +649,25 @@ class Parser(object):
dir, host = path.split(path.abspath(path.expanduser(host)))
host = self.__fix_host(host)
if name:
o = self.db.get_object('host', name)
o = self.db.get_object(otype, name)
if host: o.add_value(host)
o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir)
self.add_group('host', name)
self.add_group(otype, name)
else:
id = HostObject.genid(host)
o = self.db.get_object('host', id)
o = self.db.get_object(otype, id)
o.add_value(host)
o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir)
self.add_group('host', id)
self.add_group(otype, id)
ib = HostObject.genib(id)
o = self.db.get_object('host', ib)
o = self.db.get_object(otype, ib)
o.add_value(host)
o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir)
self.add_group('host', ib)
self.add_group(otype, ib)
############################################################################
def __setup_uinst(self):
@ -683,7 +683,7 @@ class Parser(object):
def __fix_module(self, module):
return module
def handle_module(self, cmd, *args):
def handle_module(self, otype, *args):
"""module [id=]path/to/module
module -b [id=]basedir
module -d [id=]dirspec
@ -715,9 +715,9 @@ class Parser(object):
if path.isdir(dir)])
nvss.extend(o.nvss)
# préparer la mise à jour du groupe courant
self.reset_group_maybe('module')
self.attr_otype = 'module'
defaulto = self.db.get_object('module', None)
self.reset_group_maybe(otype)
self.attr_otype = otype
defaulto = self.db.get_object(otype, None)
# traiter les modules
for nvs in nvss:
name, values = split_nlist(nvs)
@ -731,20 +731,20 @@ class Parser(object):
if dir is not None:
modulep = path.join(dir, module)
if name:
o = self.db.get_object('module', name)
o = self.db.get_object(otype, name)
if module: o.add_value(module)
o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir)
if modulep is not None: o.set_attr('path', modulep)
self.add_group('module', name)
self.add_group(otype, name)
else:
id = ModuleObject.genid(module)
o = self.db.get_object('module', id)
o = self.db.get_object(otype, id)
if module: o.add_value(module)
o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir)
if modulep is not None: o.set_attr('path', modulep)
self.add_group('module', id)
self.add_group(otype, id)
def handle_xuinst(self, ltype, *args):
"""uinst -p profile attrs*
@ -799,7 +799,7 @@ class Parser(object):
wobundle = wobundle + '.woa'
return wobundle
def handle_wobundle(self, cmd, *args):
def handle_wobundle(self, otype, *args):
"""wobundle [id=]path/to/wobundle
wobundle -b [id=]basedir
wobundle -d [id=]dirspec
@ -831,9 +831,9 @@ class Parser(object):
if path.isdir(dir) and path.splitext(dir)[1] in ('.woa', '.framework')])
nvss.extend(o.nvss)
# préparer la mise à jour du groupe courant
self.reset_group_maybe('wobundle')
self.attr_otype = 'wobundle'
defaulto = self.db.get_object('wobundle', None)
self.reset_group_maybe(otype)
self.attr_otype = otype
defaulto = self.db.get_object(otype, None)
# traiter les wobundles
for nvs in nvss:
name, values = split_nlist(nvs)
@ -847,20 +847,20 @@ class Parser(object):
if dir is not None:
wobundlep = path.join(dir, wobundle)
if name:
o = self.db.get_object('wobundle', name)
o = self.db.get_object(otype, name)
if wobundle: o.add_value(wobundle)
o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir)
if wobundlep is not None: o.set_attr('path', wobundlep)
self.add_group('wobundle', name)
self.add_group(otype, name)
else:
id = WobundleObject.genid(wobundle)
o = self.db.get_object('wobundle', id)
o = self.db.get_object(otype, id)
if wobundle: o.add_value(wobundle)
o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir)
if wobundlep is not None: o.set_attr('path', wobundlep)
self.add_group('wobundle', id)
self.add_group(otype, id)
def handle_rwoinst(self, cmd, *args):
pass
@ -876,7 +876,7 @@ class Parser(object):
def __fix_webapp(self, webapp):
return webapp
def handle_webapp(self, cmd, *args):
def handle_webapp(self, otype, *args):
"""webapp [id=]path/to/webapp
webapp -b [id=]basedir
webapp -d [id=]dirspec
@ -908,9 +908,9 @@ class Parser(object):
if path.isdir(dir)])
nvss.extend(o.nvss)
# préparer la mise à jour du groupe courant
self.reset_group_maybe('webapp')
self.attr_otype = 'webapp'
defaulto = self.db.get_object('webapp', None)
self.reset_group_maybe(otype)
self.attr_otype = otype
defaulto = self.db.get_object(otype, None)
# traiter les webapps
for nvs in nvss:
name, values = split_nlist(nvs)
@ -924,20 +924,20 @@ class Parser(object):
if dir is not None:
webappp = path.join(dir, webapp)
if name:
o = self.db.get_object('webapp', name)
o = self.db.get_object(otype, name)
if webapp: o.add_value(webapp)
o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir)
if webappp is not None: o.set_attr('path', webappp)
self.add_group('webapp', name)
self.add_group(otype, name)
else:
id = WebappObject.genid(webapp)
o = self.db.get_object('webapp', id)
o = self.db.get_object(otype, id)
if webapp: o.add_value(webapp)
o.merge_attrs(defaulto)
if dir is not None: o.set_attr('dir', dir)
if webappp is not None: o.set_attr('path', webappp)
self.add_group('webapp', id)
self.add_group(otype, id)
def handle_rtoinst(self, cmd, *args):
pass