Beispiel #1
0
def errprint(msg):
    from utils import cstr

    if not request_method:
        print cstr(msg)

    error_log.append(cstr(msg))
Beispiel #2
0
def errprint(msg):
	"""Log error. This is sent back as `exc` in response.

	:param msg: Message."""
	from utils import cstr
	if not request or (not "cmd" in local.form_dict):
		print cstr(msg)

	error_log.append(cstr(msg))
Beispiel #3
0
def errprint(msg):
    """Log error. This is sent back as `exc` in response.

	:param msg: Message."""
    from utils import cstr
    if not request or (not "cmd" in local.form_dict):
        print cstr(msg)

    error_log.append(cstr(msg))
Beispiel #4
0
def msgprint(msg, small=0, raise_exception=0, as_table=False):
    def _raise_exception():
        if raise_exception:
            if rollback_on_exception:
                conn.rollback()
            import inspect

            if inspect.isclass(raise_exception) and issubclass(raise_exception, Exception):
                raise raise_exception, msg
            else:
                raise ValidationError, msg

    if mute_messages:
        _raise_exception()
        return

    from utils import cstr

    if as_table and type(msg) in (list, tuple):
        msg = (
            '<table border="1px" style="border-collapse: collapse" cellpadding="2px">'
            + "".join(["<tr>" + "".join(["<td>%s</td>" % c for c in r]) + "</tr>" for r in msg])
            + "</table>"
        )

    if print_messages:
        print "Message: " + repr(msg)

    message_log.append((small and "__small:" or "") + cstr(msg or ""))
    _raise_exception()
Beispiel #5
0
def errprint(msg):
    """
	   Append to the :data:`debug log`
	"""
    from utils import cstr

    debug_log.append(cstr(msg or ""))
Beispiel #6
0
def log(msg):
	if not request:
		if conf.get("logging") or False:
			print repr(msg)

	from utils import cstr
	debug_log.append(cstr(msg))
Beispiel #7
0
def log(msg):
    if not request:
        if conf.get("logging") or False:
            print repr(msg)

    from utils import cstr
    debug_log.append(cstr(msg))
Beispiel #8
0
def msgprint(msg, small=0, raise_exception=0, as_table=False):
    def _raise_exception():
        if raise_exception:
            if flags.rollback_on_exception:
                db.rollback()
            import inspect
            if inspect.isclass(raise_exception) and issubclass(
                    raise_exception, Exception):
                raise raise_exception, msg
            else:
                raise ValidationError, msg

    if flags.mute_messages:
        _raise_exception()
        return

    from utils import cstr
    if as_table and type(msg) in (list, tuple):
        msg = '<table border="1px" style="border-collapse: collapse" cellpadding="2px">' + ''.join(
            [
                '<tr>' + ''.join(['<td>%s</td>' % c for c in r]) + '</tr>'
                for r in msg
            ]) + '</table>'

    if flags.print_messages:
        print "Message: " + repr(msg)

    message_log.append((small and '__small:' or '') + cstr(msg or ''))
    _raise_exception()
Beispiel #9
0
def msgprint(msg, small=0, raise_exception=0, as_table=False):
	"""Print a message to the user (via HTTP response).
	Messages are sent in the `__server_messages` property in the
	response JSON and shown in a pop-up / modal.

	:param msg: Message.
	:param small: [optional] Show as a floating message in the footer.
	:param raise_exception: [optional] Raise given exception and show message.
	:param as_table: [optional] If `msg` is a list of lists, render as HTML table.
	"""
	from utils import cstr, encode

	def _raise_exception():
		if raise_exception:
			if flags.rollback_on_exception:
				db.rollback()
			import inspect
			if inspect.isclass(raise_exception) and issubclass(raise_exception, Exception):
				raise raise_exception, encode(msg)
			else:
				raise ValidationError, encode(msg)

	if flags.mute_messages:
		_raise_exception()
		return

	if as_table and type(msg) in (list, tuple):
		msg = '<table border="1px" style="border-collapse: collapse" cellpadding="2px">' + ''.join(['<tr>'+''.join(['<td>%s</td>' % c for c in r])+'</tr>' for r in msg]) + '</table>'

	if flags.print_messages:
		print "Message: " + repr(msg).encode("utf-8")

	message_log.append((small and '__small:' or '')+cstr(msg or ''))
	_raise_exception()
