<commit_before>from medic cimport *
from cython.operator cimport dereference
from cython.operator cimport preincrement
import fnmatch
import os
import re
import sys
from maya import OpenMaya


class StaticVars:
    TesterPathEnvName = "MEDIC_TESTER_PATH"
    KartePathEnvName = "MEDIC_KARTE_PATH"
    RePluginExt = re.compile("[.]%s$" % ("so" if "linux" in sys.platform else "bundle" if "darwin" == sys.platform else "dll"), re.IGNORECASE)
    ReKarteExt = re.compile("[.]karte$", re.IGNORECASE)
    RePyExt = re.compile("[.]py$", re.IGNORECASE)
    SelectionList = OpenMaya.MSelectionList()


class Types:
    Null = MdTypes.MdNull
    Bool = MdTypes.MdBool
    Int = MdTypes.MdInt
    Float = MdTypes.MdFloat
    String = MdTypes.MdString
    BoolArray = MdTypes.MdBoolArray
    IntArray = MdTypes.MdIntArray
    FloatArray = MdTypes.MdFloatArray
    StringArray = MdTypes.MdStringArray


cdef class Parameter:
    cdef MdParameter *ptr

    def __cinit__(self, name, label, typ, defaultValue):
        if typ == Types.Bool or typ == Types.BoolArray:
            self.ptr = MdParameter.Create[bint](name, label, typ, defaultValue, NULL)
        elif typ == Types.Int or typ == Types.IntArray:
            self.ptr = MdParameter.Create[int](name, label, typ, defaultValue, NULL)
        elif typ == Types.Float or typ == Types.FloatArray:
            self.ptr = MdParameter.Create[float](name, label, typ, defaultValue, NULL)
        elif typ == Types.String or typ == Types.StringArray:
            self.ptr = MdParameter.Create[string](name, label, typ, defaultValue, NULL)
        else:
            print "WARNING : NOT SUPPORTED TYPE"


cdef class ParamContainer:
    cdef MdParamContainer *ptr

    def __cinit__(self):
        self.ptr = new MdParamContainer()

    def append(self, Parameter param):
        return self.ptr.append(param.ptr)


    def set(self, paramName, value, index=0):
        cdef MdParameter *ptr = self.ptr.getParam(<string>paramName)

        if ptr == NULL:
            return False

        typ = ptr.getType()

        if typ == Types.Bool or typ == Types.BoolArray:
            return self.ptr.set[bint](paramName, value, <size_t>index)
        elif typ == Types.Int or typ == Types.IntArray:
            return self.ptr.set[int](paramName, value, <size_t>index)
        elif typ == Types.Float or typ == Types.FloatArray:
            return self.ptr.set[float](paramName, value, <size_t>index)
        elif typ == Types.String or typ == Types.StringArray:
            return self.ptr.set[string](paramName, value, <size_t>index)

        return False

    def get(self, paramName, index=0):
        cdef bint boolValue
        cdef int intValue
        cdef float floatValue
        cdef string stringValue

        cdef MdParameter *ptr = self.ptr.getParam(<string>paramName)

        if ptr == NULL:
            return None

        typ = ptr.getType()

        if typ == Types.Bool or typ == Types.BoolArray:
            self.ptr.get[bint](paramName, boolValue, <size_t>index)
            return boolValue
        elif typ == Types.Int or typ == Types.IntArray:
            self.ptr.get[int](paramName, intValue, <size_t>index)
            return intValue
        elif typ == Types.Float or typ == Types.FloatArray:
            self.ptr.get[float](paramName, floatValue, <size_t>index)
            return floatValue
        elif typ == Types.String or typ == Types.StringArray:
            self.ptr.get[string](paramName, stringValue, <size_t>index)
            return stringValue

        return None

    def getDefault(self, paramName):
        cdef bint boolValue
        cdef int intValue
        cdef float floatValue
        cdef string stringValue

        cdef MdParameter *ptr = self.ptr.getParam(<string>paramName)

        if ptr == NULL:
            return None

        typ = ptr.getType()

        if typ == Types.Bool or typ == Types.BoolArray:
            self.ptr.getDefault[bint](paramName, boolValue)
            return boolValue
        elif typ == Types.Int or typ == Types.IntArray:
            self.ptr.getDefault[int](paramName, intValue)
            return intValue
        elif typ == Types.Float or typ == Types.FloatArray:
            self.ptr.getDefault[float](paramName, floatValue)
            return floatValue
        elif typ == Types.String or typ == Types.StringArray:
            self.ptr.getDefault[string](paramName, stringValue)
            return stringValue

        return None

    def __dealloc__(self):
        del(self.ptr)


cdef class Node:
    cdef MdNode *ptr
    cdef bint needToDelete
    m_obj = OpenMaya.MObject()
    m_dg = OpenMaya.MFnDependencyNode()
    m_dag = OpenMaya.MFnDagNode()

    def __cinit__(self):
        needToDelete = False

    def __dealloc__(self):
        if self.needToDelete:
            del(self.ptr)

    def initialize(self):
        if self.ptr == NULL:
            return False
<commit_msg>add static method Create to Parameter, ParamContainer<commit_after>from medic cimport *
from cython.operator cimport dereference
from cython.operator cimport preincrement
import fnmatch
import os
import re
import sys
from maya import OpenMaya


