Skip to content

Commit

Permalink
Logging (DQC): examine message parameters for fact
Browse files Browse the repository at this point in the history
arguments which can be obtained from modelObjects and
if so add them to format arguments of logger
  • Loading branch information
hefischer committed Jul 1, 2015
1 parent 30fa1f5 commit fa3b1f5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
6 changes: 5 additions & 1 deletion arelle/ModelXbrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ def propValues(properties):
# determine message and extra arguments
fmtArgs = {}
extras = {"messageCode":messageCode}
modelObjectArgs = ()

for argName, argValue in codedArgs.items():
if argName in ("modelObject", "modelXbrl", "modelDocument"):
Expand All @@ -927,7 +928,8 @@ def propValues(properties):
except AttributeError:
entryUrl = self.fileSource.url
refs = []
for arg in (argValue if isinstance(argValue, (tuple,list,set)) else (argValue,)):
modelObjectArgs = argValue if isinstance(argValue, (tuple,list,set)) else (argValue,)
for arg in modelObjectArgs:
if arg is not None:
if isinstance(arg, _STR_BASE):
objectUrl = arg
Expand Down Expand Up @@ -1021,6 +1023,8 @@ def propValues(properties):
except:
file = ""
extras["refs"] = [{"href": file}]
for pluginXbrlMethod in pluginClassMethods("Logging.Message.Parameters"):
pluginXbrlMethod(messageCode, msg, modelObjectArgs, fmtArgs)
return (messageCode,
(msg, fmtArgs) if fmtArgs else (msg,),
extras)
Expand Down
54 changes: 54 additions & 0 deletions arelle/plugin/logging/dqcParameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'''
Created on Dec 12, 2013
@author: Mark V Systems Limited
(c) Copyright 2013 Mark V Systems Limited, All rights reserved.
'''
from arelle.ModelDtsObject import ModelConcept
from arelle.ModelInstanceObject import ModelFact
from arelle.XmlUtil import xmlstring
import re
from collections import defaultDict

parametersPattern = re.compile(r"%\(([\w.]+)\)")
factNumberPattern = re.compile(r"fact(\n+)")

def loggingMessageParameters(messageCode, msg, modelObjectArgs, fmtArgs):
factsArray = []
factsByQname = defaultDict(list) # list of facts with the qname
for arg in modelObjectArgs:
# arg may be a ModelFact, or any other ModelObject
if isinstance(arg, ModelFact):
factArray.append(arg)
factsByQname[str(fact.qname)].append(arg)

# parse parameter names out of msg
for param in parametersPattern.findall(msg):
try:
paramParts = param.split('.')
if len(paramParts) > 2 and factNumberPattern.match(parmParts[0]):
modelFactNum = int(factNumberPattern.match(parmParts[0]).group(1))
if modelFactNum < len(factsArray):
modelFact = factsArray[modelFactNum]
if paramParts[2] == "value":
fmtArgs[param] = modelFact.value
elif len(paramParts) > 2 and paramParts[2] == "fact":
# take first matching fact ??
if paramParts[0] in factsByQname:
modelFact = factsByQname[paramParts[0]]
if paramParts[3] == "value":
fmtArgs[param] = modelFact.value

__pluginInfo__ = {
# Do not use _( ) in pluginInfo itself (it is applied later, after loading
'name': 'Logging - DQC Parameters',
'version': '1.0',
'description': '''DQC tests logging messages: adds parameter values from infrastructurally
provided logging arguments. Usually uses modelObject arguments to supply parameters found
in message text that can be derived from the arguments.''',
'license': 'Apache-2',
'author': 'Mark V Systems',
'copyright': '(c) Copyright 2014 Mark V Systems Limited, All rights reserved.',
# classes of mount points (required)
'Logging.Message.Parameters': loggingMessageParameters
}

0 comments on commit fa3b1f5

Please sign in to comment.