<commit_before>#
# Jasy - JavaScript Tooling Framework
# Copyright 2010-2011 <NAME>
#

import logging, itertools, time, atexit, json
from jasy.core.Permutation import Permutation
from jasy.core.Translation import Translation
from jasy.core.Info import *
from jasy.core.Profiler import *
from jasy.core.LocaleData import *

from jasy.Project import Project
from jasy.File import *
from jasy.Resolver import Resolver
from jasy.Optimization import Optimization
from jasy.Combiner import Combiner
from jasy.Sorter import Sorter


def toJSON(obj, sort_keys=False):
    return json.dumps(obj, separators=(',',':'), ensure_ascii=False, sort_keys=sort_keys)
    

class Session():
    def __init__(self):
        atexit.register(self.close)

        self.__timestamp = time.time()
        self.__projects = []
        self.__localeProjects = {}
        self.__fields = {}
        
        self.addProject(Project(coreProject()))
    
    
    #
    # Project Managment
    #
        
    def addProject(self, project, main=False):
        """ Adds the given project to the list of known projects """
        
        self.__projects.append(project)
        
        # That's the project from where all paths are computed
        if main:
            logging.info("Main project is: %s" % project.getName())
            self.__mainProject = project

        # Import project defined fields which might be configured using "activateField()"
        fields = project.getFields()
        for name in fields:
            entry = fields[name]

            if name in self.__fields:
                raise Exception("Field '%s' was already defined!")

            if "check" in entry:
                check = entry["check"]
                if check in ["Boolean", "String", "Number"] or type(check) == list:
                    pass
                else:
                    raise Exception("Unsupported check: '%s' for field '%s'" % (check, name))
                    
            if "detect" in entry:
                detect = entry["detect"]
                if not self.getClass(detect):
                    raise Exception("Field '%s' uses unknown detection class %s." % (name, detect))
                
            self.__fields[name] = entry
        
        
    def getProjects(self, permutation=None):
        """ 
        Returns all currently known projects.
        Automatically adds the currently configured locale project.
        """<commit_msg>added missing parameter for error handling.<commit_after>#
# Jasy - JavaScript Tooling Framework
# Copyright 2010-2011 <NAME>
#

import logging, itertools, time, atexit, json
from jasy.core.Permutation import Permutation
from jasy.core.Translation import Translation
from jasy.core.Info import *
from jasy.core.Profiler import *
from jasy.core.LocaleData import *

from jasy.Project import Project
from jasy.File import *
from jasy.Resolver import Resolver
from jasy.Optimization import Optimization
from jasy.Combiner import Combiner
from jasy.Sorter import Sorter


def toJSON(obj, sort_keys=False):
    return json.dumps(obj, separators=(',',':'), ensure_ascii=False, sort_keys=sort_keys)
    

class Session():
    def __init__(self):
        atexit.register(self.close)

        self.__timestamp = time.time()
        self.__projects = []
        self.__localeProjects = {}
        self.__fields = {}
        
        self.addProject(Project(coreProject()))
    
    
    #
    # Project Managment
    #
        
    def addProject(self, project, main=False):
        """ Adds the given project to the list of known projects """
        
        self.__projects.append(project)
        
        # That's the project from where all paths are computed
        if main:
            logging.info("Main project is: %s" % project.getName())
            self.__mainProject = project

        # Import project defined fields which might be configured using "activateField()"
        fields = project.getFields()
        for name in fields:
            entry = fields[name]

            if name in self.__fields:
                raise Exception("Field '%s' was already defined!" % (name))

            if "check" in entry:
                check = entry["check"]
                if check in ["Boolean", "String", "Number"] or type(check) == list:
                    pass
                else:
                    raise Exception("Unsupported check: '%s' for field '%s'" % (check, name))
                    
            if "detect" in entry:
                detect = entry["detect"]
                if not self.getClass(detect):
                    raise Exception("Field '%s' uses unknown detection class %s." % (name, detect))
                
            self.__fields[name] = entry
        
        
    def getProjects(self, permutation=None):
        """ 
        Returns all currently known projects.
        Automatically adds the currently configured locale project.
        """
{'fraction_non_alphanumeric': 0.09458088086056424, 'fraction_numerical': 0.0032474122183884717, 'mean_word_length': 2.0974230043997486, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6675842', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1246, 'n_words': 402}