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, hasGui=False, logFileName=None, logFileMode=None, logFileEncoding=None, logFormat=None): self.hasWin32gui = False self.hasGui = hasGui self.hasFileSystem = True # no file system on Google App Engine servers self.isGAE = False self.isCGI = False self.systemWordSize = int(round(math.log(sys.maxsize, 2)) + 1) # e.g., 32 or 64 _resourcesDir = resourcesDir() self.configDir = os.path.join(_resourcesDir, "config") self.imagesDir = os.path.join(_resourcesDir, "images") self.localeDir = os.path.join(_resourcesDir, "locale") self.pluginDir = os.path.join(_resourcesDir, "plugin") _mplDir = os.path.join(_resourcesDir, "mpl-data") if os.path.exists( _mplDir ): # set matplotlibdata for cx_Freeze with local directory os.environ["MATPLOTLIBDATA"] = _mplDir serverSoftware = os.getenv("SERVER_SOFTWARE", "") if serverSoftware.startswith( "Google App Engine/") or serverSoftware.startswith( "Development/"): self.hasFileSystem = False # no file system, userAppDir does not exist self.isGAE = True else: gatewayInterface = os.getenv("GATEWAY_INTERFACE", "") if gatewayInterface.startswith("CGI/"): self.isCGI = True configHomeDir = None # look for path configDir/CONFIG_HOME in argv and environment parameters for i, arg in enumerate( sys.argv): # check if config specified in a argv if arg.startswith("--xdgConfigHome="): configHomeDir = arg[16:] break elif arg == "--xdgConfigHome" and i + 1 < len(sys.argv): configHomeDir = sys.argv[i + 1] break if not configHomeDir: # not in argv, may be an environment parameter configHomeDir = os.getenv('XDG_CONFIG_HOME') if not configHomeDir: # look for path configDir/CONFIG_HOME configHomeDirFile = os.path.join(self.configDir, "XDG_CONFIG_HOME") if os.path.exists(configHomeDirFile): try: with io.open(configHomeDirFile, 'rt', encoding='utf-8') as f: configHomeDir = f.read().strip() if configHomeDir and not os.path.isabs(configHomeDir): configHomeDir = os.path.abspath( configHomeDir) # make into a full path if relative except EnvironmentError: configHomeDir = None if self.hasFileSystem and configHomeDir and os.path.exists( configHomeDir): # check if a cache exists in this directory (e.g. from XPE or other tool) impliedAppDir = os.path.join(configHomeDir, "arelle") if os.path.exists(impliedAppDir): self.userAppDir = impliedAppDir elif os.path.exists(os.path.join(configHomeDir, "cache")): self.userAppDir = configHomeDir # use the XDG_CONFIG_HOME because cache is already a subdirectory else: self.userAppDir = impliedAppDir if sys.platform == "darwin": self.isMac = True self.isMSW = False if self.hasFileSystem and not configHomeDir: self.userAppDir = os.path.expanduser( "~") + "/Library/Application Support/Arelle" # note that cache is in ~/Library/Caches/Arelle self.contextMenuClick = "<Button-2>" self.hasClipboard = hasGui # clipboard always only if Gui (not command line mode) self.updateURL = "http://arelle.org/downloads/8" elif sys.platform.startswith("win"): self.isMac = False self.isMSW = True if self.hasFileSystem and not configHomeDir: tempDir = tempfile.gettempdir() if tempDir.lower().endswith('local\\temp'): impliedAppDir = tempDir[:-10] + 'local' else: impliedAppDir = tempDir self.userAppDir = os.path.join(impliedAppDir, "Arelle") if hasGui: 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 else: self.hasClipboard = False 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 if self.hasFileSystem and not configHomeDir: self.userAppDir = os.path.join(os.path.expanduser("~/.config"), "arelle") if hasGui: try: import gtk self.hasClipboard = True except ImportError: self.hasClipboard = False else: self.hasClipboard = False self.contextMenuClick = "<Button-3>" try: from arelle import webserver self.hasWebServer = True except ImportError: self.hasWebServer = False # assert that app dir must exist self.config = None if self.hasFileSystem: if not os.path.exists(self.userAppDir): os.makedirs(self.userAppDir) # load config if it exists self.configJsonFile = self.userAppDir + os.sep + "config.json" 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 self.setUiLanguage(self.config.get("userInterfaceLangOverride", None), fallbackToDefault=True) from arelle.WebCache import WebCache self.webCache = WebCache(self, self.config.get("proxySettings")) # start plug in server (requres web cache initialized, but not logger) PluginManager.init(self, loadPluginConfig=hasGui) # requires plug ins initialized self.modelManager = ModelManager.initialize(self) # start taxonomy package server (requres web cache initialized, but not logger) PackageManager.init(self, loadPackagesConfig=hasGui) self.startLogging(logFileName, logFileMode, logFileEncoding, logFormat) # Cntlr.Init after logging started for pluginMethod in PluginManager.pluginClassMethods("Cntlr.Init"): pluginMethod(self)
def __init__(self, hasGui=False, logFileName=None, logFileMode=None, logFileEncoding=None, logFormat=None): self.hasWin32gui = False self.hasGui = hasGui self.hasFileSystem = True # no file system on Google App Engine servers 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") self.pluginDir = os.path.join(resources, "plugin") 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") self.pluginDir = os.path.join(resources, "plugin") 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") self.pluginDir = os.path.join(self.moduleDir, "plugin") configHomeDir = os.getenv('XDG_CONFIG_HOME') if not configHomeDir: # look for path configDir/CONFIG_HOME configHomeDirFile = os.path.join(self.configDir, "XDG_CONFIG_HOME") if os.path.exists(configHomeDirFile): try: with io.open(configHomeDirFile, 'rt', encoding='utf-8') as f: configHomeDir = f.read().strip() if configHomeDir and not os.path.isabs(configHomeDir): configHomeDir = os.path.abspath( configHomeDir) # make into a full path if relative except EnvironmentError: configHomeDir = None if configHomeDir and os.path.exists(configHomeDir): # check if a cache exists in this directory (e.g. from XPE or other tool) impliedAppDir = os.path.join(configHomeDir, "arelle") if os.path.exists(impliedAppDir): self.userAppDir = impliedAppDir elif os.path.exists(os.path.join(configHomeDir, "cache")): self.userAppDir = configHomeDir # use the XDG_CONFIG_HOME because cache is already a subdirectory else: self.userAppDir = impliedAppDir if sys.platform == "darwin": self.isMac = True self.isMSW = False self.isGAE = False if not configHomeDir: self.userAppDir = os.path.expanduser( "~") + "/Library/Application Support/Arelle" # note that cache is in ~/Library/Caches/Arelle self.contextMenuClick = "<Button-2>" self.hasClipboard = hasGui # clipboard always only if Gui (not command line mode) self.updateURL = "http://arelle.org/downloads/8" elif sys.platform.startswith("win"): self.isMac = False self.isMSW = True self.isGAE = False if not configHomeDir: tempDir = tempfile.gettempdir() if tempDir.endswith('local\\temp'): impliedAppDir = tempDir[:-10] + 'local' else: impliedAppDir = tempDir self.userAppDir = os.path.join(impliedAppDir, "Arelle") if hasGui: 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 else: self.hasClipboard = False 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 serverSoftware = os.getenv("SERVER_SOFTWARE", "") if serverSoftware.startswith( "Google App Engine/") or serverSoftware.startswith( "Development/"): self.hasFileSystem = False # no file system, userAppDir does not exist self.isGAE = True elif not configHomeDir: self.userAppDir = os.path.join(os.path.expanduser("~/.config"), "arelle") self.isGAE = False if hasGui: try: import gtk self.hasClipboard = True except ImportError: self.hasClipboard = False else: self.hasClipboard = False self.contextMenuClick = "<Button-3>" try: from arelle import webserver self.hasWebServer = True except ImportError: self.hasWebServer = False # assert that app dir must exist self.config = None if self.hasFileSystem: if not os.path.exists(self.userAppDir): os.makedirs(self.userAppDir) # load config if it exists self.configJsonFile = self.userAppDir + os.sep + "config.json" 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 self.setUiLanguage(self.config.get("userInterfaceLangOverride", None), fallbackToDefault=True) 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, but not logger) PluginManager.init(self) self.startLogging(logFileName, logFileMode, logFileEncoding, logFormat) # Cntlr.Init after logging started for pluginMethod in PluginManager.pluginClassMethods("Cntlr.Init"): pluginMethod(self)