<commit_before>#
# Jasy - Web Tooling Framework
# Copyright 2010-2012 Zynga Inc.
#

import logging, os, random

from jasy.core.Error import JasyError
from jasy.core.Permutation import Permutation

import jasy.core.Env
from jasy.core.Env import *

from jasy.js.Class import Error as ClassError


def storeKernel(fileName, assets=None, translations=None, debug=False):
    """
    Writes a so-called kernel script to the given location. This script contains
    data about possible permutations based on current session values. It optionally
    might include asset data (useful when boot phase requires some assets) and 
    localization data (if only one locale is built).
    
    Optimization of the script is auto-enabled when no other information is given.
    
    This method returns the classes which are included by the script so you can 
    exclude it from the real other generated output files.
    """
    
    startSection("Storing kernel...")
    
    # This exports all field values from the session
    fields = session.exportFields()
    
    # This permutation injects data in the core classes and configures debugging as given by parameter
    #
    # - fields => core.Env
    # - assets => core.Asset
    # - translations => core.Locale
    setPermutation(Permutation({
        "debug" : debug,
        "fields" : fields,
        "assets" : assets,
        "translations" : translations
    }))
    
    # Build resolver
    # We need the permutation here because the field configuration might rely on detection classes
    resolver = Resolver()
    
    # Include classes for value injection
    if fields is not None:
        resolver.addClassName("core.Env")
    
    if assets is not None:
        resolver.addClassName("core.io.Asset")
        
    if translations is not None:
        resolver.addClassName("core.locale.Translate")

    # Include IO classes
    resolver.addClassName("core.io.Queue")
    
    # Sort resulting class list
    classes = Sorter(resolver).getSortedClasses()
    storeCompressed(fileName, classes)
    
    setPermutation(None)
    
    return classes



def storeCombined(fileName, classes, bootCode=None):
    """
    Combines the unmodified content of the stored class list
    """

    try:
        result = "".join([classObj.getText() for classObj in classes])
        if bootCode:
            result += bootCode
        
    except ClassError as error:
        raise JasyError("Error during class combining! %s" % error)

    writeFile(fileName, result)



def storeCompressed(fileName, classes, bootCode="", translation=None):
    """
    Combines the compressed result of the stored class list
    
    - fileName: Filename to write to
    - classes: Classes to include in the compressed file in correct order
    - bootCode: Code to execute once all the classes are loaded
    - permutation: Permutation to apply to the classes before compression (for alternative code variants) (See Permutation.py)
    - translation: Translation to apply to the classes before compression (inlining of translation)
    """
    
    logging.info("Compressing %s classes...", len(classes))

    try:
        result = "".join([classObj.getCompressed(getPermutation(), translation, optimization, formatting) for classObj in classes])
        if bootCode:
            result += bootCode
        
    except ClassError as error:
        raise JasyError("Error during class compression! %s" % error)
        
    writeFile(fileName, result)



def storeSourceLoader(fileName, classes, bootCode="", urlPrefix=""):
    """
    Generates a source loader which is basically a file which loads the original JavaScript files.
    This is super useful during development of a project as it supports pretty fast workflows
    where most often a simple reload in the browser is enough to get the newest sources.
    
    - fileName: Filename to write to
    - classes: Classes to include in the compressed file in correct order
    - bootCode: Code to run after all defined classes have been loaded.
    - prefixUrl: Useful when the project files are stored on another domain (CDN). Puts the given URL prefix in front of all URLs to load.
    """
    
    logging.info("Building source loader (%s classes)...", len(classes))

    main = session.getMain()
    files = []
    for classObj in classes:
        # Support for multi path classes (e.g. in manual mode)
        path = classObj.getPath()
        if type(path) is list:
            for split in path:
                files.append(main.toRelativeUrl(split, urlPrefix))
        else:
            files.append(main.toRelativeUrl(path, urlPrefix))
    <commit_msg>Renamed<commit_after>#
# Jasy - Web Tooling Framework
# Copyright 2010-2012 Zynga Inc.
#

