Esempio n. 1
0
 def run(self, options):
     self.filename = options.filename
     filesource = FileSource.openFileSource(self.filename,self)
     if options.validateEFM:
         if options.gfmName:
             self.addToLog(_("both --efm and --gfm validation are requested, proceeding with --efm only"),
                           messageCode="info", file=self.filename)
         self.modelManager.validateDisclosureSystem = True
         self.modelManager.disclosureSystem.select("efm")
     elif options.gfmName:
         self.modelManager.validateDisclosureSystem = True
         self.modelManager.disclosureSystem.select(options.gfmName)
     else:
         self.modelManager.disclosureSystem.select(None) # just load ordinary mappings
     if options.calcDecimals:
         if options.calcPrecision:
             self.addToLog(_("both --calcDecimals and --calcPrecision validation are requested, proceeding with --calcDecimals only"),
                           messageCode="info", file=self.filename)
         self.modelManager.validateInferDecimals = True
         self.modelManager.validateCalcLB = True
     elif options.calcPrecision:
         self.modelManager.validateInferDecimals = False
         self.modelManager.validateCalcLB = True
     if options.utrValidate:
         self.modelManager.validateUtr = True
     fo = FormulaOptions()
     if options.formulaParamExprResult:
         fo.traceParameterExpressionResult = True
     if options.formulaParamInputValue:
         fo.traceParameterInputValue = True
     if options.formulaCallExprSource:
         fo.traceCallExpressionSource = True
     if options.formulaCallExprCode:
         fo.traceCallExpressionCode = True
     if options.formulaCallExprEval:
         fo.traceCallExpressionEvaluation = True
     if options.formulaCallExprResult:
         fo.traceCallExpressionResult = True
     if options.formulaVarSetExprEval:
         fo.traceVariableSetExpressionEvaluation = True
     if options.formulaVarSetExprResult:
         fo.traceVariableSetExpressionResult = True
     if options.formulaAsserResultCounts:
         fo.traceAssertionResultCounts = True
     if options.formulaFormulaRules:
         fo.traceFormulaRules = True
     if options.formulaVarsOrder:
         fo.traceVariablesOrder = True
     if options.formulaVarExpressionSource:
         fo.traceVariableExpressionSource = True
     if options.formulaVarExpressionCode:
         fo.traceVariableExpressionCode = True
     if options.formulaVarExpressionEvaluation:
         fo.traceVariableExpressionEvaluation = True
     if options.formulaVarExpressionResult:
         fo.traceVariableExpressionResult = True
     if options.formulaVarFiltersResult:
         fo.traceVariableFiltersResult = True
     self.modelManager.formulaOptions = fo
     timeNow = XmlUtil.dateunionValue(datetime.datetime.now())
     startedAt = time.time()
     modelXbrl = self.modelManager.load(filesource, _("views loading"))
     self.addToLog(format_string(self.modelManager.locale, 
                                 _("loaded in %.2f secs at %s"), 
                                 (time.time() - startedAt, timeNow)), 
                                 messageCode="info", file=self.filename)
     
     if options.diffFilename and options.versReportFilename:
         diffFilesource = FileSource.FileSource(self.diffFilename,self)
         startedAt = time.time()
         modelXbrl = self.modelManager.load(diffFilesource, _("views loading"))
         self.addToLog(format_string(self.modelManager.locale, 
                                     _("diff comparison DTS loaded in %.2f secs"), 
                                     time.time() - startedAt), 
                                     messageCode="info", file=self.filename)
         startedAt = time.time()
         self.modelManager.compareDTSes(options.versReportFilename)
         self.addToLog(format_string(self.modelManager.locale, 
                                     _("compared in %.2f secs"), 
                                     time.time() - startedAt), 
                                     messageCode="info", file=self.filename)
     try:
         if options.validate:
             startedAt = time.time()
             self.modelManager.validate()
             self.addToLog(format_string(self.modelManager.locale, 
                                         _("validated in %.2f secs"), 
                                         time.time() - startedAt),
                                         messageCode="info", file=self.filename)
             if (options.csvTestReport and 
                 self.modelManager.modelXbrl.modelDocument.type in 
                     (ModelDocument.Type.TESTCASESINDEX, 
                      ModelDocument.Type.TESTCASE, 
                      ModelDocument.Type.REGISTRY)):
                 ViewCsvTests.viewTests(self.modelManager.modelXbrl, options.csvTestReport)
             
         if options.csvDTS:
             ViewCsvDTS.viewDTS(modelXbrl, options.csvDTS)
         if options.csvFactList:
             ViewCsvFactList.viewFacts(modelXbrl, options.csvFactList, cols=options.csvFactListCols)
         if options.csvConcepts:
             ViewCsvConcepts.viewConcepts(modelXbrl, options.csvConcepts)
         if options.csvPre:
             ViewCsvRelationshipSet.viewRelationshipSet(modelXbrl, options.csvPre, "Presentation", "http://www.xbrl.org/2003/arcrole/parent-child")
         if options.csvCal:
             ViewCsvRelationshipSet.viewRelationshipSet(modelXbrl, options.csvCal, "Calculation", "http://www.xbrl.org/2003/arcrole/summation-item")
         if options.csvDim:
             ViewCsvRelationshipSet.viewRelationshipSet(modelXbrl, options.csvDim, "Dimension", "XBRL-dimensions")
     except (IOError, EnvironmentError) as err:
         self.addToLog(_("[IOError] Failed to save output:\n {0}").format(err))
     except Exception as err:
         self.addToLog(_("[Exception] Failed to complete validation: \n{0} \n{1}").format(
                     err,
                     traceback.format_tb(sys.exc_info()[2])))
