Commit 94fc3cad authored by Etienne Nadji's avatar Etienne Nadji
Browse files

Log support

	modifié :         pyscribus/common/xml.py
	modifié :         pyscribus/dimensions.py
	modifié :         pyscribus/logs.py
	modifié :         pyscribus/pageobjects.py
	modifié :         pyscribus/pages.py
	modifié :         pyscribus/styles.py
parent 60816542
......@@ -25,9 +25,8 @@ Most of them are annoyingly simple, but necessary.
# Imports ===============================================================#
import pprint
import copy
import pprint
import lxml
import lxml.etree as ET
......@@ -431,7 +430,7 @@ def all_undocumented_to_python(xml: ET._Element):
def all_undocumented_to_xml(
xml: ET._Element, undocumented: dict,
report: bool = True, msg: str = "", passattr: list = []):
report: bool = True, msg: str = "", passattr: list = [], logger=False):
"""
Function to manage the export of undocumented
XML/SLA attributes.
......@@ -451,6 +450,9 @@ def all_undocumented_to_xml(
is True.
:type passattr: list
:param passattr: List of SLA attributes names to not report. For debug.
:type logger: logging.Logger, bool
:param logger: Logger object to use if report. If False, report is printed
in STDOUT.
:returns: List containing LXML element and undocumented attributes
names list.
:rtype: list
......@@ -472,8 +474,19 @@ def all_undocumented_to_xml(
undoc_attribs.append(att_name)
if report and undoc_attribs:
print("Undocumented XML attributes in {} :".format(msg.strip()))
pprint.pprint(undoc_attribs, width=80, compact=True)
msg = msg.strip()
undocstr = "Undoc. XML attributes in {} : ".format(msg)
if logger:
logger.debug(
undocstr + pprint.pformat(undoc_attribs, compact=True)
)
else:
print(undocstr)
pprint.pprint(undoc_attribs, width=80, compact=True)
return [xml, undoc_attribs]
......
......@@ -26,6 +26,7 @@ import math
from pyscribus.common.math import PICA_TO_MM,INCH_TO_MM
import pyscribus.logs as logs
import pyscribus.exceptions as exceptions
import pyscribus.papers.ansi as ansipaper
......@@ -1007,9 +1008,18 @@ class DimBox:
# XML, only original box coords and rotation angle value
# are saved.
# FIXME Remove that after implementation
print("PyScribus - Box rotation not implemented.")
# print("Rotation degree :", degree)
# FIXME Remove that after implementation -------
logger=logs.getLogger()
if logger:
logger.debug("Box rotation not implemented.")
# logger.debug("Rotation degree : {}".format(degree))
else:
print("PyScribus - Box rotation not implemented.")
# print("Rotation degree :", degree)
# ----------------------------------------------
valid = True
......
......@@ -23,58 +23,40 @@ Logging for PyScribus
# Imports ===============================================================#
import os
import logging
# Variables globales ====================================================#
__author__ = "Etienne Nadji <etnadji@eml.cc>"
# Classes ===============================================================#
USE_LOG = False
class Logger(logging.Logger):
# Fonctions =============================================================#
def __init__(self):
super().__init__()
def init_logging(
filepath="test.log",
formatstr="%(asctime)s:%(levelname)s:%(message)s"):
global USE_LOG
self.sub_levels = {
"omitting_pageobjects": logging.INFO
}
logger = getLogger()
def setLevel(self, level):
logging.Logger.setLevel(level)
filepath = os.path.realpath(filepath)
for k in self.sub_levels.keys():
self.sub_levels[k] = level
logging.basicConfig(
filename=filepath,
level=logging.DEBUG,
format=formatstr
)
def setSubLevel(self, sublevel, level):
self.sub_levels[sublevel] = level
USE_LOG = True
def _valid_level(self, la_name, lb):
if self.sub_levels[la_name] >= lb:
return True
else:
return False
def getLogger():
global USE_LOG
def debug(self, msg, *args, **kwargs):
if "logsublevel" in kwargs:
if self._valid_level(kwargs["logsublevel"], logging.DEBUG):
logging.Logger.debug(msg, args, kwargs)
else:
logging.Logger.debug(msg, args, kwargs)
def info(self, msg, *args, **kwargs):
pass
def warning(self, msg, *args, **kwargs):
pass
def error(self, msg, *args, **kwargs):
pass
def critical(self, msg, *args, **kwargs):
pass
if USE_LOG:
return logging.getLogger('pyscribus')
else:
return False
# vim:set shiftwidth=4 softtabstop=4 spl=en:
......@@ -32,6 +32,7 @@ import lxml.etree as ET
import svg.path as svg
import pyscribus.common.xml as xmlc
import pyscribus.logs as logs
import pyscribus.exceptions as exceptions
import pyscribus.dimensions as dimensions
import pyscribus.itemattribute as itemattribute
......@@ -694,6 +695,7 @@ class PageObject(xmlc.PyScribusElement):
self.ptype + " frame '" + self.name + "'",
# FIXME This disable debug for path, copath attributes
# ["path", "copath"]
logger=logs.getLogger()
)
except AttributeError:
......@@ -1255,7 +1257,8 @@ class TableObject(PageObject):
try:
xml, undoc_attribs = xmlc.all_undocumented_to_xml(
xml, self.undocumented, True,
self.ptype + " frame '" + self.name + "'"
self.ptype + " frame '" + self.name + "'",
logger=logs.getLogger()
)
except AttributeError:
......@@ -1446,7 +1449,8 @@ class GroupObject(PageObject):
try:
xml, undoc_attribs = xmlc.all_undocumented_to_xml(
xml, self.undocumented, True,
self.ptype + " frame '" + self.name + "'"
self.ptype + " frame '" + self.name + "'",
logger=logs.getLogger()
)
except AttributeError:
......@@ -1796,7 +1800,8 @@ class TextObject(PageObject):
try:
xml, undoc_attribs = xmlc.all_undocumented_to_xml(
xml, self.undocumented, True,
self.ptype + " frame '" + self.name + "'"
self.ptype + " frame '" + self.name + "'",
logger=logs.getLogger()
)
except AttributeError:
......
......@@ -32,6 +32,7 @@ Classes for SLA Pages / Master pages.
import lxml
import lxml.etree as ET
import pyscribus.logs as logs
import pyscribus.exceptions as exceptions
import pyscribus.dimensions as dimensions
......@@ -534,7 +535,8 @@ class PageAbstract(PyScribusElement):
try:
# xml = undocumented_to_xml(xml, self.undocumented)
xml, undoc_attribs = all_undocumented_to_xml(
xml, self.undocumented, True, tag
xml, self.undocumented, True, tag,
logger=logs.getLogger()
)
except AttributeError:
......
......@@ -27,6 +27,7 @@ import lxml
import lxml.etree as ET
import pyscribus.common.xml as xmlc
import pyscribus.logs as logs
import pyscribus.exceptions as exceptions
import pyscribus.dimensions as dimensions
......@@ -548,7 +549,8 @@ class StyleAbstract(xmlc.PyScribusElement):
if self.style_type not in ["paragraph", "character"]:
xml, undoc_attribs = xmlc.all_undocumented_to_xml(
xml, self.undocumented, True,
self.style_type + " style " + self.name
self.style_type + " style " + self.name,
logger=logs.getLogger()
)
except AttributeError:
......@@ -828,7 +830,8 @@ class ParagraphStyle(StyleAbstract):
try:
xml, undoc_attribs = xmlc.all_undocumented_to_xml(
xml, self.undocumented, True,
self.style_type + " style " + self.name
self.style_type + " style " + self.name,
logger=logs.getLogger()
)
except AttributeError:
......@@ -995,7 +998,8 @@ class CharacterStyle(StyleAbstract):
try:
xml, undoc_attribs = xmlc.all_undocumented_to_xml(
xml, self.undocumented, True,
self.style_type + " style " + self.name
self.style_type + " style " + self.name,
logger=logs.getLogger()
)
except AttributeError:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment