def read(cls, filepath=None): if filepath is None: filepath = os.path.join(get_config_dir(), cls.DEFAULT_FILENAME) if not os.path.exists(filepath): return cls() return super().read(filepath)
def setUp(self): super().setUp() # Exchange settings.h5 self.filepath = os.path.join(get_config_dir(), Settings.DEFAULT_FILENAME) if os.path.exists(self.filepath): self.filepath_backup = self.filepath + '.backup' os.rename(self.filepath, self.filepath_backup) else: self.filepath_backup = None settings = Settings() settings.write(self.filepath)
def write(self, filepath=None): if filepath is None: filepath = os.path.join(get_config_dir(), self.DEFAULT_FILENAME) return super().write(filepath)
def _setup(ns): # Configuration directory configdir = get_config_dir() frozen = getattr(sys, "frozen", False) # Redirect stdout and stderr when frozen if frozen: filepath = os.path.join(configdir, "pymontecarlo.stdout") sys.stdout = open(filepath, "w") # NOTE: Important since warnings required sys.stderr not be None filepath = os.path.join(configdir, "pymontecarlo.stderr") sys.stderr = open(filepath, "w") # Logging logger = logging.getLogger() logger.setLevel(logging.DEBUG if ns.verbose else logging.INFO) fmt = "%(asctime)s - %(levelname)s - %(module)s - %(lineno)d: %(message)s" formatter = logging.Formatter(fmt) handler = logging.FileHandler(os.path.join(configdir, "pymontecarlo.log"), "w") handler.setFormatter(formatter) logger.addHandler(handler) if not frozen: handler = logging.StreamHandler() handler.setFormatter(formatter) logger.addHandler(handler) logger.info("Started pyMonteCarlo") logger.info("pymontecarlo version = %s", pymontecarlo.__version__) logger.info("pymontecarlo-gui version = %s", pymontecarlo_gui.__version__) logger.info("operating system = %s %s", platform.system(), platform.release()) logger.info("machine = %s", platform.machine()) logger.info("processor = %s", platform.processor()) logger.info("qt = %s", QtCore.__version__) # Log plugins for name in sorted(pymontecarlo.pymontecarlo_plugins): logger.info("Found plug-in: {}".format(name)) # Log entities entities = [] for clasz in EntityBase._subclasses: entities.append("{}.{}".format(clasz.__module__, clasz.__name__)) for clasz in ProgramFieldBase._subclasses: entities.append("{}.{}".format(clasz.__module__, clasz.__name__)) for entity in sorted(entities): logger.info("Registered entity: {}".format(entity)) # Catch all exceptions def _excepthook(exc_type, exc_obj, exc_tb): sys.__excepthook__(exc_type, exc_obj, exc_tb) messagebox.exception(None, exc_obj) sys.excepthook = _excepthook # Output sys.path logger.info("sys.path = %s", sys.path) # Output environment variables logger.info("ENVIRON = %s" % os.environ) # Change app id on Windows # https://stackoverflow.com/questions/1551605/how-to-set-applications-taskbar-icon-in-windows-7 if sys.platform == "win32": myappid = "com.github.pymontecarlo.main" # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)