def main(args): usage = """ usage: ruleman fetch [options] [ruleset0 ruleset1 ...] Options: -f, --force If no ruleset names are specified the only those enabled will be fetched, otherwise only the specified rulesets will be fetched even if not enabld. """ force = False try: opts, args = getopt.getopt(args, "hf", ["help", "force"]) except getopt.GetoptError as err: print(usage, file=sys.stderr) return 1 for o, a in opts: if o in ["-h", "--help"]: print(usage) return 0 elif o in ["-f", "--force"]: force = True if not os.path.exists(config.RULESET_DATA_DIR): print("Creating directory %s." % config.RULESET_DATA_DIR) os.makedirs(config.RULESET_DATA_DIR) rulesets = config.get_rulesets() fetched = [] for ruleset in rulesets.values(): ret = False if args: if ruleset["name"] in args: ret = fetch_ruleset(ruleset, force=force) else: ret = fetch_ruleset(ruleset, force=force) if ret: fetched.append(ruleset["name"]) # Return a list of ruleset names that were actually fetched. return fetched
def search(self): rulesets = config.get_rulesets() for ruleset in rulesets.itervalues(): core.load_ruleset_files(ruleset) core.load_ruleset_rules(ruleset) logger.info("Loaded ruleset %s: %d files; %d rules" % ( ruleset["name"], len(ruleset["files"]), len(ruleset["rules"]))) match_count = 0 for ruleset in rulesets.itervalues(): for rule in ruleset["rules"].itervalues(): if self.is_match(rule): match_count += 1 self.print_rule(ruleset["name"], rule) print("Found %d rules." % (match_count))
def test_get_rulesets(self): rulesets = config.get_rulesets() self.assertTrue("partial" in rulesets) self.assertTrue("complete" in rulesets)