def storeIntoDBMenuCommand(): # save DTS menu item has been invoked if cntlr.modelManager is None or cntlr.modelManager.modelXbrl is None: cntlr.addToLog("No XBRL instance or taxonomy is loaded.") return from arelle.DialogUserPassword import askDatabase # (user, password, host, port, database) priorDBconnection = cntlr.config.get("xbrlDBconnection", None) dbConnection = askDatabase(cntlr.parent, priorDBconnection) if dbConnection: host, port, user, password, db = dbConnection # identify server if isPostgresPort(host, port): insertIntoDB = insertIntoPostgresDB elif isRexsterPort(host, port): insertIntoDB = insertIntoRexsterDB else: from tkinter import messagebox messagebox.showwarning( _("Unable to determine server type!"), _("Probing host {0} port {1} unable to determine server type." ).format(host, port), parent=cntlr.parent) return cntlr.config["xbrlDBconnection"] = dbConnection cntlr.saveConfig() else: # action cancelled return def backgroundStoreIntoDB(): try: startedAt = time.time() insertIntoDB(cntlr.modelManager.modelXbrl, host=host, port=port, user=user, password=password, database=db) cntlr.addToLog( format_string(cntlr.modelManager.locale, _("stored to database in %.2f secs"), time.time() - startedAt)) except Exception as ex: import traceback cntlr.addToLog( _("[xpDB:exception] Loading XBRL DB: %(exception)s: %(error)s \n%(traceback)s" ) % { "exception": ex.__class__.__name__, "error": str(ex), "exc_info": True, "traceback": traceback.format_tb(sys.exc_info()[2]) }) import threading thread = threading.Thread(target=backgroundStoreIntoDB) thread.daemon = True thread.start()
def enterConnectionString(): from arelle.DialogUserPassword import askDatabase # (user, password, host, port, database) db = askDatabase(cntlr.parent, dialog.cellDBconnection.value.split(',') if dialog.cellDBconnection.value else None) if db: dbConnectionString = ','.join(db) dialog.options["xbrlDBconnection"] = dbConnectionString dialog.cellDBconnection.setValue(dbConnectionString) else: # deleted dialog.options.pop("xbrlDBconnection", "") # remove entry
def storeIntoDBMenuCommand(): # save DTS menu item has been invoked if cntlr.modelManager is None or cntlr.modelManager.modelXbrl is None: cntlr.addToLog("No XBRL instance or taxonomy is loaded.") return from arelle.DialogUserPassword import askDatabase # (user, password, host, port, database) priorDBconnection = cntlr.config.get("xbrlDBconnection", None) dbConnection = askDatabase(cntlr.parent, priorDBconnection) if dbConnection: host, port, user, password, db, timeout = dbConnection if timeout and timeout.isdigit(): timeout = int(timeout) # identify server if isPostgresPort(host, port): insertIntoDB = insertIntoPostgresDB elif isRexsterPort(host, port): insertIntoDB = insertIntoRexsterDB elif isRdfPort(host, port, db): insertIntoDB = insertIntoRdfDB else: from tkinter import messagebox messagebox.showwarning(_("Unable to determine server type!"), _("Probing host {0} port {1} unable to determine server type.") .format(host, port), parent=cntlr.parent) return cntlr.config["xbrlDBconnection"] = dbConnection cntlr.saveConfig() else: # action cancelled return def backgroundStoreIntoDB(): try: startedAt = time.time() insertIntoDB(cntlr.modelManager.modelXbrl, host=host, port=port, user=user, password=password, database=db, timeout=timeout) cntlr.addToLog(format_string(cntlr.modelManager.locale, _("stored to database in %.2f secs"), time.time() - startedAt)) except Exception as ex: import traceback cntlr.addToLog( _("[xpDB:exception] Loading XBRL DB: %(exception)s: %(error)s \n%(traceback)s") % {"exception": ex.__class__.__name__, "error": str(ex), "exc_info": True, "traceback": traceback.format_tb(sys.exc_info()[2])}) import threading thread = threading.Thread(target=backgroundStoreIntoDB) thread.daemon = True thread.start()
def enterConnectionString(): from arelle.DialogUserPassword import askDatabase # (user, password, host, port, database) db = askDatabase( cntlr.parent, dialog.cellDBconnection.value.split(',') if dialog.cellDBconnection.value else None) if db: dbConnectionString = ','.join(db) dialog.options["xbrlDBconnection"] = dbConnectionString dialog.cellDBconnection.setValue(dbConnectionString) else: # deleted dialog.options.pop("xbrlDBconnection", "") # remove entry
def storeIntoDBMenuCommand(): # save DTS menu item has been invoked if cntlr.modelManager is None or cntlr.modelManager.modelXbrl is None: cntlr.addToLog("No XBRL instance or taxonomy is loaded.") return from arelle.DialogUserPassword import askDatabase # (user, password, host, port, database) priorDBconnection = cntlr.config.get("xbrlDBconnection", None) dbConnection = askDatabase(cntlr.parent, priorDBconnection) if not dbConnection: # action cancelled return def backgroundStoreIntoDB(): try: host, port, user, password, db, timeout, dbType = dbConnection product = None if timeout and timeout.isdigit(): timeout = int(timeout) # identify server if dbType in dbTypes: insertIntoDB = dbTypes[dbType] product = dbProduct[dbType] else: cntlr.addToLog(_("Probing host {0} port {1} to determine server database type.") .format(host, port)) if isPostgresPort(host, port): dbType = "postgres" insertIntoDB = insertIntoPostgresDB elif isSemanticSqlPort(host, port): dbType = "pgSemantic" insertIntoDB = insertIntoPostgresDB elif isRexsterPort(host, port): dbType = "rexster" insertIntoDB = insertIntoRexsterDB elif isRdfPort(host, port, db): dbType = "rdfDB" insertIntoDB = insertIntoRdfDB elif isJsonPort(host, port, db): dbType = "json" insertIntoDB = insertIntoJsonDB else: cntlr.addToLog(_("Unable to determine server type!\n ") + _("Probing host {0} port {1} unable to determine server type.") .format(host, port)) cntlr.config["xbrlDBconnection"] = (host, port, user, password, db, timeout, '') # forget type cntlr.saveConfig() return cntlr.addToLog(_("Database type {} identified.").format(dbType)) cntlr.config["xbrlDBconnection"] = (host, port, user, password, db, timeout, dbType) cntlr.saveConfig() startedAt = time.time() insertIntoDB(cntlr.modelManager.modelXbrl, host=host, port=port, user=user, password=password, database=db, timeout=timeout, product=product) cntlr.addToLog(format_string(cntlr.modelManager.locale, _("stored to database in %.2f secs"), time.time() - startedAt)) except Exception as ex: import traceback cntlr.addToLog( _("[xpDB:exception] Loading XBRL DB: %(exception)s: %(error)s \n%(traceback)s") % {"exception": ex.__class__.__name__, "error": str(ex), "exc_info": True, "traceback": traceback.format_tb(sys.exc_info()[2])}) cntlr.config["xbrlDBconnection"] = (host, port, user, password, db, timeout, '') # forget type cntlr.saveConfig() import threading thread = threading.Thread(target=backgroundStoreIntoDB) thread.daemon = True thread.start()
def storeIntoDBMenuCommand(): # save DTS menu item has been invoked if cntlr.modelManager is None or cntlr.modelManager.modelXbrl is None: cntlr.addToLog("No XBRL instance or taxonomy is loaded.") return from arelle.DialogUserPassword import askDatabase # (user, password, host, port, database) priorDBconnection = cntlr.config.get("xbrlDBconnection", None) dbConnection = askDatabase(cntlr.parent, priorDBconnection) if not dbConnection: # action cancelled return def backgroundStoreIntoDB(): try: host, port, user, password, db, timeout, dbType = dbConnection product = None if timeout and timeout.isdigit(): timeout = int(timeout) # identify server if dbType in dbTypes: insertIntoDB = dbTypes[dbType] product = dbProduct[dbType] else: cntlr.addToLog( _("Probing host {0} port {1} to determine server database type." ).format(host, port)) if isPostgresPort(host, port): dbType = "postgres" insertIntoDB = insertIntoPostgresDB elif isSemanticSqlPort(host, port): dbType = "pgSemantic" insertIntoDB = insertIntoPostgresDB elif isRexsterPort(host, port): dbType = "rexster" insertIntoDB = insertIntoRexsterDB elif isRdfPort(host, port, db): dbType = "rdfDB" insertIntoDB = insertIntoRdfDB elif isJsonPort(host, port, db): dbType = "json" insertIntoDB = insertIntoJsonDB else: cntlr.addToLog( _("Unable to determine server type!\n ") + _("Probing host {0} port {1} unable to determine server type." ).format(host, port)) cntlr.config["xbrlDBconnection"] = (host, port, user, password, db, timeout, '' ) # forget type cntlr.saveConfig() return cntlr.addToLog( _("Database type {} identified.").format(dbType)) cntlr.config["xbrlDBconnection"] = (host, port, user, password, db, timeout, dbType) cntlr.saveConfig() startedAt = time.time() insertIntoDB(cntlr.modelManager.modelXbrl, host=host, port=port, user=user, password=password, database=db, timeout=timeout, product=product) cntlr.addToLog( format_string(cntlr.modelManager.locale, _("stored to database in %.2f secs"), time.time() - startedAt)) except Exception as ex: import traceback cntlr.addToLog( _("[xpDB:exception] Loading XBRL DB: %(exception)s: %(error)s \n%(traceback)s" ) % { "exception": ex.__class__.__name__, "error": str(ex), "exc_info": True, "traceback": traceback.format_tb(sys.exc_info()[2]) }) cntlr.config["xbrlDBconnection"] = (host, port, user, password, db, timeout, '' ) # forget type cntlr.saveConfig() import threading thread = threading.Thread(target=backgroundStoreIntoDB) thread.daemon = True thread.start()