Esempio n. 2
0
    def run(self, options):
        if options.logFile:
            self.messages = []
        else:
            self.messages = None

        self.filename = options.filename
        filesource = FileSource.FileSource(self.filename, self)
        if options.validateEFM:
            if options.gfmName:
                self.addToLog(
                    _("[info] both --efm and --gfm validation are requested, proceeding with --efm only"
                      ))
            self.modelManager.validateDisclosureSystem = True
            self.modelManager.disclosureSystem.select("efm")
        elif options.gfmName:
            self.modelManager.validateDisclosureSystem = True
            self.modelManager.disclosureSystem.select(options.gfmName)
        else:
            self.modelManager.disclosureSystem.select(
                None)  # just load ordinary mappings
        if options.calcDecimals:
            if options.calcPrecision:
                self.addToLog(
                    _("[info] both --calcDecimals and --calcPrecision validation are requested, proceeding with --calcDecimals only"
                      ))
            self.modelManager.validateInferDecimals = True
            self.modelManager.validateCalcLB = True
        elif options.calcPrecision:
            self.modelManager.validateInferDecimals = False
            self.modelManager.validateCalcLB = True
        if options.utrValidate:
            self.modelManager.validateUtr = True
        fo = FormulaOptions()
        if options.formulaParamExprResult:
            fo.traceParameterExpressionResult = True
        if options.formulaParamInputValue:
            fo.traceParameterInputValue = True
        if options.formulaCallExprSource:
            fo.traceCallExpressionSource = True
        if options.formulaCallExprCode:
            fo.traceCallExpressionCode = True
        if options.formulaCallExprEval:
            fo.traceCallExpressionEvaluation = True
        if options.formulaCallExprResult:
            fo.traceCallExpressionResult = True
        if options.formulaVarSetExprEval:
            fo.traceVariableSetExpressionEvaluation = True
        if options.formulaVarSetExprResult:
            fo.traceVariableSetExpressionResult = True
        if options.formulaAsserResultCounts:
            fo.traceAssertionResultCounts = True
        if options.formulaFormulaRules:
            fo.traceFormulaRules = True
        if options.formulaVarsOrder:
            fo.traceVariablesOrder = True
        if options.formulaVarExpressionSource:
            fo.traceVariableExpressionSource = True
        if options.formulaVarExpressionCode:
            fo.traceVariableExpressionCode = True
        if options.formulaVarExpressionEvaluation:
            fo.traceVariableExpressionEvaluation = True
        if options.formulaVarExpressionResult:
            fo.traceVariableExpressionResult = True
        if options.formulaVarFiltersResult:
            fo.traceVariableFiltersResult = True
        self.modelManager.formulaOptions = fo
        timeNow = XmlUtil.dateunionValue(datetime.datetime.now())
        startedAt = time.time()
        modelXbrl = self.modelManager.load(filesource, _("views loading"))
        self.addToLog(
            format_string(self.modelManager.locale,
                          _("[info] loaded in %.2f secs at %s"),
                          (time.time() - startedAt, timeNow)))

        if options.diffFilename and options.versReportFilename:
            diffFilesource = FileSource.FileSource(self.diffFilename, self)
            startedAt = time.time()
            modelXbrl = self.modelManager.load(diffFilesource,
                                               _("views loading"))
            self.addToLog(
                format_string(
                    self.modelManager.locale,
                    _("[info] diff comparison DTS loaded in %.2f secs"),
                    time.time() - startedAt))
            startedAt = time.time()
            self.modelManager.compareDTSes(options.versReportFilename)
            self.addToLog(
                format_string(self.modelManager.locale,
                              _("[info] compared in %.2f secs"),
                              time.time() - startedAt))
        try:
            if options.validate:
                startedAt = time.time()
                self.modelManager.validate()
                self.addToLog(
                    format_string(self.modelManager.locale,
                                  _("[info] validated in %.2f secs"),
                                  time.time() - startedAt))
                if (options.csvTestReport
                        and self.modelManager.modelXbrl.modelDocument.type
                        in (ModelDocument.Type.TESTCASESINDEX,
                            ModelDocument.Type.REGISTRY)):
                    ViewCsvTests.viewTests(self.modelManager.modelXbrl,
                                           options.csvTestReport)

            if options.csvDTS:
                ViewCsvDTS.viewDTS(modelXbrl, options.csvDTS)
            if options.csvFactList:
                ViewCsvFactList.viewFacts(modelXbrl, options.csvFactList)
            if options.csvConcepts:
                ViewCsvConcepts.viewConcepts(modelXbrl, options.csvConcepts)
            if options.csvPre:
                ViewCsvRelationshipSet.viewRelationshipSet(
                    modelXbrl, options.csvPre, "Presentation",
                    "http://www.xbrl.org/2003/arcrole/parent-child")
            if options.csvCal:
                ViewCsvRelationshipSet.viewRelationshipSet(
                    modelXbrl, options.csvCal, "Calculation",
                    "http://www.xbrl.org/2003/arcrole/summation-item")
            if options.csvDim:
                ViewCsvRelationshipSet.viewRelationshipSet(
                    modelXbrl, options.csvDim, "Dimension", "XBRL-dimensions")
        except (IOError, EnvironmentError) as err:
            self.addToLog(
                _("[IOError] Failed to save output:\n {0}").format(err))

        if self.messages:
            try:
                with open(options.logFile, "w", encoding="utf-8") as fh:
                    fh.writelines(self.messages)
            except (IOError, EnvironmentError) as err:
                print("Unable to save log to file: " + err)
