Ejemplo n.º 1
0
def dashboardRectMaker(value, description, treshold):
    """dashboard HTMl maker - rectangle with large number"""
    content = str(value)
    # normal button
    if value <= treshold:
        html_code = ("<a class='dashboardLink' title='OK - maximum value " +
                     str(int(treshold)) + "'><p class='dashboardRectNormal'>" +
                     content + "<br><span class='dashboardSmall'>" +
                     description + "</span>"
                     "</p></a>")
        return coreutils.prepare_html_str(html_code)
    # mediocre button
    elif value < treshold * 2:
        html_code = ("<a class='dashboardLink' href='" + WIKI_ARTICLE +
                     "' title='Mediocre - goal value " + str(int(treshold)) +
                     "'><p class='dashboardRectMediocre'>" + content +
                     "<br><span class='dashboardSmall'>" + description +
                     "</span>"
                     "</p></a>")
        return coreutils.prepare_html_str(html_code)
    # critical button
    else:
        html_code = ("<a class='dashboardLink' href='" + WIKI_ARTICLE +
                     "' title='Critical - goal value " + str(int(treshold)) +
                     "'><p class='dashboardRectCritical'>" + content +
                     "<br><span class='dashboardSmall'>" + description +
                     "</span>"
                     "</p></a>")
        return coreutils.prepare_html_str(html_code)
Ejemplo n.º 2
0
    def print_html(html_str):
        """Add the html code to the output window.

        Example:
            >>> output = pyrevit.output.get_output()
            >>> output.print_html('<strong>Title</strong>')
        """
        print(coreutils.prepare_html_str(html_str), end="")
Ejemplo n.º 3
0
    def print_code(code_str):
        """Print code to the output window with special formatting.

        Example:
            >>> output = pyrevit.output.get_output()
            >>> output.print_code('value = 12')
        """
        code_div = '<div class="code">{}</div>'
        print(coreutils.prepare_html_str(
            code_div.format(code_str.replace('    ', '&nbsp;' * 4))),
              end="")
Ejemplo n.º 4
0
    def print_md(md_str):
        """Process markdown code and print to output window.

        Example:
            >>> output = pyrevit.output.get_output()
            >>> output.print_md('### Title')
        """
        tables_ext = 'pyrevit.coreutils.markdown.extensions.tables'
        markdown_html = markdown.markdown(md_str, extensions=[tables_ext])
        markdown_html = markdown_html.replace('\n', '').replace('\r', '')
        html_code = coreutils.prepare_html_str(markdown_html)
        print(html_code, end="")
Ejemplo n.º 5
0
 def _handle_parse_err(self, filename, parse_err):
     err_msg = '<strong>Error while parsing file:</strong>\n{file}\n' \
               '<strong>Error type:</strong> {type}\n' \
               '<strong>Error Message:</strong> {errmsg}\n' \
               '<strong>Line/Column:</strong> {lineno}/{colno}\n' \
               '<strong>Line Text:</strong> {linetext}' \
               .format(file=filename,
                       type=parse_err.__class__.__name__,
                       errmsg=parse_err.msg,
                       lineno=parse_err.lineno,
                       colno=parse_err.offset,
                       linetext=parse_err.text)
     mlogger.error(coreutils.prepare_html_str(err_msg))
Ejemplo n.º 6
0
 def log_parse_except(self, parsed_file, parse_ex):
     err_msg = '<strong>Error while parsing file:</strong>\n{file}\n' \
               '<strong>Error type:</strong> {type}\n' \
               '<strong>Error Message:</strong> {errmsg}\n' \
               '<strong>Line/Column:</strong> {lineno}/{colno}\n' \
               '<strong>Line Text:</strong> {linetext}' \
               .format(file=parsed_file,
                       type=parse_ex.__class__.__name__,
                       errmsg=parse_ex.msg if hasattr(parse_ex, 'msg') else "",
                       lineno=parse_ex.lineno if hasattr(parse_ex, 'lineno') else 0,
                       colno=parse_ex.offset if hasattr(parse_ex, 'offset') else 0,
                       linetext=parse_ex.text if hasattr(parse_ex, 'text') else "",
                       )
     self.error(coreutils.prepare_html_str(err_msg))
