import logging
log = logging.getLogger('pyi2ncommon.arnied_wrapper')
-from .cnfline import build_cnfvar
from . import cnfvar_old
from . import sysmisc
os.close(fd)
os.unlink(filename)
return filename
-
-
-# enum
-Delete = 0
-Update = 1
-Add = 2
-Child = 3
-
-
-def batch_update_cnf(cnf, vars):
- """
- Perform a batch update of multiple cnf variables.
-
- :param cnf: CNF variable to update
- :type cnf: BuildCnfVar object
- :param vars: tuples of enumerated action and subtuple with data
- :type vars: [(int, (str, int, str))]
- :returns: updated CNF variable
- :rtype: BuildCnfVar object
-
- The actions are indexed in the same order: delete, update, add, child.
- """
- last = 0
- for (action, data) in vars:
- if action == Update:
- var, ref, val = data
- last = cnf.update_cnf(var, ref, val)
- elif action == Add:
- var, ref, val = data
- last = cnf.add_cnf(var, ref, val)
- elif action == Delete:
- last = cnf.del_cnf(data)
- elif action == Child: # only one depth supported
- var, ref, val = data
- # do not update last
- cnf.add_cnf(var, ref, val, different_parent_line_no=last)
- return cnf
-
-
-def build_cnf(kind, instance=0, vals=[], data="", filename=None):
- """
- Build a CNF variable and save it in a config file.
-
- :param str kind: name of the CNF variable
- :param int instance: instance number of the CNF variable
- :param vals: tuples of enumerated action and subtuple with data
- :type vals: [(int, (str, int, str))]
- :param str data: data for the CNF variable
- :param filename: optional custom name of the config file
- :type filename: str or None
- :returns: name of the saved config file
- :rtype: str
- """
- builder = build_cnfvar.BuildCnfVar(kind, instance=instance, data=data)
- batch_update_cnf(builder, vals)
- filename = generate_config_path(dumped=True) if filename is None else filename
- [filename] = prep_config_paths([filename], DUMP_CONFIG_DIR)
- builder.save(filename)
- return filename
-