Beispiel #1
0
    def _analyse_python_script(self):
        try:
            # reading script file content to extract parameters
            script_content = \
                coreutils.ScriptFileParser(self.get_full_script_address())

            # extracting min requried Revit and pyRevit versions
            extracted_ui_title = \
                script_content.extract_param(exts.UI_TITLE_PARAM)  # type: str
            if extracted_ui_title:
                self.ui_title = extracted_ui_title

            self.doc_string = script_content.get_docstring()
            custom_docstring = \
                script_content.extract_param(exts.DOCSTRING_PARAM)  # type: str
            if custom_docstring:
                self.doc_string = custom_docstring

            self.author = script_content.extract_param(
                exts.AUTHOR_PARAM)  # type: str
            self.max_revit_ver = script_content.extract_param(
                exts.MAX_REVIT_VERSION_PARAM)  # type: str
            self.min_revit_ver = script_content.extract_param(
                exts.MIN_REVIT_VERSION_PARAM)  # type: str
            self.cmd_help_url = script_content.extract_param(
                exts.COMMAND_HELP_URL)  # type: str

            # panel buttons should be active always
            if self.type_id != exts.PANEL_PUSH_BUTTON_POSTFIX:
                self.cmd_context = script_content.extract_param(
                    exts.COMMAND_CONTEXT_PARAM)  # type: str
                if isinstance(self.cmd_context, list):
                    self.cmd_context = ';'.join(self.cmd_context)
            else:
                self.cmd_context = exts.CTX_ZERODOC[0]

            self.beta_cmd = script_content.extract_param(
                exts.BETA_SCRIPT_PARAM)  # type: bool

            # only True when command is specifically asking for
            # a clean engine or a fullframe engine. False if not set.
            self.requires_clean_engine = script_content.extract_param(
                exts.CLEAN_ENGINE_SCRIPT_PARAM, False)  # type: bool
            self.requires_fullframe_engine = script_content.extract_param(
                exts.FULLFRAME_ENGINE_PARAM, False)  # type: bool

        except Exception as parse_err:
            self._handle_parse_err(self.script_file, parse_err)

        # FIXME: logger reports module as 'ast' after a
        # successfull param retrieval. Must be ast.literal_eval()
        mlogger.debug('Maximum host version: %s', self.max_revit_ver)
        mlogger.debug('Minimum host version: %s', self.min_revit_ver)
        mlogger.debug('command tooltip: %s', self.doc_string)
        mlogger.debug('Command author: %s', self.author)
        mlogger.debug('Command help url: %s', self.cmd_help_url)

        if self.beta_cmd:
            mlogger.debug('Command is in beta.')
Beispiel #2
0
def open_command_helpurl(pyrvtcmd):
    script_content = coreutils.ScriptFileParser(selected_cmd.script)
    helpurl = script_content.extract_param(exts.COMMAND_HELP_URL)
    if helpurl:
        script.open_url(helpurl)
        return True

    return False
Beispiel #3
0
def show_command_docstring(pyrvtcmd):
    script_content = coreutils.ScriptFileParser(selected_cmd.script)
    doc_string = script_content.get_docstring()
    custom_docstring = script_content.extract_param(exts.DOCSTRING_PARAM)
    if custom_docstring:
        doc_string = custom_docstring

    print(doc_string)
Beispiel #4
0
    def __init__(self, cmp_path=None, needs_commandclass=False):
        # using classname otherwise exceptions in superclasses won't show
        GenericUICommand.__init__(self, cmp_path=cmp_path, needs_script=False)
        self.assembly = self.command_class = None
        # to support legacy linkbutton types using python global var convention
        # if has python script, read metadata
        if self.script_language == exts.PYTHON_LANG:
            try:
                # reading script file content to extract parameters
                script_content = \
                    coreutils.ScriptFileParser(self.script_file)

                self.assembly = \
                    script_content.extract_param(exts.LINK_BUTTON_ASSEMBLY)

                self.command_class = \
                    script_content.extract_param(exts.LINK_BUTTON_COMMAND_CLASS)

                if self.assembly or self.command_class:
                    mlogger.deprecate(
                        "Creating link buttons using \"__assembly__\" "
                        "and \"__commandclass__\" global "
                        "variables inside a python file is deprecated. "
                        "use bundle.yaml instead. | %s", self)

            except PyRevitException as err:
                mlogger.error(err)

        # otherwise read metadata from metadata file
        elif self.meta:
            # get the target assembly from metadata
            self.assembly = \
                self.meta.get(exts.MDATA_LINK_BUTTON_ASSEMBLY, None)

            # get the target command class from metadata
            self.command_class = \
                self.meta.get(exts.MDATA_LINK_BUTTON_COMMAND_CLASS, None)

            # for invoke buttons there is no script source so
            # assign the metadata file to the script
            self.script_file = self.config_script_file = self.meta_file
        else:
            mlogger.debug("%s does not specify target assembly::class.", self)

        if not self.assembly:
            mlogger.error("%s does not specify target assembly.", self)

        if needs_commandclass and not self.command_class:
            mlogger.error("%s does not specify target command class.", self)

        mlogger.debug('%s assembly.class: %s.%s',
                      self, self.assembly, self.command_class)