Ejemplo n.º 7
0
    def print_code(code_str):
        nbsp = '&nbsp;'
        code_div = '<div style="font-family:courier new;' \
                   'border-style: solid;' \
                   'border-width:0 0 0 5;' \
                   'border-color:#87b012;' \
                   'background:#ececec;' \
                   'color:#3e3d3d;' \
                   'line-height: 150%;' \
                   'padding:10;' \
                   'margin:10 0 10 0">' \
                   '{}' \
                   '</div>'

        print(prepare_html_str(code_div.format(code_str.replace('    ', nbsp*4))), end="")
Ejemplo n.º 8
0
    def _log(self, level, msg, args, exc_info=None, extra=None):
        # any report other than logging.INFO level reports, need to cleanup < and > character to avoid html conflict
        self._has_errors = (self._has_errors or level >= logging.ERROR)

        if not isinstance(msg, str):
            msg_str = unicode(msg)
        else:
            msg_str = msg
        # get rid of unicode characters
        msg_str = msg_str.encode('ascii', 'ignore')
        msg_str = msg_str.replace(os.path.sep, '/')
        msg_str = emojize(msg_str)
        if level == logging.INFO:
            msg_str = prepare_html_str(msg_str)
        logging.Logger._log(self, level, msg_str, args, exc_info=None, extra=None)
Ejemplo n.º 9
0
    def linkify(element_ids, title=None):
        """Create clickable link for the provided element ids.

        This method, creates the link but does not print it directly.

        Args:
            element_ids (`ElementId`) or
            element_ids (:obj:`list` of `ElementId`): single or multiple ids
            title (str): tile of the link. defaults to list of element ids

        Example:
            >>> output = pyrevit.output.get_output()
            >>> for idx, elid in enumerate(element_ids):
            >>>     print('{}: {}'.format(idx+1, output.linkify(elid)))
        """
        return coreutils.prepare_html_str(
            linkmaker.make_link(element_ids, contents=title))
Ejemplo n.º 10
0
 def print_md(md_str):
     tables_ext = 'pyrevit.coreutils.console.markdown.extensions.tables'
     markdown_html = markdown.markdown(md_str, extensions=[tables_ext])
     markdown_html = markdown_html.replace('\n', '').replace('\r', '')
     html_code = emojize(prepare_html_str(markdown_html))
     print(html_code, end="")
Ejemplo n.º 11
0
import sys
import os.path
import logging

from pyrevit import PYREVIT_ADDON_NAME, EXEC_PARAMS
from pyrevit import PYREVIT_VERSION_APP_DIR, PYREVIT_FILE_PREFIX_STAMPED
from pyrevit.coreutils import prepare_html_str
from pyrevit.coreutils import envvars
from pyrevit.coreutils.emoji import emojize

LOG_REC_FORMAT = "%(levelname)s: [%(name)s] %(message)s"
LOG_REC_FORMAT_FILE = "%(asctime)s %(levelname)s: [%(name)s] %(message)s"
LOG_REC_FORMAT_FILE_C = "%(asctime)s %(levelname)s: [<{}> %(name)s] %(message)s"

LOG_REC_FORMAT_HTML = prepare_html_str('<div class="logdefault {0}">{1}</div>')

LOG_REC_CLASS_ERROR = 'logerror'
LOG_REC_FORMAT_ERROR = LOG_REC_FORMAT_HTML.format(LOG_REC_CLASS_ERROR,
                                                  LOG_REC_FORMAT)

LOG_REC_CLASS_WARNING = 'logwarning'
LOG_REC_FORMAT_WARNING = LOG_REC_FORMAT_HTML.format(LOG_REC_CLASS_WARNING,
                                                    LOG_REC_FORMAT)

