def ok(self, event=None): labelLangIndex = self.cbLabelLang.valueIndex if labelLangIndex >= 0 and labelLangIndex != self.labelLangIndex: # changed if labelLangIndex == 0: langCode = self.mainWin.modelManager.defaultLang else: langCode, sep, localeCode = self.languageCodes[ self.cbLabelLang.value].partition(" ") self.mainWin.config["labelLangOverride"] = langCode self.mainWin.labelLang = langCode uiLangIndex = self.cbUiLang.valueIndex if uiLangIndex >= 0 and uiLangIndex != self.uiLangIndex: # changed if uiLangIndex == 0: langCode = self.mainWin.modelManager.defaultLang localeCode = "" else: langCode, sep, localeCode = self.languageCodes[ self.cbUiLang.value].partition(" ") if not self.mainWin.isMSW: # Windows uses string language codes localeCode = langCode.replace( "-", "_") + ".UTF-8" # Unix and Mac uses en_US.UTF-8 newLocale = getUserLocale(localeCode) if newLocale is not None: self.mainWin.modelManager.locale = newLocale else: messagebox.showerror( _("User interface locale error"), _("Locale setting {0} ({1}) is not supported on this system" ).format(langCode, localeCode), parent=self) return if localeCode != "": # not the system default self.mainWin.config["userInterfaceLangOverride"] = langCode self.mainWin.config["userInterfaceLocaleOverride"] = localeCode else: # use system default self.mainWin.config.pop("userInterfaceLangOverride", None) self.mainWin.config.pop("userInterfaceLocaleOverride", None) try: gettext.translation("arelle", self.mainWin.localeDir, getLanguageCodes(lang=langCode)).install() except: gettext.install("arelle", self.mainWin.localeDir) if messagebox.askyesno( _("User interface language changed"), _("Should Arelle restart with changed user interface language, if there are any unsaved changes they would be lost!" ), parent=self): self.mainWin.uiThreadQueue.put( (self.mainWin.quit, [None, True])) else: messagebox.showwarning( _("User interface language changed"), _("Please restart Arelle for the change in user interface language." ), parent=self) self.close()
def setUiLanguage(self, lang, fallbackToDefault=False): try: gettext.translation("arelle", self.localeDir, getLanguageCodes(lang)).install() except Exception: if fallbackToDefault or (lang and lang.lower().startswith("en")): gettext.install("arelle", self.localeDir)
def ok(self, event=None): labelLangIndex = self.cbLabelLang.valueIndex if labelLangIndex >= 0 and labelLangIndex != self.labelLangIndex: # changed if labelLangIndex == 0: langCode = self.mainWin.modelManager.defaultLang else: langCode, sep, localeCode = self.languageCodes[self.cbLabelLang.value].partition(" ") self.mainWin.config["labelLangOverride"] = langCode self.mainWin.labelLang = langCode uiLangIndex = self.cbUiLang.valueIndex if uiLangIndex >= 0 and uiLangIndex != self.uiLangIndex: # changed if uiLangIndex == 0: langCode = self.mainWin.modelManager.defaultLang localeCode = "" else: langCode, sep, localeCode = self.languageCodes[self.cbUiLang.value].partition(" ") if not self.mainWin.isMSW: # Windows uses string language codes localeCode = langCode.replace("-", "_") + ".UTF-8" # Unix and Mac uses en_US.UTF-8 newLocale = getUserLocale(localeCode) if newLocale is not None: self.mainWin.modelManager.locale = newLocale else: messagebox.showerror(_("User interface locale error"), _("Locale setting {0} ({1}) is not supported on this system") .format(langCode, localeCode), parent=self) return if localeCode != "": # not the system default self.mainWin.config["userInterfaceLangOverride"] = langCode self.mainWin.config["userInterfaceLocaleOverride"] = localeCode else: # use system default self.mainWin.config.pop("userInterfaceLangOverride", None) self.mainWin.config.pop("userInterfaceLocaleOverride", None) try: gettext.translation("arelle", self.mainWin.localeDir, getLanguageCodes(lang=langCode)).install() except: gettext.install("arelle", self.mainWin.localeDir) if messagebox.askyesno( _("User interface language changed"), _("Should Arelle restart with changed user interface language, if there are any unsaved changes they would be lost!"), parent=self): self.mainWin.uiThreadQueue.put((self.mainWin.quit, [None, True])) else: messagebox.showwarning( _("User interface language changed"), _("Please restart Arelle for the change in user interface language."), parent=self) self.close()
def setUiLanguage(self, lang, fallbackToDefault=False): try: gettext.translation("arelle", self.localeDir, getLanguageCodes(lang)).install() if not isPy3: # 2.7 gettext provides string instead of unicode from .mo files installedGettext = __builtins__['_'] def convertGettextResultToUnicode(msg): translatedMsg = installedGettext(msg) if isinstance(translatedMsg, _STR_UNICODE): return translatedMsg return translatedMsg.decode('utf-8') __builtins__['_'] = convertGettextResultToUnicode except Exception: if fallbackToDefault or (lang and lang.lower().startswith("en")): gettext.install("arelle", self.localeDir)
def loadModule(moduleInfo): name = moduleInfo['name'] moduleURL = moduleInfo['moduleURL'] moduleFilename = webCache.getfilename(moduleURL, normalize=True) if moduleFilename: file, path, description = imp.find_module( os.path.basename(moduleFilename).partition('.')[0], [os.path.dirname(moduleFilename)]) if file: try: module = imp.load_module(name, file, path, description) pluginInfo = module.__pluginInfo__.copy() if name == pluginInfo.get('name'): pluginInfo["moduleURL"] = moduleURL modulePluginInfos[name] = pluginInfo if 'localeURL' in pluginInfo: # set L10N internationalization in loaded module localeDir = os.path.dirname( module.__file__) + os.sep + pluginInfo['localeURL'] try: _gettext = gettext.translation( pluginInfo['localeDomain'], localeDir, getLanguageCodes()) except IOError: _gettext = lambda x: x # no translation else: _gettext = lambda x: x for key, value in pluginInfo.items(): if key == 'name': if name: pluginConfig['modules'][name] = moduleInfo elif isinstance(value, types.FunctionType): classModuleNames = pluginConfig[ 'classes'].setdefault(key, []) if name and name not in classModuleNames: classModuleNames.append(name) module._ = _gettext global pluginConfigChanged pluginConfigChanged = True except (ImportError, AttributeError): pass finally: file.close()
def loadModule(moduleInfo): name = moduleInfo['name'] moduleURL = moduleInfo['moduleURL'] moduleFilename = _cntlr.webCache.getfilename(moduleURL, normalize=True, base=_pluginBase) if moduleFilename: try: if os.path.isdir(moduleFilename) and os.path.isfile(os.path.join(moduleFilename, "__init__.py")): moduleDir = os.path.dirname(moduleFilename) moduleName = os.path.basename(moduleFilename) else: moduleName = os.path.basename(moduleFilename).partition('.')[0] moduleDir = os.path.dirname(moduleFilename) file, path, description = imp.find_module(moduleName, [moduleDir]) if file or path: # file returned if non-package module, otherwise just path for package try: module = imp.load_module(moduleName, file, path, description) pluginInfo = module.__pluginInfo__.copy() elementSubstitutionClasses = None if name == pluginInfo.get('name'): pluginInfo["moduleURL"] = moduleURL modulePluginInfos[name] = pluginInfo if 'localeURL' in pluginInfo: # set L10N internationalization in loaded module localeDir = os.path.dirname(module.__file__) + os.sep + pluginInfo['localeURL'] try: _gettext = gettext.translation(pluginInfo['localeDomain'], localeDir, getLanguageCodes()) except IOError: _gettext = lambda x: x # no translation else: _gettext = lambda x: x for key, value in pluginInfo.items(): if key == 'name': if name: pluginConfig['modules'][name] = moduleInfo elif isinstance(value, types.FunctionType): classModuleNames = pluginConfig['classes'].setdefault(key, []) if name and name not in classModuleNames: classModuleNames.append(name) if key == 'ModelObjectFactory.ElementSubstitutionClasses': elementSubstitutionClasses = value module._ = _gettext global pluginConfigChanged pluginConfigChanged = True if elementSubstitutionClasses: try: from arelle.ModelObjectFactory import elementSubstitutionModelClass elementSubstitutionModelClass.update(elementSubstitutionClasses) except Exception as err: print(_("Exception loading plug-in {name}: processing ModelObjectFactory.ElementSubstitutionClasses").format( name=name, error=err), file=sys.stderr) except (ImportError, AttributeError) as err: print(_("Exception loading plug-in {name}: {error}").format( name=name, error=err), file=sys.stderr) finally: if file: file.close() # non-package module except (EnvironmentError, ImportError, NameError) as err: #find_module failed, no file to close print(_("Exception finding plug-in {name}: {error}").format( name=name, error=err), file=sys.stderr)
def loadModule(moduleInfo, packagePrefix=""): name = moduleInfo['name'] moduleURL = moduleInfo['moduleURL'] moduleFilename = _cntlr.webCache.getfilename(moduleURL, normalize=True, base=_pluginBase) if moduleFilename: try: if os.path.basename( moduleFilename) == "__init__.py" and os.path.isfile( moduleFilename): moduleFilename = os.path.dirname( moduleFilename) # want just the dirpart of package if os.path.isdir(moduleFilename) and os.path.isfile( os.path.join(moduleFilename, "__init__.py")): moduleDir = os.path.dirname(moduleFilename) moduleName = os.path.basename(moduleFilename) packageImportPrefix = moduleName + "." else: moduleName = os.path.basename(moduleFilename).partition('.')[0] moduleDir = os.path.dirname(moduleFilename) packageImportPrefix = packagePrefix file, path, description = imp.find_module(moduleName, [moduleDir]) if file or path: # file returned if non-package module, otherwise just path for package try: module = imp.load_module(packagePrefix + moduleName, file, path, description) pluginInfo = module.__pluginInfo__.copy() elementSubstitutionClasses = None if name == pluginInfo.get('name'): pluginInfo["moduleURL"] = moduleURL modulePluginInfos[name] = pluginInfo if 'localeURL' in pluginInfo: # set L10N internationalization in loaded module localeDir = os.path.dirname( module.__file__ ) + os.sep + pluginInfo['localeURL'] try: _gettext = gettext.translation( pluginInfo['localeDomain'], localeDir, getLanguageCodes()) except IOError: _gettext = lambda x: x # no translation else: _gettext = lambda x: x for key, value in pluginInfo.items(): if key == 'name': if name: pluginConfig['modules'][name] = moduleInfo elif isinstance(value, types.FunctionType): classModuleNames = pluginConfig[ 'classes'].setdefault(key, []) if name and name not in classModuleNames: classModuleNames.append(name) if key == 'ModelObjectFactory.ElementSubstitutionClasses': elementSubstitutionClasses = value module._ = _gettext global pluginConfigChanged pluginConfigChanged = True if elementSubstitutionClasses: try: from arelle.ModelObjectFactory import elementSubstitutionModelClass elementSubstitutionModelClass.update( elementSubstitutionClasses) except Exception as err: _msg = _( "Exception loading plug-in {name}: processing ModelObjectFactory.ElementSubstitutionClasses" ).format(name=name, error=err) if PLUGIN_TRACE_FILE: with open(PLUGIN_TRACE_FILE, "at", encoding='utf-8') as fh: fh.write(_msg + '\n') else: print(_msg, file=sys.stderr) for importModuleInfo in moduleInfo.get( 'imports', EMPTYLIST): loadModule(importModuleInfo, packageImportPrefix) except (ImportError, AttributeError, SystemError) as err: _msg = _( "Exception loading plug-in {name}: {error}\n{traceback}" ).format(name=name, error=err, traceback=traceback.format_tb(sys.exc_info()[2])) if PLUGIN_TRACE_FILE: with open(PLUGIN_TRACE_FILE, "at", encoding='utf-8') as fh: fh.write(_msg + '\n') else: print(_msg, file=sys.stderr) finally: if file: file.close() # non-package module except (EnvironmentError, ImportError, NameError, SyntaxError) as err: #find_module failed, no file to close _msg = _("Exception finding plug-in {name}: {error}").format( name=name, error=err) if PLUGIN_TRACE_FILE: with open(PLUGIN_TRACE_FILE, "at", encoding='utf-8') as fh: fh.write(_msg + '\n') else: print(_msg, file=sys.stderr)
def loadModule(moduleInfo): name = moduleInfo['name'] moduleURL = moduleInfo['moduleURL'] moduleFilename = _cntlr.webCache.getfilename(moduleURL, normalize=True, base=_pluginBase) if moduleFilename: try: if os.path.isdir(moduleFilename) and os.path.isfile( os.path.join(moduleFilename, "__init__.py")): moduleDir = os.path.dirname(moduleFilename) moduleName = os.path.basename(moduleFilename) else: moduleName = os.path.basename(moduleFilename).partition('.')[0] moduleDir = os.path.dirname(moduleFilename) file, path, description = imp.find_module(moduleName, [moduleDir]) if file or path: # file returned if non-package module, otherwise just path for package try: module = imp.load_module(moduleName, file, path, description) pluginInfo = module.__pluginInfo__.copy() elementSubstitutionClasses = None if name == pluginInfo.get('name'): pluginInfo["moduleURL"] = moduleURL modulePluginInfos[name] = pluginInfo if 'localeURL' in pluginInfo: # set L10N internationalization in loaded module localeDir = os.path.dirname( module.__file__ ) + os.sep + pluginInfo['localeURL'] try: _gettext = gettext.translation( pluginInfo['localeDomain'], localeDir, getLanguageCodes()) except IOError: _gettext = lambda x: x # no translation else: _gettext = lambda x: x for key, value in pluginInfo.items(): if key == 'name': if name: pluginConfig['modules'][name] = moduleInfo elif isinstance(value, types.FunctionType): classModuleNames = pluginConfig[ 'classes'].setdefault(key, []) if name and name not in classModuleNames: classModuleNames.append(name) if key == 'ModelObjectFactory.ElementSubstitutionClasses': elementSubstitutionClasses = value module._ = _gettext global pluginConfigChanged pluginConfigChanged = True if elementSubstitutionClasses: try: from arelle.ModelObjectFactory import elementSubstitutionModelClass elementSubstitutionModelClass.update( elementSubstitutionClasses) except Exception as err: print(_( "Exception loading plug-in {name}: processing ModelObjectFactory.ElementSubstitutionClasses" ).format(name=name, error=err), file=sys.stderr) except (ImportError, AttributeError) as err: print( _("Exception loading plug-in {name}: {error}").format( name=name, error=err), file=sys.stderr) finally: if file: file.close() # non-package module except (EnvironmentError, ImportError, NameError) as err: #find_module failed, no file to close print(_("Exception finding plug-in {name}: {error}").format( name=name, error=err), file=sys.stderr)
def loadModule(moduleInfo, packagePrefix=""): name = moduleInfo['name'] moduleURL = moduleInfo['moduleURL'] moduleFilename = _cntlr.webCache.getfilename(moduleURL, normalize=True, base=_pluginBase) if moduleFilename: try: if os.path.basename(moduleFilename) == "__init__.py" and os.path.isfile(moduleFilename): moduleFilename = os.path.dirname(moduleFilename) # want just the dirpart of package if os.path.isdir(moduleFilename) and os.path.isfile(os.path.join(moduleFilename, "__init__.py")): moduleDir = os.path.dirname(moduleFilename) moduleName = os.path.basename(moduleFilename) packageImportPrefix = moduleName + "." else: moduleName = os.path.basename(moduleFilename).partition('.')[0] moduleDir = os.path.dirname(moduleFilename) packageImportPrefix = packagePrefix file, path, description = imp.find_module(moduleName, [moduleDir]) if file or path: # file returned if non-package module, otherwise just path for package try: module = imp.load_module(packagePrefix + moduleName, file, path, description) pluginInfo = module.__pluginInfo__.copy() elementSubstitutionClasses = None if name == pluginInfo.get('name'): pluginInfo["moduleURL"] = moduleURL modulePluginInfos[name] = pluginInfo if 'localeURL' in pluginInfo: # set L10N internationalization in loaded module localeDir = os.path.dirname(module.__file__) + os.sep + pluginInfo['localeURL'] try: _gettext = gettext.translation(pluginInfo['localeDomain'], localeDir, getLanguageCodes()) except IOError: _gettext = lambda x: x # no translation else: _gettext = lambda x: x for key, value in pluginInfo.items(): if key == 'name': if name: pluginConfig['modules'][name] = moduleInfo elif isinstance(value, types.FunctionType): classModuleNames = pluginConfig['classes'].setdefault(key, []) if name and name not in classModuleNames: classModuleNames.append(name) if key == 'ModelObjectFactory.ElementSubstitutionClasses': elementSubstitutionClasses = value module._ = _gettext global pluginConfigChanged pluginConfigChanged = True if elementSubstitutionClasses: try: from arelle.ModelObjectFactory import elementSubstitutionModelClass elementSubstitutionModelClass.update(elementSubstitutionClasses) except Exception as err: _msg = _("Exception loading plug-in {name}: processing ModelObjectFactory.ElementSubstitutionClasses").format( name=name, error=err) if PLUGIN_TRACE_FILE: with open(PLUGIN_TRACE_FILE, "at", encoding='utf-8') as fh: fh.write(_msg + '\n') else: print(_msg, file=sys.stderr) for importModuleInfo in moduleInfo.get('imports', EMPTYLIST): loadModule(importModuleInfo, packageImportPrefix) except (ImportError, AttributeError, SystemError) as err: _msg = _("Exception loading plug-in {name}: {error}\n{traceback}").format( name=name, error=err, traceback=traceback.format_tb(sys.exc_info()[2])) if PLUGIN_TRACE_FILE: with open(PLUGIN_TRACE_FILE, "at", encoding='utf-8') as fh: fh.write(_msg + '\n') else: print(_msg, file=sys.stderr) finally: if file: file.close() # non-package module except (EnvironmentError, ImportError, NameError, SyntaxError) as err: #find_module failed, no file to close _msg = _("Exception finding plug-in {name}: {error}").format(name=name, error=err) if PLUGIN_TRACE_FILE: with open(PLUGIN_TRACE_FILE, "at", encoding='utf-8') as fh: fh.write(_msg + '\n') else: print(_msg, file=sys.stderr)
def loadModule(moduleInfo): name = moduleInfo['name'] moduleURL = moduleInfo['moduleURL'] moduleFilename = webCache.getfilename(moduleURL, normalize=True) if moduleFilename: file, path, description = imp.find_module(os.path.basename(moduleFilename).partition('.')[0], [os.path.dirname(moduleFilename)]) if file: try: module = imp.load_module(name, file, path, description) pluginInfo = module.__pluginInfo__.copy() if name == pluginInfo.get('name'): pluginInfo["moduleURL"] = moduleURL modulePluginInfos[name] = pluginInfo if 'localeURL' in pluginInfo: # set L10N internationalization in loaded module localeDir = os.path.dirname(module.__file__) + os.sep + pluginInfo['localeURL'] try: _gettext = gettext.translation(pluginInfo['localeDomain'], localeDir, getLanguageCodes()) except IOError: _gettext = lambda x: x # no translation else: _gettext = lambda x: x for key, value in pluginInfo.items(): if key == 'name': if name: pluginConfig['modules'][name] = moduleInfo elif isinstance(value, types.FunctionType): classModuleNames = pluginConfig['classes'].setdefault(key, []) if name and name not in classModuleNames: classModuleNames.append(name) module._ = _gettext global pluginConfigChanged pluginConfigChanged = True except (ImportError, AttributeError): pass finally: file.close()
def __init__(self, logFileName=None, logFileMode=None, logFileEncoding=None, logFormat=None): self.hasWin32gui = False self.hasGui = False if sys.platform == "darwin": self.isMac = True self.isMSW = False self.userAppDir = os.path.expanduser("~") + "/Library/Application Support/Arelle" self.contextMenuClick = "<Button-2>" self.hasClipboard = True self.updateURL = "http://arelle.org/downloads/8" elif sys.platform.startswith("win"): self.isMac = False self.isMSW = True tempDir = tempfile.gettempdir() if tempDir.endswith('local\\temp'): self.userAppDir = tempDir[:-10] + 'local\\Arelle' else: self.userAppDir = tempDir + os.sep + 'arelle' try: import win32clipboard self.hasClipboard = True except ImportError: self.hasClipboard = False try: import win32gui self.hasWin32gui = True # active state for open file dialogs except ImportError: pass self.contextMenuClick = "<Button-3>" if "64 bit" in sys.version: self.updateURL = "http://arelle.org/downloads/9" else: # 32 bit self.updateURL = "http://arelle.org/downloads/10" else: # Unix/Linux self.isMac = False self.isMSW = False self.userAppDir = os.path.join( os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config")), "arelle") try: import gtk self.hasClipboard = True except ImportError: self.hasClipboard = False self.contextMenuClick = "<Button-3>" self.moduleDir = os.path.dirname(__file__) # for python 3.2 remove __pycache__ if self.moduleDir.endswith("__pycache__"): self.moduleDir = os.path.dirname(self.moduleDir) if self.moduleDir.endswith("python32.zip/arelle"): ''' distZipFile = os.path.dirname(self.moduleDir) d = os.path.join(self.userAppDir, "arelle") self.configDir = os.path.join(d, "config") self.imagesDir = os.path.join(d, "images") import zipfile distZip = zipfile.ZipFile(distZipFile, mode="r") distNames = distZip.namelist() distZip.extractall(path=self.userAppDir, members=[f for f in distNames if "/config/" in f or "/images/" in f] ) distZip.close() ''' resources = os.path.dirname(os.path.dirname(os.path.dirname(self.moduleDir))) self.configDir = os.path.join(resources, "config") self.imagesDir = os.path.join(resources, "images") self.localeDir = os.path.join(resources, "locale") elif self.moduleDir.endswith("library.zip\\arelle") or self.moduleDir.endswith("library.zip/arelle"): # cx_Freexe resources = os.path.dirname(os.path.dirname(self.moduleDir)) self.configDir = os.path.join(resources, "config") self.imagesDir = os.path.join(resources, "images") self.localeDir = os.path.join(resources, "locale") else: self.configDir = os.path.join(self.moduleDir, "config") self.imagesDir = os.path.join(self.moduleDir, "images") self.localeDir = os.path.join(self.moduleDir, "locale") try: from arelle import webserver self.hasWebServer = True except ImportError: self.hasWebServer = False # assert that app dir must exist if not os.path.exists(self.userAppDir): os.makedirs(self.userAppDir) # load config if it exists self.configJsonFile = self.userAppDir + os.sep + "config.json" self.config = None if os.path.exists(self.configJsonFile): try: with io.open(self.configJsonFile, 'rt', encoding='utf-8') as f: self.config = json.load(f) except Exception as ex: self.config = None # restart with a new config if not self.config: self.config = { 'fileHistory': [], 'windowGeometry': "{0}x{1}+{2}+{3}".format(800, 500, 200, 100), } # start language translation for domain try: gettext.translation("arelle", self.localeDir, getLanguageCodes(self.config.get("userInterfaceLangOverride",None))).install() except Exception as msg: gettext.install("arelle", self.localeDir) from arelle.WebCache import WebCache self.webCache = WebCache(self, self.config.get("proxySettings")) self.modelManager = ModelManager.initialize(self) # start plug in server (requres web cache initialized PluginManager.init(self) self.startLogging(logFileName, logFileMode, logFileEncoding, logFormat)
def __init__(self, logFileName=None, logFileMode=None, logFileEncoding=None, logFormat=None): self.hasWin32gui = False if sys.platform == "darwin": self.isMac = True self.isMSW = False self.userAppDir = os.path.expanduser("~") + "/Library/Application Support/Arelle" self.contextMenuClick = "<Button-2>" self.hasClipboard = True self.updateURL = "http://arelle.org/downloads/8" elif sys.platform.startswith("win"): self.isMac = False self.isMSW = True tempDir = tempfile.gettempdir() if tempDir.endswith("local\\temp"): self.userAppDir = tempDir[:-10] + "local\\Arelle" else: self.userAppDir = tempDir + os.sep + "arelle" try: import win32clipboard self.hasClipboard = True except ImportError: self.hasClipboard = False try: import win32gui self.hasWin32gui = True # active state for open file dialogs except ImportError: pass self.contextMenuClick = "<Button-3>" if "64 bit" in sys.version: self.updateURL = "http://arelle.org/downloads/9" else: # 32 bit self.updateURL = "http://arelle.org/downloads/10" else: # Unix/Linux self.isMac = False self.isMSW = False self.userAppDir = os.path.join(os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config")), "arelle") try: import gtk self.hasClipboard = True except ImportError: self.hasClipboard = False self.contextMenuClick = "<Button-3>" self.moduleDir = os.path.dirname(__file__) # for python 3.2 remove __pycache__ if self.moduleDir.endswith("__pycache__"): self.moduleDir = os.path.dirname(self.moduleDir) if self.moduleDir.endswith("python32.zip/arelle"): """ distZipFile = os.path.dirname(self.moduleDir) d = os.path.join(self.userAppDir, "arelle") self.configDir = os.path.join(d, "config") self.imagesDir = os.path.join(d, "images") import zipfile distZip = zipfile.ZipFile(distZipFile, mode="r") distNames = distZip.namelist() distZip.extractall(path=self.userAppDir, members=[f for f in distNames if "/config/" in f or "/images/" in f] ) distZip.close() """ resources = os.path.dirname(os.path.dirname(os.path.dirname(self.moduleDir))) self.configDir = os.path.join(resources, "config") self.imagesDir = os.path.join(resources, "images") self.localeDir = os.path.join(resources, "locale") elif self.moduleDir.endswith("library.zip\\arelle"): # cx_Freexe resources = os.path.dirname(os.path.dirname(self.moduleDir)) self.configDir = os.path.join(resources, "config") self.imagesDir = os.path.join(resources, "images") self.localeDir = os.path.join(resources, "locale") else: self.configDir = os.path.join(self.moduleDir, "config") self.imagesDir = os.path.join(self.moduleDir, "images") self.localeDir = os.path.join(self.moduleDir, "locale") # assert that app dir must exist if not os.path.exists(self.userAppDir): os.makedirs(self.userAppDir) # load config if it exists self.configPickleFile = self.userAppDir + os.sep + "config.pickle" self.config = None if os.path.exists(self.configPickleFile): try: with open(self.configPickleFile, "rb") as f: self.config = pickle.load(f) except Exception as ex: self.config = None # restart with a new config if not self.config: self.config = {"fileHistory": [], "windowGeometry": "{0}x{1}+{2}+{3}".format(800, 500, 200, 100)} # start language translation for domain try: gettext.translation("arelle", self.localeDir, getLanguageCodes()).install() except Exception as msg: gettext.install("arelle", self.localeDir) from arelle.WebCache import WebCache self.webCache = WebCache(self, self.config.get("proxySettings")) self.modelManager = ModelManager.initialize(self) if logFileName: # use default logging self.logger = logging.getLogger("arelle") if logFileName == "logToPrint": self.logHandler = LogToPrintHandler() else: self.logHandler = logging.FileHandler( filename=logFileName, mode=logFileMode if logFileMode else "w", encoding=logFileEncoding if logFileEncoding else "utf-8", ) self.logHandler.level = logging.DEBUG self.logHandler.setFormatter( logging.Formatter( logFormat if logFormat else "%(asctime)s [%(messageCode)s] %(message)s - %(file)s %(sourceLine)s \n" ) ) self.logger.addHandler(self.logHandler) else: self.logger = None