Beispiel #5
0
    def __init_from_dir__(self, cmd_dir):
        GenericUICommand.__init_from_dir__(self, cmd_dir)
        self.assembly = self.command_class = None
        try:
            # reading script file content to extract parameters
            script_content = \
                coreutils.ScriptFileParser(self.get_full_script_address())

            self.assembly = script_content.extract_param(
                exts.LINK_BUTTON_ASSEMBLY_PARAM)  # type: str

            self.command_class = \
                script_content.extract_param(
                    exts.LINK_BUTTON_COMMAND_CLASS_PARAM)  # type: str

        except PyRevitException as err:
            mlogger.error(err)

        mlogger.debug('Link button assembly.class: %s.%s', self.assembly,
                      self.command_class)
Beispiel #6
0
    def _read_bundle_metadata_from_python_script(self):
        try:
            # reading script file content to extract parameters
            script_content = \
                coreutils.ScriptFileParser(self.script_file)

            self._ui_title = \
                script_content.extract_param(exts.UI_TITLE_PARAM) \
                    or self._ui_title

            script_docstring = script_content.get_docstring()
            custom_docstring = \
                script_content.extract_param(exts.DOCSTRING_PARAM)
            self._tooltip = \
                custom_docstring or script_docstring or self._tooltip

            script_author = script_content.extract_param(exts.AUTHOR_PARAM)
            script_author = script_content.extract_param(exts.AUTHORS_PARAM)
            if isinstance(script_author, list):
                script_author = '\n'.join(script_author)
            self.author = script_author or self.author

            # extracting min requried Revit and pyRevit versions
            self.max_revit_ver = \
                script_content.extract_param(exts.MAX_REVIT_VERSION_PARAM) \
                    or self.max_revit_ver
            self.min_revit_ver = \
                script_content.extract_param(exts.MIN_REVIT_VERSION_PARAM) \
                    or self.min_revit_ver
            self._help_url = \
                script_content.extract_param(exts.COMMAND_HELP_URL_PARAM) \
                    or self._help_url

            self.is_beta = \
                script_content.extract_param(exts.BETA_SCRIPT_PARAM) \
                    or self.is_beta

            self.highlight_type = \
                script_content.extract_param(exts.HIGHLIGHT_SCRIPT_PARAM) \
                    or self.highlight_type

            # only True when command is specifically asking for
            # a clean engine or a fullframe engine. False if not set.
            self.requires_clean_engine = \
                script_content.extract_param(exts.CLEAN_ENGINE_SCRIPT_PARAM) \
                    or False
            self.requires_fullframe_engine = \
                script_content.extract_param(exts.FULLFRAME_ENGINE_PARAM) \
                    or False
            self.requires_persistent_engine = \
                script_content.extract_param(exts.PERSISTENT_ENGINE_PARAM) \
                    or False

            # panel buttons should be active always
            if self.type_id == exts.PANEL_PUSH_BUTTON_POSTFIX:
                self.context = exts.CTX_ZERODOC[0]
            else:
                self.context = \
                    script_content.extract_param(exts.COMMAND_CONTEXT_PARAM)
                if isinstance(self.context, list):
                    self.context = coreutils.join_strings(self.context)

                if self.context and exts.CTX_ZERODOC[1] in self.context:
                    mlogger.deprecate(
                        "\"zerodoc\" context is deprecated. "
                        "use \"zero-doc\" instead. | %s", self)

        except Exception as parse_err:
            mlogger.log_parse_except(self.script_file, parse_err)