Beispiel #10
0
def msgprint(msg, small=0, raise_exception=0, as_table=False):
	"""Print a message to the user (via HTTP response).
	Messages are sent in the `__server_messages` property in the
	response JSON and shown in a pop-up / modal.

	:param msg: Message.
	:param small: [optional] Show as a floating message in the footer.
	:param raise_exception: [optional] Raise given exception and show message.
	:param as_table: [optional] If `msg` is a list of lists, render as HTML table.
	"""
	from utils import cstr, encode

	def _raise_exception():
		if raise_exception:
			if flags.rollback_on_exception:
				db.rollback()
			import inspect
			if inspect.isclass(raise_exception) and issubclass(raise_exception, Exception):
				raise raise_exception, encode(msg)
			else:
				raise ValidationError, encode(msg)

	if flags.mute_messages:
		_raise_exception()
		return

	if as_table and type(msg) in (list, tuple):
		msg = '<table border="1px" style="border-collapse: collapse" cellpadding="2px">' + ''.join(['<tr>'+''.join(['<td>%s</td>' % c for c in r])+'</tr>' for r in msg]) + '</table>'

	if flags.print_messages:
		print "Message: " + repr(msg).encode("utf-8")

	message_log.append((small and '__small:' or '')+cstr(msg or ''))
	_raise_exception()
Beispiel #11
0
def log(msg):
	if not request_method:
		import conf
		if getattr(conf, "logging", False):
			print repr(msg)
	
	from utils import cstr
	debug_log.append(cstr(msg))
Beispiel #12
0
def log(msg):
	if not request_method:
		import conf
		if getattr(conf, "logging", False):
			print repr(msg)
	
	from utils import cstr
	debug_log.append(cstr(msg))
Beispiel #13
0
def read_file(path, raise_not_found=False):
	from frappe.utils import cstr
	if os.path.exists(path):
		with open(path, "r") as f:
			return cstr(f.read())
	elif raise_not_found:
		raise IOError("{} Not Found".format(path))
	else:
		return None
Beispiel #14
0
def read_file(path, raise_not_found=False):
    from frappe.utils import cstr
    if os.path.exists(path):
        with open(path, "r") as f:
            return cstr(f.read())
    elif raise_not_found:
        raise IOError("{} Not Found".format(path))
    else:
        return None
Beispiel #15
0
def log(msg):
	"""Add to `debug_log`.

	:param msg: Message."""
	if not request:
		if conf.get("logging") or False:
			print repr(msg)

	from utils import cstr
	debug_log.append(cstr(msg))
Beispiel #16
0
def log(msg):
    """Add to `debug_log`.

	:param msg: Message."""
    if not request:
        if conf.get("logging") or False:
            print repr(msg)

    from utils import cstr
    debug_log.append(cstr(msg))
Beispiel #17
0
 def log(self, tag, **kargs):
     # if self.coinbase != 0: return
     t = int(self.env.now)
     c = lambda x: cstr(self.coinbase, x)
     msg = ' '.join(
         [str(t),
          c(repr(self)), tag, (' %r' % kargs if kargs else '')])
     if self.stopped:
         msg = 'X' + msg
     print msg
Beispiel #18
0
def read_file(path, raise_not_found=False):
	"""Open a file and return its content as Unicode."""
	from frappe.utils import cstr
	if os.path.exists(path):
		with open(path, "r") as f:
			return cstr(f.read())
	elif raise_not_found:
		raise IOError("{} Not Found".format(path))
	else:
		return None
Beispiel #19
0
def read_file(path, raise_not_found=False):
    """Open a file and return its content as Unicode."""
    from frappe.utils import cstr
    if os.path.exists(path):
        with open(path, "r") as f:
            return cstr(f.read())
    elif raise_not_found:
        raise IOError("{} Not Found".format(path))
    else:
        return None
Beispiel #20
0
def msgprint(msg, small=0, raise_exception=0, as_table=False):
	"""
	   Append to the :data:`message_log`
	"""	
	from utils import cstr
	if as_table and type(msg) in (list, tuple):
		msg = '<table border="1px" style="border-collapse: collapse" cellpadding="2px">' + ''.join(['<tr>'+''.join(['<td>%s</td>' % c for c in r])+'</tr>' for r in msg]) + '</table>'
	
	message_log.append((small and '__small:' or '')+cstr(msg or ''))
	if raise_exception:
		raise ValidationError, msg
Beispiel #21
0
def msgprint(msg, small=0, raise_exception=0, as_table=False):
	from utils import cstr
	if as_table and type(msg) in (list, tuple):
		msg = '<table border="1px" style="border-collapse: collapse" cellpadding="2px">' + ''.join(['<tr>'+''.join(['<td>%s</td>' % c for c in r])+'</tr>' for r in msg]) + '</table>'
	
	if print_messages:
		print "Message: " + repr(msg)
	
	message_log.append((small and '__small:' or '')+cstr(msg or ''))
	if raise_exception:
		import inspect
		if inspect.isclass(raise_exception) and issubclass(raise_exception, Exception):
			raise raise_exception, msg
		else:
			raise ValidationError, msg
