def update_settings(self, args): """ Update settings. Args: args (Namespace): parsed arguments to hold customized parameters. """ if args.port is None: args.port = settings.PORT pid, workspace = self.get_process(args.port) setattr(args, 'pid', pid) os.environ['MINDINSIGHT_PORT'] = str(args.port) os.environ['MINDINSIGHT_WORKSPACE'] = workspace settings.refresh()
def init(workspace='', config='', **kwargs): """ Init MindInsight context. Args: workspace (str): specify mindinsight workspace, default is ''. config (str): specify mindinsight config file, default is ''. Raises: FileSystemPermissionError, if workspace is not allowed to access or available. """ permissions = os.R_OK | os.W_OK | os.X_OK # set umask to 0o077 os.umask(permissions << 3 | permissions) # assign argument values into environment if workspace: kwargs['workspace'] = workspace if config: kwargs['config'] = config for key, value in kwargs.items(): variable = 'MINDINSIGHT_{}'.format(key.upper()) os.environ[variable] = str(value) settings.refresh() if os.path.exists(settings.WORKSPACE): if not os.access(settings.WORKSPACE, permissions): raise FileSystemPermissionError( 'Workspace {} not allowed to access'.format(workspace)) else: try: mode = permissions << 6 os.makedirs(settings.WORKSPACE, mode=mode, exist_ok=True) except OSError: # race condition or priority problem raise FileSystemPermissionError( 'Workspace {} not available'.format(workspace)) for hook in HookUtils.instance().hooks(): hook.on_init()