import logging, os, random

from jasy.core.Error import JasyError
from jasy.core.Permutation import Permutation

import jasy.core.Env
from jasy.core.Env import *

from jasy.js.Class import Error as ClassError


def storeKernel(fileName, assets=None, translations=None, debug=False):
    """
    Writes a so-called kernel script to the given location. This script contains
    data about possible permutations based on current session values. It optionally
    might include asset data (useful when boot phase requires some assets) and 
    localization data (if only one locale is built).
    
    Optimization of the script is auto-enabled when no other information is given.
    
    This method returns the classes which are included by the script so you can 
    exclude it from the real other generated output files.
    """
    
    startSection("Storing kernel...")
    
    # This exports all field values from the session
    fields = session.exportFields()
    
    # This permutation injects data in the core classes and configures debugging as given by parameter
    #
    # - fields => core.Env
    # - assets => core.Asset
    # - translations => core.Locale
    setPermutation(Permutation({
        "debug" : debug,
        "fields" : fields,
        "assets" : assets,
        "translations" : translations
    }))
    
    # Build resolver
    # We need the permutation here because the field configuration might rely on detection classes
    resolver = Resolver()
    
    # Include classes for value injection
    if fields is not None:
        resolver.addClassName("core.Env")
    
    if assets is not None:
        resolver.addClassName("core.io.Asset")
        
    if translations is not None:
        resolver.addClassName("core.locale.Translate")

    # Include IO classes
    resolver.addClassName("core.io.Queue")
    
    # Sort resulting class list
    classes = Sorter(resolver).getSortedClasses()
    storeCompressed(fileName, classes)
    
    setPermutation(None)
    
    return classes



def storeCombined(fileName, classes, bootCode=None):
    """
    Combines the unmodified content of the stored class list
    """

    try:
        result = "".join([classObj.getText() for classObj in classes])
        if bootCode:
            result += bootCode
        
    except ClassError as error:
        raise JasyError("Error during class combining! %s" % error)

    writeFile(fileName, result)



def storeCompressed(fileName, classes, bootCode="", translation=None):
    """
    Combines the compressed result of the stored class list
    
    - fileName: Filename to write to
    - classes: Classes to include in the compressed file in correct order
    - bootCode: Code to execute once all the classes are loaded
    - permutation: Permutation to apply to the classes before compression (for alternative code variants) (See Permutation.py)
    - translation: Translation to apply to the classes before compression (inlining of translation)
    """
    
    logging.info("Compressing %s classes...", len(classes))

    try:
        result = "".join([classObj.getCompressed(getPermutation(), translation, optimization, formatting) for classObj in classes])
        if bootCode:
            result += bootCode
        
    except ClassError as error:
        raise JasyError("Error during class compression! %s" % error)
        
    writeFile(fileName, result)



def storeLoader(fileName, classes, bootCode="", urlPrefix=""):
    """
    Generates a source loader which is basically a file which loads the original JavaScript files.
    This is super useful during development of a project as it supports pretty fast workflows
    where most often a simple reload in the browser is enough to get the newest sources.
    
    - fileName: Filename to write to
    - classes: Classes to include in the compressed file in correct order
    - bootCode: Code to run after all defined classes have been loaded.
    - prefixUrl: Useful when the project files are stored on another domain (CDN). Puts the given URL prefix in front of all URLs to load.
    """
    
    logging.info("Building source loader (%s classes)...", len(classes))

    main = session.getMain()
    files = []
    for classObj in classes:
        # Support for multi path classes (e.g. in manual mode)
        path = classObj.getPath()
        if type(path) is list:
            for split in path:
                files.append(main.toRelativeUrl(split, urlPrefix))
        else:
            files.append(main.toRelativeUrl(path, urlPrefix))
    
{'fraction_non_alphanumeric': 0.07428940568475452, 'fraction_numerical': 0.0017226528854435831, 'mean_word_length': 2.821061291649527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '89981', 'n_tokens_mistral': 2470, 'n_tokens_neox': 2362, 'n_words': 974}