Esempio n. 3
0
 def fileSave(self, *ignore):
     if self.modelManager.modelXbrl:
         if self.modelManager.modelXbrl.modelDocument.type == ModelDocument.Type.TESTCASESINDEX:
             filename = tkinter.filedialog.asksaveasfilename(
                     title=_("arelle\u2122 - Save Test Results"),
                     initialdir=os.path.dirname(self.modelManager.modelXbrl.modelDocument.uri),
                     filetypes=[(_("CSV file"), "*.csv")],
                     defaultextension=".csv",
                     parent=self.parent)
             if not filename:
                 return False
             try:
                 ViewCsvTests.viewTests(self.modelManager.modelXbrl, filename)
             except (IOError, EnvironmentError) as err:
                 tkinter.messagebox.showwarning(_("arelle\u2122 - Error"),
                                     _("Failed to save {0}:\n{1}").format(
                                     self.filename, err),
                                     parent=self.parent)
             return True
         elif self.modelManager.modelXbrl.formulaOutputInstance:
             filename = tkinter.filedialog.asksaveasfilename(
                     title=_("arelle\u2122 - Save Formula Result Instance Document"),
                     initialdir=os.path.dirname(self.modelManager.modelXbrl.modelDocument.uri),
                     filetypes=[(_("XBRL output instance .xml"), "*.xml"), (_("XBRL output instance .xbrl"), "*.xbrl")],
                     defaultextension=".xml",
                     parent=self.parent)
             if not filename:
                 return False
             try:
                 from arelle import XmlUtil
                 with open(filename, "w") as fh:
                     XmlUtil.writexml(fh, self.modelManager.modelXbrl.formulaOutputInstance.modelDocument.xmlDocument, encoding="utf-8")
                 self.addToLog(_("[info] Saved formula output instance to {0}").format(filename) )
             except (IOError, EnvironmentError) as err:
                 tkinter.messagebox.showwarning(_("arelle\u2122 - Error"),
                                 _("Failed to save {0}:\n{1}").format(
                                 self.filename, err),
                                 parent=self.parent)
             return True
     if self.filename is None:
         filename = tkinter.filedialog.asksaveasfilename(
                 title=_("arelle\u2122 - Save File"),
                 initialdir=".",
                 filetypes=[(_("Xbrl file"), "*.x*")],
                 defaultextension=".xbrl",
                 parent=self.parent)
         if not filename:
             return False
         self.filename = filename
         if not self.filename.endswith(".xbrl"):
             self.filename += ".xbrl"
     try:
         with open(self.filename, "wb") as fh:
             pickle.dump(self.data, fh, pickle.HIGHEST_PROTOCOL)
         self.dirty = False
         self.uiShowStatus(_("Saved {0} items to {1}").format(
                             len(self.data),
                             self.filename), clearAfter=5000)
         self.parent.title(_("arelle\u2122 - {0}").format(
                             os.path.basename(self.filename)))
     except (EnvironmentError, pickle.PickleError) as err:
         tkinter.messagebox.showwarning(_("arelle\u2122 - Error"),
                             _("Failed to save {0}:\n{1}").format(
                             self.filename, err),
                             parent=self.parent)
     return True;