def _find_furl(self, profile='default', cluster_dir=None, furl_or_file=None, furl_file_name=None, ipython_dir=None): """Find a FURL file. If successful, this returns a FURL file that exists on the file system. The contents of the file have not been checked though. This is because we often have to deal with FURL file whose buffers have not been flushed. This raises an :exc:`~IPython.kernel.fcutil.FURLError` exception if a FURL file can't be found. This tries the following: 1. By the name ``furl_or_file``. 2. By ``cluster_dir`` and ``furl_file_name``. 3. By cluster profile with a default of ``default``. This uses ``ipython_dir``. """ # Try by furl_or_file if furl_or_file is not None: if is_valid_furl_or_file(furl_or_file): return furl_or_file if furl_file_name is None: raise FURLError('A furl_file_name must be provided if furl_or_file is not') # Try by cluster_dir if cluster_dir is not None: cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir) sdir = cluster_dir_obj.security_dir furl_file = os.path.join(sdir, furl_file_name) validate_furl_or_file(furl_file) return furl_file # Try by profile if ipython_dir is None: ipython_dir = get_ipython_dir() if profile is not None: cluster_dir_obj = ClusterDir.find_cluster_dir_by_profile( ipython_dir, profile) sdir = cluster_dir_obj.security_dir furl_file = os.path.join(sdir, furl_file_name) validate_furl_or_file(furl_file) return furl_file raise FURLError('Could not find a valid FURL file.')
def _setup_cluster_dir(self, profile, cluster_dir, ipython_dir, auto_create): if ipython_dir is None: ipython_dir = get_ipython_dir() if cluster_dir is not None: try: self.cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir) except ClusterDirError: pass if profile is not None: try: self.cluster_dir_obj = ClusterDir.find_cluster_dir_by_profile( ipython_dir, profile) except ClusterDirError: pass if auto_create or profile=='default': # This should call 'ipcluster create --profile default self.cluster_dir_obj = ClusterDir.create_cluster_dir_by_profile( ipython_dir, profile) else: raise ClusterDirError('Cluster dir not found.')