<commit_before>#!/usr/bin/env python2
import os, json, sys, traceback, re
from bottle import route, run, debug, template, request, validate, static_file, redirect, response
from config import *

# this bit of code should be more dynamic but that goes beyond my python-fu
# we basically want to import all templates in a given directory, instantiate objects from their classes,
# and keep a list of all of them (pref. alphabetically ordered)
from graph_templates.cpu import CpuTemplate
from graph_templates.swift_object_server import SwiftObjectServerTemplate
from graph_templates.swift_tempauth import SwiftTempauthTemplate
template_objects = [CpuTemplate(), SwiftObjectServerTemplate(), SwiftTempauthTemplate()]
templates = ["cpu", "swift_object_server", "swift_tempauth"]
<commit_msg>Load modules a little more dynamically<commit_after>#!/usr/bin/env python2
import os, json, sys, traceback, re
from inspect import isclass
from bottle import route, run, debug, template, request, validate, static_file, redirect, response
from config import *

# Load all the graph_templates sub-modules and create a list of
# template_objects and templates
# FIXME: Needs to detect sub-modules automatically (fill modlist)
from graph_templates import GraphTemplate

template_objects = []
templates = []
modlist = ['cpu', 'swift_object_server', 'swift_tempauth']
for module in modlist:
    imp = __import__('graph_templates.'+module, globals(), locals(), ['*'])
    for itemname in dir(imp):
        item = getattr(imp, itemname)
        if isclass(item) and item != GraphTemplate and issubclass(item, GraphTemplate):
            template_objects.append(item())
            templates.append(module)

{'fraction_non_alphanumeric': 0.0855106888361045, 'fraction_numerical': 0.0011876484560570072, 'mean_word_length': 5.505791505791506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2022852', 'n_tokens_mistral': 454, 'n_tokens_neox': 441, 'n_words': 172}