Esempio n. 1
0
def _generate_base_classes_asm():
    source_list = []
    for source_file in _get_source_files():
        source_list.append(source_file)

    # now try to compile
    try:
        mlogger.debug('Compiling base types to: %s', BASE_TYPES_ASM_FILE)
        compile_csharp(source_list, BASE_TYPES_ASM_FILE,
                       reference_list=_get_references(), resource_list=[])
        return load_asm_file(BASE_TYPES_ASM_FILE)

    except PyRevitException as compile_err:
        errors = safe_strtype(compile_err).replace('Compile error: ', '')
        mlogger.critical('Can not compile base types code into assembly.\n%s',
                         errors)
        raise compile_err
Esempio n. 2
0
def _generate_base_classes_asm():
    source_list = list()
    source_list.append(_get_asm_attr_source())
    for source_file in _get_source_files():
        source_list.append(read_source_file(source_file))

    # now try to compile
    try:
        logger.debug('Compiling base types to: {}'.format(BASE_TYPES_ASM_FILE))
        # compile_csharp(source_list, BASE_TYPES_ASM_FILE,
        #                reference_list=_get_references(), resource_list=[_get_resource_file('python_27_lib.zip')])
        compile_csharp(source_list,
                       BASE_TYPES_ASM_FILE,
                       reference_list=_get_references())
        return load_asm_file(BASE_TYPES_ASM_FILE)

    except PyRevitException as compile_err:
        logger.critical(
            'Can not compile base types code into assembly. | {}'.format(
                compile_err))
        raise compile_err
Esempio n. 3
0
def _generate_base_classes_asm():
    source_list = list()
    # source_list.append(_get_asm_attr_source())
    for source_file in _get_source_files():
        # source_list.append(read_source_file(source_file))
        source_list.append(source_file)

    # now try to compile
    try:
        logger.debug('Compiling base types to: {}'.format(BASE_TYPES_ASM_FILE))
        compile_csharp(source_list,
                       BASE_TYPES_ASM_FILE,
                       reference_list=_get_references(),
                       resource_list=[])
        return load_asm_file(BASE_TYPES_ASM_FILE)

    except PyRevitException as compile_err:
        errors = '\n'.join(
            eval(unicode(compile_err).replace('Compile error: ', '')))
        logger.critical(
            'Can not compile base types code into assembly.\n{}'.format(
                errors))
        raise compile_err
Esempio n. 4
0
def _get_csharp_cmd_asm(cmd_component):
    """

    Args:
        cmd_component (pyrevit.extensions.genericcomps.GenericUICommand):

    Returns:

    """
    script_path = cmd_component.get_full_script_address()
    source = read_source_file(script_path)
    script_hash = get_str_hash(source)[:HASH_CUTOFF_LENGTH]

    command_assm_file_id = '{}_{}'\
        .format(script_hash, cmd_component.unique_name)

    # check to see if compiled c# command assembly is already loaded
    compiled_assm_list = find_loaded_asm(command_assm_file_id,
                                         by_partial_name=True)
    if len(compiled_assm_list) > 0:
        return compiled_assm_list[0]

    # if not already loaded, check to see if the assembly file exits
    compiled_assm_path = \
        appdata.is_data_file_available(file_id=command_assm_file_id,
                                       file_ext=ASSEMBLY_FILE_TYPE)
    if compiled_assm_path:
        return load_asm_file(compiled_assm_path)

    # else, let's compile the script and make the types
    command_assm_file = \
        appdata.get_data_file(file_id=command_assm_file_id,
                              file_ext=ASSEMBLY_FILE_TYPE)
    logger.debug('Compiling script {} to {}'.format(cmd_component,
                                                    command_assm_file))
    compiled_assm_path = compile_csharp([script_path],
                                        command_assm_file,
                                        reference_list=_get_references())
    return load_asm_file(compiled_assm_path)