示例#1
0
    def attribute_hash(el, attribute):
        try:
            repr_str = unicode(getattr(el, attribute))
        except Exception as hash_err:
            logger.debug('Error reading attribute: '
                         '{} form element {} with id: {} | {}'
                         .format(attribute, el, el.Id, hash_err))
            return ''

        if diff_results:
            diff_results.processed_params.add(attribute)

        return get_str_hash(cleanup_repr_str(repr_str))
示例#2
0
def element_hash(rvt_element, include_type=False, diff_results=None):

    def param_hash(param):
        repr_str = '{} {}'.format(unicode(param.Definition.Name).ljust(30),
                                  param.AsValueString())
        if diff_results:
            diff_results.processed_params.add(param.Definition.Name)
        return get_str_hash(cleanup_repr_str(repr_str))

    def attribute_hash(el, attribute):
        try:
            repr_str = unicode(getattr(el, attribute))
        except Exception as hash_err:
            logger.debug('Error reading attribute: '
                         '{} form element {} with id: {} | {}'
                         .format(attribute, el, el.Id, hash_err))
            return ''

        if diff_results:
            diff_results.processed_params.add(attribute)

        return get_str_hash(cleanup_repr_str(repr_str))

    sorted_params = sorted(rvt_element.Parameters,
                           key=lambda x: x.Definition.Name)
    if diff_results:
        diff_results.rvt_element_types.add(type(rvt_element))

    hash_value = ''
    for parameter in sorted_params:
        if parameter.Definition.Name not in domain_param_exclude_list:
            if include_type:
                hash_value += param_hash(parameter)
            elif parameter.Definition.Name not in type_param_exclude_list:
                hash_value += param_hash(parameter)

    if type(rvt_element) in custom_attrs:
        for el_attr in custom_attrs[type(rvt_element)]:
            hash_value += attribute_hash(rvt_element, el_attr)

    return get_str_hash(hash_value)
示例#3
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)
示例#4
0
 def get_hash(self):
     return coreutils.get_str_hash(safe_strtype(self.get_cache_data()))
示例#5
0
    def get_config_file_hash(self):
        with open(self._cfg_file_path, 'r') as cfg_file:
            cfg_hash = get_str_hash(cfg_file.read())

        return cfg_hash
示例#6
0
def _make_extension_hash(extension):
    # creates a hash based on hash of baseclasses module that
    # the extension is based upon and also the user configuration version
    return coreutils.get_str_hash(BASE_TYPES_DIR_HASH +
                                  EXEC_PARAMS.engine_ver +
                                  extension.get_hash())[:HASH_CUTOFF_LENGTH]
示例#7
0
def _make_extension_hash(extension):
    # creates a hash based on hash of baseclasses module that the extension is based upon
    return get_str_hash(BASE_TYPES_DIR_HASH +
                        extension.ext_hash_value)[:HASH_CUTOFF_LENGTH]
示例#8
0
    make_canonical_name(LOADER_BASE_NAMESPACE, 'PyRevitCommandExtendedAvail')

CMD_AVAIL_TYPE_NAME_SELECTION = \
    make_canonical_name(LOADER_BASE_NAMESPACE, 'PyRevitCommandSelectionAvail')

# template dynamobim command class
DYNOCMD_EXECUTOR_TYPE_NAME = '{}.{}'\
    .format(LOADER_BASE_NAMESPACE, 'PyRevitCommandDynamoBIM')

SOURCE_FILE_EXT = '.cs'
SOURCE_FILE_FILTER = r'(\.cs)'

if not EXEC_PARAMS.doc_mode:
    BASE_TYPES_DIR_HASH = \
        get_str_hash(
            calculate_dir_hash(INTERFACE_TYPES_DIR, '', SOURCE_FILE_FILTER)
            + EXEC_PARAMS.engine_ver
            )[:HASH_CUTOFF_LENGTH]
    BASE_TYPES_ASM_FILE_ID = '{}_{}'\
        .format(BASE_TYPES_DIR_HASH, LOADER_BASE_NAMESPACE)
    BASE_TYPES_ASM_FILE = appdata.get_data_file(BASE_TYPES_ASM_FILE_ID,
                                                ASSEMBLY_FILE_TYPE)
    # taking the name of the generated data file and use it as assembly name
    BASE_TYPES_ASM_NAME = op.splitext(op.basename(BASE_TYPES_ASM_FILE))[0]
    mlogger.debug('Interface types assembly file is: %s', BASE_TYPES_ASM_NAME)
