def main(argc, argv): parser = argparse.ArgumentParser("Generate API documentation.") parser.add_argument( "--tables", default="osquery/tables/specs", help="Path to osquery table specs" ) parser.add_argument( "--profile", default=None, help="Add the results of a profile summary to the API." ) args = parser.parse_args() logging.basicConfig(format=LOG_FORMAT, level=logging.INFO) if not os.path.exists(args.tables): logging.error("Cannot find path: %s" % (args.tables)) exit(1) profile = {} if args.profile is not None: if not os.path.exists(args.profile): logging.error("Cannot find path: %s" % (args.profile)) exit(1) with open(args.profile, "r") as fh: try: profile = json.loads(fh.read()) except Exception as e: logging.error("Cannot parse profile data: %s" % (str(e))) exit(2) # Read in the optional list of blacklisted tables blacklist = None blacklist_path = os.path.join(args.tables, "blacklist") if os.path.exists(blacklist_path): with open(blacklist_path, "r") as fh: blacklist = fh.read() categories = {} for base, _, files in os.walk(args.tables): for spec_file in files: # Exclude blacklist specific file if spec_file == 'blacklist': continue platform = os.path.basename(base) platform_name = CANONICAL_PLATFORMS[platform] name = spec_file.split(".table", 1)[0] if platform not in categories.keys(): categories[platform] = {"name": platform_name, "tables": []} with open(os.path.join(base, spec_file), "rU") as fh: tree = ast.parse(fh.read()) table_spec = gen_spec(tree) table_profile = profile.get("%s.%s" % (platform, name), {}) table_spec["profile"] = NoIndent(table_profile) table_spec["blacklisted"] = is_blacklisted(table_spec["name"], blacklist=blacklist) categories[platform]["tables"].append(table_spec) categories = [{"key": k, "name": v["name"], "tables": v["tables"]} for k, v in categories.iteritems()] print(gen_api(categories))