<commit_before>
from exceptions import Exception
import logging

from common cimport *
from vixDiskLib_headers cimport *
import numpy as np
# "cimport" is used to import special compile-time information
# about the numpy module (this is stored in a file numpy.pxd which is
# currently part of the Cython distribution).
cimport numpy as np

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

class VixDiskLibError(Exception):
    pass

# Add some default callbacks (from the sample application in the VDDK)
cdef void LogFunc(char *format, va_list args):
    cdef char buffer[1000]
    PyOS_vsnprintf(buffer, 1000, format, args)
    log.debug(buffer.strip())

cdef void WarnFunc(char *format, va_list args):
    cdef char buffer[1000]
    PyOS_vsnprintf(buffer, 1000, format, args)
    log.warn(buffer.strip())

cdef void PanicFunc(char *format, va_list args):
    cdef char buffer[1000]
    PyOS_vsnprintf(buffer, 1000, format, args)
    log.error(buffer.strip())
    
cdef bint progressCallback(void *data, int percentComplete): 
    cdef char buffer[1000]
    if data != NULL:
        sprintf(buffer, "%s: %d% complete", <char *>data, percentComplete)
    else:
        sprintf(buffer, "%d% complete", percentComplete)
    log.info(buffer)

DTYPE  = np.uint8
ctypedef np.uint8_t DTYPE_t

VixDiskLibSectorSize = VIXDISKLIB_SECTOR_SIZE
cdef int DEFAULT_BLOCK_SIZE = 1048576 # 1MB

cdef uint32 SECTORS_PER_BLOCK = DEFAULT_BLOCK_SIZE/VIXDISKLIB_SECTOR_SIZE

cdef int VIXDISKLIB_VERSION_MAJOR = 1
cdef int VIXDISKLIB_VERSION_MINOR = 2

class VixCredentials(object):
    def __init__(self, host, username, password):
        self.host = host
        self.username = username
        self.password = password
    
class VixDiskOpenFlags:
    UNBUFFERED = VIXDISKLIB_FLAG_OPEN_UNBUFFERED
    SINGLE_LINK = VIXDISKLIB_FLAG_OPEN_SINGLE_LINK
    READ_ONLY = VIXDISKLIB_FLAG_OPEN_READ_ONLY

class VDDKError(Exception):
    pass


cdef class VixDiskLib(object):
    cdef VixDiskLibHandle handle
    cdef np.ndarray buff
    cdef VixDiskLibConnectParams params
    cdef VixDiskLibConnection conn
    
    cdef info
    cdef connected
    cdef opened
    cdef cred
    cdef ro
    cdef char *libdir
    cdef char *config
    cdef vmdk_path
    
    def __init__(self, vmxSpec, params, libdir=None, conf=None):
        log.debug("Initializing vixDiskLib")<commit_msg>Added callback for VixDiskLib logging<commit_after>
from exceptions import Exception
import logging

from common cimport *
from vixDiskLib_headers cimport *
import numpy as np
# "cimport" is used to import special compile-time information
# about the numpy module (this is stored in a file numpy.pxd which is
# currently part of the Cython distribution).
cimport numpy as np

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

logging_callback = None

class VixDiskLibError(Exception):
    pass

# Add some default callbacks (from the sample application in the VDDK)
cdef void LogFunc(char *format, va_list args):
    cdef char buffer[1000]
    PyOS_vsnprintf(buffer, 1000, format, args)
    if logging_callback:
        logging_callback(logging.INFO, buffer.strip()))
    else:
        log.debug(buffer.strip())

cdef void WarnFunc(char *format, va_list args):
    cdef char buffer[1000]
    PyOS_vsnprintf(buffer, 1000, format, args)
    if logging_callback:
        logging_callback(logging.WARN, buffer.strip()))
    else:
        log.warn(buffer.strip())

cdef void PanicFunc(char *format, va_list args):
    cdef char buffer[1000]
    PyOS_vsnprintf(buffer, 1000, format, args)
    if logging_callback:
        logging_callback(logging.CRITICAL, buffer.strip()))
    else:
        log.error(buffer.strip())
    
cdef bint progressCallback(void *data, int percentComplete): 
    cdef char buffer[1000]
    if data != NULL:
        sprintf(buffer, "%s: %d% complete", <char *>data, percentComplete)
    else:
        sprintf(buffer, "%d% complete", percentComplete)
    log.info(buffer)

DTYPE  = np.uint8
ctypedef np.uint8_t DTYPE_t

VixDiskLibSectorSize = VIXDISKLIB_SECTOR_SIZE
cdef int DEFAULT_BLOCK_SIZE = 1048576 # 1MB

cdef uint32 SECTORS_PER_BLOCK = DEFAULT_BLOCK_SIZE/VIXDISKLIB_SECTOR_SIZE

cdef int VIXDISKLIB_VERSION_MAJOR = 1
cdef int VIXDISKLIB_VERSION_MINOR = 2

class VixCredentials(object):
    def __init__(self, host, username, password):
        self.host = host
        self.username = username
        self.password = password
    
class VixDiskOpenFlags:
    UNBUFFERED = VIXDISKLIB_FLAG_OPEN_UNBUFFERED
    SINGLE_LINK = VIXDISKLIB_FLAG_OPEN_SINGLE_LINK
    READ_ONLY = VIXDISKLIB_FLAG_OPEN_READ_ONLY

class VDDKError(Exception):
    pass


cdef class VixDiskLib(object):
    cdef VixDiskLibHandle handle
    cdef np.ndarray buff
    cdef VixDiskLibConnectParams params
    cdef VixDiskLibConnection conn
    
    cdef info
    cdef connected
    cdef opened
    cdef cred
    cdef ro
    cdef char *libdir
    cdef char *config
    cdef vmdk_path
    
    def __init__(self, vmxSpec, params, libdir=None, conf=None, callback=None):
        log.debug("Initializing vixDiskLib")
        
        global logging_callback
        logging_callback = callback
{'fraction_non_alphanumeric': 0.07289647150058162, 'fraction_numerical': 0.016285381930981, 'mean_word_length': 3.82600561272217, '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': '2235216', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1670, 'n_words': 467}