LOG_REC_CLASS_CRITICAL = 'logcritical'
LOG_REC_FORMAT_CRITICAL = LOG_REC_FORMAT_HTML.format(LOG_REC_CLASS_CRITICAL,
                                                     LOG_REC_FORMAT)

# Setting default global logging level
DEFAULT_LOGGING_LEVEL = logging.WARNING
Ejemplo n.º 12
0
 def linkify(*args):
     return prepare_html_str(rvtprotocol.make_url(args))
Ejemplo n.º 13
0
 def print_md(md_str):
     from pyrevit.coreutils.console import markdown
     print(prepare_html_str(markdown.markdown(md_str)), end="")
Ejemplo n.º 14
0
 def print_html(html_str):
     print(prepare_html_str(html_str), end="")
Ejemplo n.º 15
0
def dashboardLeftMaker(value):
    """dashboard HTMl maker - div for left aligning"""
    content = str(value)
    html_code = "<div class='dashboardLeft'>" + content + "</div>"
    print(coreutils.prepare_html_str(html_code))
Ejemplo n.º 16
0
import os.path as op
import re

from pyrevit.coreutils import prepare_html_str
from pyrevit.coreutils.emoji.unicodes import emoji_file_dict

HTML_EMOJI_SPAN = prepare_html_str('<span><img src="{}" class="emoji"></span>')


def emojize(text):
    pattern = re.compile(':([a-z0-9+-_]+):')

    def emojifier(match):
        emoji_name = match.group(1)
        if emoji_name in emoji_file_dict:
            emoji_name = emoji_file_dict[emoji_name]
            return HTML_EMOJI_SPAN.format(
                op.join(op.dirname(__file__), 'png',
                        '{}.png'.format(emoji_name)))
        else:
            return ':{}:'.format(emoji_name)

    return pattern.sub(emojifier, text)
Ejemplo n.º 17
0
import os.path as op
import re

from pyrevit.coreutils import prepare_html_str
from pyrevit.coreutils.console.emoji.code import emoji_file_dict

HTML_EMOJI_SPAN = prepare_html_str(
    '<span><img src="{}" style="vertical-align:middle;margin:-4px 0px -4px 0px;"></span>'
)


def emojize(text):
    pattern = re.compile(':([a-z0-9+-_]+):')

    def emojifier(match):
        emoji_name = match.group(1)
        if emoji_name in emoji_file_dict:
            emoji_name = emoji_file_dict[emoji_name]

        return HTML_EMOJI_SPAN.format(
            op.join(op.dirname(__file__), 'png', '{}.png'.format(emoji_name)))

    return pattern.sub(emojifier, text)
Ejemplo n.º 18
0
from pyrevit import PYREVIT_ADDON_NAME, EXEC_PARAMS
from pyrevit import PYREVIT_VERSION_APP_DIR, PYREVIT_FILE_PREFIX_STAMPED
from pyrevit.coreutils import prepare_html_str
from pyrevit.coreutils.console.emoji import emojize
from pyrevit.coreutils.envvars import set_pyrevit_env_var, get_pyrevit_env_var

DEBUG_ISC_NAME = PYREVIT_ADDON_NAME + '_debugISC'
VERBOSE_ISC_NAME = PYREVIT_ADDON_NAME + '_verboseISC'

RUNTIME_LOGGING_LEVEL = logging.WARNING
RUNTIME_FILE_LOGGING_LEVEL = logging.DEBUG

LOG_REC_FORMAT = "%(levelname)s: [%(name)s] %(message)s"

LOG_REC_FORMAT_HTML = prepare_html_str('<div style="{0}">{1}</div>')
LOG_REC_FORMAT_ERROR = LOG_REC_FORMAT_HTML.format('background:#f9f2f4;color:#c7254e;'
                                                  'padding:10px;margin:10px 0px 10px 0px', LOG_REC_FORMAT)
