def get_component_set_from(config, components_lists): """ Use the Guesser API to fetch the components set from the given components_lists """ all_set = set() module_name = config.get(DEPMAKE_ACTION_NAME, GUESSER_MODULE_NAME) _LOGGER.debug("Guesser module name: %s" , module_name) module = __import__(to_str_from_unicode(module_name, should_be_uni=True)) # Go through sys.modules to find modules inside packages module = sys.modules[module_name] params = config.get(DEPMAKE_ACTION_NAME, GUESSER_PARAMS_NAME) params = replace_if_none(params) _LOGGER.debug("Guesser parameters: %s", params) params = to_str_from_unicode(params) guesser = module.get_guesser(params) _LOGGER.info("Using guesser: %s", guesser) for cl in components_lists: cl = to_str_from_unicode(cl, 'utf-8', True) (components_for, unknown) = guesser.guess_type(cl) if len(unknown) != 0: _LOGGER.warning("%s: [Unknown components]", unknown) for table in components_for: for type_ in components_for[table]: components = NodeSet(components_for[table][type_]) for component in components: comp2 = to_unicode(component) all_set.add(Component(comp2, type_, table)) return all_set
def dbcopy(db, config, args): """ Copy a rule or ruleset of the sequencer table. """ usage = "%prog [options] dbcopy " + \ "ruleset_src[:rule_src] ruleset_dst" doc = "Copy ruleset_src to ruleset_dst" + \ " or copy rule_src from ruleset_src to ruleset_dest." cmd = os.path.basename(sys.argv[0]) progname=to_unicode(cmd).encode('ascii', 'replace') parser = optparse.OptionParser(usage, description=doc, prog=progname) (options, copy_args) = parser.parse_args(args) if len(copy_args) < 2: parser.error(DBCOPY_ACTION_NAME + \ ": expected a minimum of %d arguments, given %d" % \ (2, len(copy_args))) (ruleset_src, sep, rule_src) = copy_args[0].partition(":") ruleset_dst = copy_args[1] try: src_set = db.get_rules_for(ruleset_src) except UnknownRuleSet as urs: _LOGGER.error(str(urs)) return 1 dst_set = dict() try: dst_set = db.get_rules_for(ruleset_dst) except UnknownRuleSet: pass rule_src = replace_if_none(rule_src) if rule_src is None and len(dst_set) != 0: _LOGGER.error(DBCOPY_ACTION_NAME + \ ": ruleset %s already exists!", ruleset_dst) return 1 if rule_src is not None and len(rule_src) != 0: if rule_src in dst_set: _LOGGER.error(DBCOPY_ACTION_NAME + \ ": rule %s " + \ " already exists in " + \ "ruleset %s!", rule_src, ruleset_dst) return 1 if rule_src not in src_set: _LOGGER.error(DBCOPY_ACTION_NAME + \ ": unknown rule %s in ruleset %s", rule_src, ruleset_src) return 1 rule_dst = src_set[rule_src] rule_dst.ruleset = ruleset_dst db.add_rules([rule_dst]) return for rule in src_set.values(): rule.ruleset = ruleset_dst dst_set[rule.name] = rule db.add_rules(dst_set.values())
def create_rule_from_strings_array(given_row): """ Function that creates a Rule from a strings array Arguments are converted to their final model format. """ row = [replace_if_none(x) for x in given_row] ruleset = row[0] name = row[1] # Multiple types are allowed: they are separated by symbol ',' try: # Try unicode first types = None if row[2] is None else [unicode.strip(x) for x in row[2].split(',')] except TypeError: # Try str then types = None if row[2] is None else [str.strip(x) for x in row[2].split(',')] filter_ = row[3] action = row[4] depsfinder = row[5] # Multiple dependencies are allowed: they are separated by symbol ',' try: # Try unicode first dependson = None if row[6] is None else [unicode.strip(x) for x in row[6].split(',')] except TypeError: # Try str then. dependson = None if row[6] is None else [str.strip(x) for x in row[6].split(',')] comments = row[7] help = row[8] #if row[8] is not None else unicode(None) return Rule(ruleset, name, types, filter_, action, depsfinder, dependson, comments, help)