def __init__(self, args): super(Application, self).__init__(args) QtWebEngineQuick.initialize() splash = QtWidgets.QSplashScreen( QtGui.QPixmap(resourcePath("vi/ui/res/logo_splash.png")) ) splash.show() if version.SNAPSHOT: QMessageBox.critical( splash, "Snapshot", "This is a snapshot release... Use as you will...." ) def change_splash_text(txt): if len(txt): splash.showMessage( f" {txt} ...", QtCore.Qt.AlignmentFlag.AlignLeft, QtGui.QColor(0x808000), ) # Set up paths chat_log_directory = "" if len(sys.argv) > 1: chat_log_directory = sys.argv[1] if not os.path.exists(chat_log_directory): change_splash_text("Searching for EVE Logs") if sys.platform.startswith("darwin"): chat_log_directory = os.path.join( os.path.expanduser("~"), "Documents", "EVE", "logs", "Chatlogs" ) if not os.path.exists(chat_log_directory): chat_log_directory = os.path.join( os.path.expanduser("~"), "Library", "Application Support", "Eve Online", "p_drive", "User", "My Documents", "EVE", "logs", "Chatlogs", ) elif sys.platform.startswith("linux"): chat_log_directory = os.path.join( os.path.expanduser("~"), "Documents", "EVE", "logs", "Chatlogs" ) elif sys.platform.startswith("win32") or sys.platform.startswith("cygwin"): import ctypes.wintypes buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH) ctypes.windll.shell32.SHGetFolderPathW(0, 0x05, 0, 0, buf) documents_path = buf.value chat_log_directory = os.path.join( documents_path, "EVE", "logs", "Chatlogs" ) # Now I need to just make sure... Some old pcs could still be on XP if not os.path.exists(chat_log_directory): chat_log_directory = os.path.join( os.path.expanduser("~"), "My Documents", "EVE", "logs", "Chatlogs", ) if not os.path.exists(chat_log_directory): chat_log_directory = QtWidgets.QFileDialog.getExistingDirectory( None, caption="Select EVE Online chat logfiles directory", directory=chat_log_directory, ) if not os.path.exists(chat_log_directory): # None of the paths for logs exist, bailing out QMessageBox.critical( splash, "No path to Logs", "No logs found at: " + chat_log_directory, QMessageBox.Close, ) sys.exit(1) # Setting local directory for cache and logging change_splash_text("Setting Spyglass Directories") spyglass_dir = os.path.join( os.path.dirname(os.path.dirname(chat_log_directory)), "spyglass" ) if not os.path.exists(spyglass_dir): os.mkdir(spyglass_dir) cache.Cache.PATH_TO_CACHE = os.path.join(spyglass_dir, "cache-2.sqlite3") spyglass_log_directory = os.path.join(spyglass_dir, "logs") if not os.path.exists(spyglass_log_directory): os.mkdir(spyglass_log_directory) change_splash_text("Connecting to Cache") spyglass_cache = Cache() log_level = spyglass_cache.getFromCache("logging_level") if not log_level: log_level = logging.WARN if version.SNAPSHOT: log_level = logging.DEBUG # For Testing BACKGROUND_COLOR = spyglass_cache.getFromCache("background_color") if BACKGROUND_COLOR: self.setStyleSheet(f"background-color: {BACKGROUND_COLOR};") css = Styles().getStyle() self.setStyleSheet(css) del css # Setup logging for console and rotated log files formatter = logging.Formatter( "%(asctime)s| %(message)s", datefmt="%m/%d %I:%M:%S" ) root_logger = logging.getLogger() root_logger.setLevel(level=log_level) log_filename = spyglass_log_directory + "/output.log" file_handler = RotatingFileHandler( maxBytes=(1048576 * 5), backupCount=7, filename=log_filename, mode="a" ) file_handler.setFormatter(formatter) root_logger.addHandler(file_handler) console_handler = StreamHandler() console_handler.setFormatter(formatter) root_logger.addHandler(console_handler) logging.critical("") logging.critical( "------------------- Spyglass %s starting up -------------------", version.VERSION, ) logging.critical("") logging.critical(" Looking for chat logs at: %s", chat_log_directory) logging.critical( " Cache maintained here: %s", cache.Cache.PATH_TO_CACHE ) logging.critical(" Writing logs to: %s", spyglass_log_directory) tray_icon = systemtray.TrayIcon(self) tray_icon.show() self.main_window = viui.MainWindow( chat_log_directory, tray_icon, change_splash_text ) self.main_window.show() self.main_window.raise_()
def main(): FORMAT = '%(asctime)-15s %(filename)s L%(lineno)d %(funcName)s: %(message)s' logging.basicConfig(level=logging.FATAL, format=FORMAT, datefmt='%d.%m.%Y %H:%M:%S') global error_file splash = QtWidgets.QSplashScreen( QtGui.QPixmap(resource_path("vi/ui/res/logo.png"))) splash.show() app.processEvents() PATH_TO_LOGS = None # did we have a manuel path to the logs as an argument at start? if len(sys.argv) > 1: PATH_TO_LOGS = sys.argv[1] print("Try to find Logdir @:", PATH_TO_LOGS) # Path to Chatlogs on Linux System using wine if not PATH_TO_LOGS or not os.path.exists(PATH_TO_LOGS): print("Going on find logdir...") PATH_TO_LOGS = os.path.join(os.path.expanduser("~"), "EVE", "logs", "Chatlogs") print("Try to find Logdir @:", PATH_TO_LOGS) # Path to Chatlogs on MacOS if not os.path.exists(PATH_TO_LOGS): print("No logdir @:", PATH_TO_LOGS) PATH_TO_LOGS = os.path.join(os.path.expanduser("~"), "Library", "Application Support", "Eve Online", "p_drive", "User", "My Documents", "EVE", "logs", "Chatlogs") print("Try to find Logdir @:", PATH_TO_LOGS) # Path to chatlogs on windows if not os.path.exists(PATH_TO_LOGS): print("No logdir @: ", PATH_TO_LOGS) CSIDL_PERSONAL = 5 SHGFP_TYPE_CURRENT = 0 buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH) ctypes.windll.shell32.SHGetFolderPathW(0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, buf) documents_path = buf.value print("Documents path? :", documents_path) PATH_TO_LOGS = os.path.join(documents_path, "EVE", "logs", "Chatlogs") # None of the pathes for logs exists? So we can not work, sorry if not os.path.exists(PATH_TO_LOGS): QtWidgets.QMessageBox.critical( None, "No path to Logs", "Vintel could not find the directory where the EvE chatlogs are stored. Sorry.", QtWidgets.QMessageBox.Close) sys.exit(1) print("I expect logs @:", PATH_TO_LOGS) # setting local working directory for cache, etc. # datadir = os.path.join(os.path.expanduser("~"), "EVE", "vintel") datadir = os.path.join(os.path.dirname(os.path.dirname(PATH_TO_LOGS)), "vintel") if not os.path.exists(datadir): os.mkdir(datadir) print("Vintel writes data in :", datadir) cache.Cache.PATH_TO_CACHE = os.path.join(datadir, "cache.sqlite3") error_file = os.path.join(datadir, "error.log") trayicon = systemtray.TrayIcon(app) trayicon.setContextMenu(systemtray.TrayContextMenu(trayicon)) trayicon.show() mw = viui.MainWindow(PATH_TO_LOGS, trayicon) mw.show() splash.finish(mw) app.exec() app.quit()
def __init__(self, args): super(Application, self).__init__(args) # Set up paths chatLogDirectory = "" if len(sys.argv) > 1: chatLogDirectory = sys.argv[1] if not os.path.exists(chatLogDirectory): if sys.platform.startswith("darwin"): chatLogDirectory = os.path.join(os.path.expanduser("~"), "Documents", "EVE", "logs", "Chatlogs") if not os.path.exists(chatLogDirectory): chatLogDirectory = os.path.join(os.path.expanduser("~"), "Library", "Application Support", "Eve Online", "p_drive", "User", "My Documents", "EVE", "logs", "Chatlogs") elif sys.platform.startswith("linux"): chatLogDirectory = os.path.join(os.path.expanduser("~"), "EVE", "logs", "Chatlogs") elif sys.platform.startswith("win32") or sys.platform.startswith( "cygwin"): import ctypes.wintypes buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH) ctypes.windll.shell32.SHGetFolderPathW(0, 5, 0, 0, buf) documentsPath = buf.value chatLogDirectory = os.path.join(documentsPath, "EVE", "logs", "Chatlogs") if not os.path.exists(chatLogDirectory): # None of the paths for logs exist, bailing out QMessageBox.critical(None, "No path to Logs", "No logs found at: " + chatLogDirectory, "Quit") sys.exit(1) # Setting local directory for cache and logging vintelDirectory = os.path.join( os.path.dirname(os.path.dirname(chatLogDirectory)), "vintel") if not os.path.exists(vintelDirectory): os.mkdir(vintelDirectory) cache.Cache.PATH_TO_CACHE = os.path.join(vintelDirectory, "cache-2.sqlite3") vintelLogDirectory = os.path.join(vintelDirectory, "logs") if not os.path.exists(vintelLogDirectory): os.mkdir(vintelLogDirectory) splash = QtGui.QSplashScreen( QtGui.QPixmap(resourcePath("vi/ui/res/logo.png"))) vintelCache = Cache() logLevel = vintelCache.getFromCache("logging_level") if not logLevel: logLevel = logging.WARN backGroundColor = vintelCache.getFromCache("background_color") if backGroundColor: self.setStyleSheet("QWidget { background-color: %s; }" % backGroundColor) splash.show() self.processEvents() # Setup logging for console and rotated log files formatter = logging.Formatter('%(asctime)s| %(message)s', datefmt='%m/%d %I:%M:%S') rootLogger = logging.getLogger() rootLogger.setLevel(level=logLevel) logFilename = vintelLogDirectory + "/output.log" fileHandler = RotatingFileHandler(maxBytes=(1048576 * 5), backupCount=7, filename=logFilename, mode='a') fileHandler.setFormatter(formatter) rootLogger.addHandler(fileHandler) consoleHandler = StreamHandler() consoleHandler.setFormatter(formatter) rootLogger.addHandler(consoleHandler) logging.critical("") logging.critical( "------------------- Vintel %s starting up -------------------", version.VERSION) logging.critical("") logging.debug("Looking for chat logs at: %s", chatLogDirectory) logging.debug("Cache maintained here: %s", cache.Cache.PATH_TO_CACHE) logging.debug("Writing logs to: %s", vintelLogDirectory) trayIcon = systemtray.TrayIcon(self) trayIcon.show() self.mainWindow = viui.MainWindow(chatLogDirectory, trayIcon, backGroundColor) self.mainWindow.show() self.mainWindow.raise_() splash.finish(self.mainWindow)
logFilename = vintelLogDirectory + "/output.log" fileHandler = RotatingFileHandler(maxBytes=(1048576 * 5), backupCount=7, filename=logFilename, mode='a') fileHandler.setFormatter(formatter) rootLogger.addHandler(fileHandler) consoleHandler = StreamHandler() consoleHandler.setFormatter(formatter) rootLogger.addHandler(consoleHandler) logging.critical("") logging.critical( "------------------- Vintel %s starting up -------------------", version.VERSION) logging.critical("") logging.debug("Looking for chat logs at: %s", chatLogDirectory) logging.debug("Cache maintained here: %s", cache.Cache.PATH_TO_CACHE) logging.debug("Writing logs to: %s", vintelLogDirectory) trayIcon = systemtray.TrayIcon(app) trayIcon.setContextMenu(systemtray.TrayContextMenu(trayIcon)) trayIcon.show() mainWindow = viui.MainWindow(chatLogDirectory, trayIcon, backGroundColor) mainWindow.show() splash.finish(mainWindow) sys.exit(app.exec_())