else:
    BASE_TYPES_DIR_HASH = BASE_TYPES_ASM_FILE_ID = None
    BASE_TYPES_ASM_FILE = BASE_TYPES_ASM_NAME = None


def _get_source_files_in(source_files_path):
    source_files = {}
示例#9
0
    if CPYTHON_ENGINE:
        CPYTHON_ENGINE_ASSM = CPYTHON_ENGINE.AssemblyPath
        mlogger.debug('Loading cpython engine: %s', CPYTHON_ENGINE_ASSM)
        assmutils.load_asm_file(CPYTHON_ENGINE_ASSM)
    else:
        raise PyRevitException('Can not find cpython engines.')

    # create a hash for the loader assembly
    # this hash is calculated based on:
    # - runtime csharp files
    # - runtime engine version
    # - cpython engine version
    BASE_TYPES_DIR_HASH = \
        coreutils.get_str_hash(
            coreutils.calculate_dir_hash(INTERFACE_TYPES_DIR, '', SOURCE_FILE_FILTER)
            + EXEC_PARAMS.engine_ver
            + str(CPYTHON_ENGINE.Version)
            )[:HASH_CUTOFF_LENGTH]
    RUNTIME_ASSM_FILE_ID = '{}_{}'\
        .format(BASE_TYPES_DIR_HASH, RUNTIME_NAMESPACE)
    RUNTIME_ASSM_FILE = \
        appdata.get_data_file(RUNTIME_ASSM_FILE_ID,
                              framework.ASSEMBLY_FILE_TYPE)
    # taking the name of the generated data file and use it as assembly name
    RUNTIME_ASSM_NAME = op.splitext(op.basename(RUNTIME_ASSM_FILE))[0]
    mlogger.debug('Interface types assembly file is: %s', RUNTIME_ASSM_NAME)
else:
    BASE_TYPES_DIR_HASH = RUNTIME_ASSM_FILE_ID = None
    RUNTIME_ASSM_FILE = RUNTIME_ASSM_NAME = None

示例#10
0
    def get_config_file_hash(self):
        """Get calculated unique hash for this config."""
        with codecs.open(self._cfg_file_path, 'r', 'utf-8') as cfg_file:
            cfg_hash = coreutils.get_str_hash(cfg_file.read())

        return cfg_hash
示例#11
0
 def ext_hash_value(self):
     return get_str_hash(safe_strtype(self.get_cache_data()))
示例#12
0
 def ext_hash_value(self):
     return get_str_hash(unicode(self.get_cache_data()))
示例#13
0
# template python command availability class
CMD_AVAIL_TYPE_NAME = \
    make_canonical_name(LOADER_BASE_NAMESPACE, 'PyRevitCommandDefaultAvail')

CMD_AVAIL_TYPE_NAME_CATEGORY = \
    make_canonical_name(LOADER_BASE_NAMESPACE, 'PyRevitCommandCategoryAvail')

CMD_AVAIL_TYPE_NAME_SELECTION = \
    make_canonical_name(LOADER_BASE_NAMESPACE, 'PyRevitCommandSelectionAvail')

source_file_filter = '(\.cs)'

if not EXEC_PARAMS.doc_mode:
    BASE_TYPES_DIR_HASH = \
        get_str_hash(
            calculate_dir_hash(INTERFACE_TYPES_DIR, '', source_file_filter)
            + EXEC_PARAMS.engine_ver
            )[:HASH_CUTOFF_LENGTH]
    BASE_TYPES_ASM_FILE_ID = '{}_{}'\
        .format(BASE_TYPES_DIR_HASH, LOADER_BASE_NAMESPACE)
    BASE_TYPES_ASM_FILE = appdata.get_data_file(BASE_TYPES_ASM_FILE_ID,
                                                ASSEMBLY_FILE_TYPE)
    # taking the name of the generated data file and use it as assembly name
    BASE_TYPES_ASM_NAME = op.splitext(op.basename(BASE_TYPES_ASM_FILE))[0]
    logger.debug(
        'Interface types assembly file is: {}'.format(BASE_TYPES_ASM_NAME))
else:
    BASE_TYPES_DIR_HASH = BASE_TYPES_ASM_FILE_ID = None
    BASE_TYPES_ASM_FILE = BASE_TYPES_ASM_NAME = None


def _get_source_files():
示例#14
0
 def param_hash(param):
     repr_str = '{} {}'.format(unicode(param.Definition.Name).ljust(30),
                               param.AsValueString())
     if diff_results:
         diff_results.processed_params.add(param.Definition.Name)
     return get_str_hash(cleanup_repr_str(repr_str))