class StaticVars:
    TesterPathEnvName = "MEDIC_TESTER_PATH"
    KartePathEnvName = "MEDIC_KARTE_PATH"
    RePluginExt = re.compile("[.]%s$" % ("so" if "linux" in sys.platform else "bundle" if "darwin" == sys.platform else "dll"), re.IGNORECASE)
    ReKarteExt = re.compile("[.]karte$", re.IGNORECASE)
    RePyExt = re.compile("[.]py$", re.IGNORECASE)
    SelectionList = OpenMaya.MSelectionList()


class Types:
    Null = MdTypes.MdNull
    Bool = MdTypes.MdBool
    Int = MdTypes.MdInt
    Float = MdTypes.MdFloat
    String = MdTypes.MdString
    BoolArray = MdTypes.MdBoolArray
    IntArray = MdTypes.MdIntArray
    FloatArray = MdTypes.MdFloatArray
    StringArray = MdTypes.MdStringArray


cdef class Parameter:
    cdef MdParameter *ptr

    def __cinit__(self):
        pass

    @staticmethod
    def Create(name, label, typ, defaultValue):
        pram = Parameter()
        if typ == Types.Bool or typ == Types.BoolArray:
            pram.ptr = MdParameter.Create[bint](name, label, typ, defaultValue, NULL)
        elif typ == Types.Int or typ == Types.IntArray:
            pram.ptr = MdParameter.Create[int](name, label, typ, defaultValue, NULL)
        elif typ == Types.Float or typ == Types.FloatArray:
            pram.ptr = MdParameter.Create[float](name, label, typ, defaultValue, NULL)
        elif typ == Types.String or typ == Types.StringArray:
            pram.ptr = MdParameter.Create[string](name, label, typ, defaultValue, NULL)
        else:
            print "WARNING : NOT SUPPORTED TYPE"
            return None

        return pram


cdef class ParamContainer:
    cdef MdParamContainer *ptr

    def __cinit__(self):
        pass

    @staticmethod
    def Create():
        con = ParamContainer()
        con.ptr = new MdParamContainer()
        return con

    def append(self, Parameter param):
        if self.ptr == NULL:
            return None

        return self.ptr.append(param.ptr)

    def set(self, paramName, value, index=0):
        if self.ptr == NULL:
            return False

        cdef MdParameter *ptr = self.ptr.getParam(<string>paramName)

        if ptr == NULL:
            return False

        typ = ptr.getType()

        if typ == Types.Bool or typ == Types.BoolArray:
            return self.ptr.set[bint](paramName, value, <size_t>index)
        elif typ == Types.Int or typ == Types.IntArray:
            return self.ptr.set[int](paramName, value, <size_t>index)
        elif typ == Types.Float or typ == Types.FloatArray:
            return self.ptr.set[float](paramName, value, <size_t>index)
        elif typ == Types.String or typ == Types.StringArray:
            return self.ptr.set[string](paramName, value, <size_t>index)

        return False

    def get(self, paramName, index=0):
        if self.ptr == NULL:
            return None

        cdef bint boolValue
        cdef int intValue
        cdef float floatValue
        cdef string stringValue

        cdef MdParameter *ptr = self.ptr.getParam(<string>paramName)

        if ptr == NULL:
            return None

        typ = ptr.getType()

        if typ == Types.Bool or typ == Types.BoolArray:
            self.ptr.get[bint](paramName, boolValue, <size_t>index)
            return boolValue
        elif typ == Types.Int or typ == Types.IntArray:
            self.ptr.get[int](paramName, intValue, <size_t>index)
            return intValue
        elif typ == Types.Float or typ == Types.FloatArray:
            self.ptr.get[float](paramName, floatValue, <size_t>index)
            return floatValue
        elif typ == Types.String or typ == Types.StringArray:
            self.ptr.get[string](paramName, stringValue, <size_t>index)
            return stringValue

        return None

    def getDefault(self, paramName):
        if self.ptr == NULL:
            return None

        cdef bint boolValue
        cdef int intValue
        cdef float floatValue
        cdef string stringValue

        cdef MdParameter *ptr = self.ptr.getParam(<string>paramName)

        if ptr == NULL:
            return None

        typ = ptr.getType()

        if typ == Types.Bool or typ == Types.BoolArray:
            self.ptr.getDefault[bint](paramName, boolValue)
            return boolValue
        elif typ == Types.Int or typ == Types.IntArray:
            self.ptr.getDefault[int](paramName, intValue)
            return intValue
        elif typ == Types.Float or typ == Types.FloatArray:
            self.ptr.getDefault[float](paramName, floatValue)
            return floatValue
        elif typ == Types.String or typ == Types.StringArray:
            self.ptr.getDefault[string](paramName, stringValue)
            return stringValue

        return None

    def __dealloc__(self):
        if self.ptr != NULL:
            del(self.ptr)


cdef class Node:
    cdef MdNode *ptr
    cdef bint needToDelete
    m_obj = OpenMaya.MObject()
    m_dg = OpenMaya.MFnDependencyNode()
    m_dag = OpenMaya.MFnDagNode()

    def __cinit__(self):
        needToDelete = False

    def __dealloc__(self):
        if self.needToDelete:
            del(self.ptr)

    def initialize(self):
        if self.ptr == NULL:
            return False

{'fraction_non_alphanumeric': 0.09727325468961516, 'fraction_numerical': 0.00038677238445175013, 'mean_word_length': 2.339683564740071, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '5767428', 'n_tokens_mistral': 3129, 'n_tokens_neox': 3030, 'n_words': 822}