LOG_REC_FORMAT_WARNING = LOG_REC_FORMAT_HTML.format('background:#F7F3F2;color:#C64325;'
                                                    'padding:10px;margin:10px 0px 10px 0px', LOG_REC_FORMAT)
LOG_REC_FORMAT_CRITICAL = LOG_REC_FORMAT_HTML.format('background:#c7254e;color:white;'
                                                     'padding:10px;margin:10px 0px 10px 0px', LOG_REC_FORMAT)


if EXEC_PARAMS.command_mode:
    FILE_LOG_REC_FORMAT = "%(asctime)s %(levelname)s: [<{}> %(name)s] %(message)s".format(EXEC_PARAMS.command_name)
else:
    FILE_LOG_REC_FORMAT = "%(asctime)s %(levelname)s: [%(name)s] %(message)s"

FILE_LOG_FILENAME = '{}.log'.format(PYREVIT_FILE_PREFIX_STAMPED)
FILE_LOG_FILEPATH = os.path.join(PYREVIT_VERSION_APP_DIR, FILE_LOG_FILENAME)
Ejemplo n.º 19
0
 def print_html(html_str):
     print(prepare_html_str(emojize(html_str)), end="")
Ejemplo n.º 20
0
for i in content:
    portions = re.split(";", i)
    date = portions[0]
    time = portions[1]
    rawId = portions[2]
    rawModel = portions[3]
    comment = portions[4]
    username = portions[5]
    grouping = portions[6]
    id = re.split(':', rawId)[2]
    model = re.split(':', rawModel)[2]
    # print line info
    if name == model[0:len(model) - 1]:
        if grouping != lastId:
            if len(allId) > 1:
                good = coreutils.prepare_html_str(
                    linkmaker.make_link(allId, contents='GROUP SELECT'))
                print('Select all ' + str(len(allId)) + ' elements   ' + good +
                      ' Group ID: ' + str(grouping))
                print('---------------------------------------')
                # print ('GROUP ' + str(num) + '---------------------------------------')
                num += 1
                allId = []
            else:
                print('---------------------------------------')
                allId = []
        element = doc.GetElement(ElementId(int(id[0:len(id) - 1])))
        try:
            currentid = format(outprint.linkify(element.Id))
        except:
            currentid = id[0:len(id) - 1]
        print(date + '  ' + time + '    ' + 'User: '******'      ' +
Ejemplo n.º 21
0
"""Core logging module for pyRevit."""
import sys
import os.path as op
import logging

#pylint: disable=W0703,C0302,C0103
from pyrevit import EXEC_PARAMS, USER_DESKTOP
from pyrevit.compat import safe_strtype
from pyrevit import PYREVIT_VERSION_APP_DIR, PYREVIT_FILE_PREFIX_STAMPED
from pyrevit import coreutils
from pyrevit.coreutils import envvars

LOG_REC_FORMAT = "%(levelname)s [%(name)s] %(message)s"
LOG_REC_FORMAT_HEADER = \
    coreutils.prepare_html_str(
        "<strong>%(levelname)s</strong> [%(name)s] %(message)s"
        )
LOG_REC_FORMAT_HEADER_NO_NAME = \
    coreutils.prepare_html_str(
        "<strong>%(levelname)s</strong>\n%(message)s"
        )
LOG_REC_FORMAT_EMOJI = "{emoji} %(levelname)s [%(name)s] %(message)s"
LOG_REC_FORMAT_FILE = "%(asctime)s %(levelname)s [%(name)s] %(message)s"
LOG_REC_FORMAT_FILE_C = "%(asctime)s %(levelname)s [<{}> %(name)s] %(message)s"

LOG_REC_FORMAT_HTML = \
    coreutils.prepare_html_str('<div class="logdefault {style}">{message}</div>')

LOG_REC_CLASS_ERROR = 'logerror'
LOG_REC_FORMAT_ERROR = \
    LOG_REC_FORMAT_HTML.format(style=LOG_REC_CLASS_ERROR,