Beispiel #22
0
def msgprint(msg, small=0, raise_exception=0, as_table=False):
    """
	   Append to the :data:`message_log`
	"""
    from utils import cstr

    if as_table and type(msg) in (list, tuple):
        msg = (
            '<table border="1px" style="border-collapse: collapse" cellpadding="2px">'
            + "".join(["<tr>" + "".join(["<td>%s</td>" % c for c in r]) + "</tr>" for r in msg])
            + "</table>"
        )

    message_log.append((small and "__small:" or "") + cstr(msg or ""))
    if raise_exception:
        raise ValidationError, msg
Beispiel #23
0
def msgprint(msg, small=0, raise_exception=0, as_table=False):
    """
	   Append to the :data:`message_log`
	"""
    from utils import cstr
    if as_table and type(msg) in (list, tuple):
        msg = '<table border="1px" style="border-collapse: collapse" cellpadding="2px">' + ''.join(
            [
                '<tr>' + ''.join(['<td>%s</td>' % c for c in r]) + '</tr>'
                for r in msg
            ]) + '</table>'

    message_log.append((small and '__small:' or '') + cstr(msg or ''))
    if raise_exception:
        import inspect
        if inspect.isclass(raise_exception) and issubclass(
                raise_exception, Exception):
            raise raise_exception, msg
        else:
            raise ValidationError, msg
Beispiel #24
0
    def str_tree(self,
                 str_fn=lambda n: 'o',
                 selected_child=None,
                 all_children_new_line=False,
                 max_depth=None):
        str_root = str_fn(self)
        node_characters = len(str_root)
        lines = [" " + str_root]
        if all_children_new_line:
            lines.append("")  # start a new line
        q = list(reversed(self.children))
        depth_nodes = [len(self.children)]
        print_blue = False
        while q:
            n = q.pop()

            if selected_child is not None and n.depth == 1:
                print_blue = n is selected_child

            if len(lines[-1]) == 0:  # new branch
                for i, d in enumerate(depth_nodes):
                    if all_children_new_line:
                        lines[-1] += " "
                    else:
                        lines[-1] += " " * (node_characters + 1)

                    if i == len(depth_nodes) - 1:  # last one
                        assert d != 0
                        if d == 1:
                            lines[-1] += '\u2570'  # L
                        else:
                            lines[-1] += '\u251c'  # |-
                    else:
                        if d == 0:
                            lines[-1] += ' '
                        else:
                            lines[-1] += '\u2502'  # |
            else:  # same branch, this is never the case with all_children_new_line=True
                if depth_nodes[-1] == 1:
                    lines[-1] += '\u2500'  # --
                else:
                    lines[-1] += '\u252c'  # T

            str_node = str_fn(n)
            if not all_children_new_line:
                assert len(str_node) == len(
                    str_root
                ), "Use all_children_new_line for str_node of variable size."
            lines[-1] += '\u2500' + str_node  # remove '--' for shorter tree
            depth_nodes[-1] -= 1
            assert depth_nodes[-1] >= 0

            if n.children and (max_depth is None or n.depth < max_depth + 1):
                # continue branch with first children
                q.extend(reversed(n.children)
                         )  # add them reversed, since it's a stack (LIFO)
                depth_nodes.append(len(n.children))
                if all_children_new_line:
                    lines.append("")  # start a new line
            else:
                # end branch
                if print_blue:
                    lines[-1] = lines[-1][:3] + cstr(
                        lines[-1][3:],
                        'blue')  # TODO: this 3 should be dependant on str_node
                lines.append("")

            # shrink depth list to the current depth
            while depth_nodes and depth_nodes[-1] == 0:
                depth_nodes.pop()

        return "\n".join(lines)
Beispiel #25
0
def errprint(msg):
	if not request_method:
		print repr(msg)

	from utils import cstr
	debug_log.append(cstr(msg or ''))
Beispiel #26
0
def errprint(msg):
    if not request_method:
        print repr(msg)

    from utils import cstr
    debug_log.append(cstr(msg or ''))
Beispiel #27
0
def errprint(msg):
	from utils import cstr
	if not request or (not "cmd" in local.form_dict):
		print cstr(msg)

	error_log.append(cstr(msg))
Beispiel #28
0
def errprint(msg):
    from utils import cstr
    if not request:
        print cstr(msg)

    error_log.append(cstr(msg))
Beispiel #29
0
def errprint(msg):
    """
	   Append to the :data:`debug log`
	"""
    from utils import cstr
    debug_log.append(cstr(msg or ''))
Beispiel #30
0
def errprint(msg):
    from utils import cstr
    if not request or (not "cmd" in local.form_dict):
        print cstr(msg)

    error_log.append(cstr(msg))