diff --git a/IPython/utils/path.py b/IPython/utils/path.py index bc0a16e..5b4a09c 100644 --- a/IPython/utils/path.py +++ b/IPython/utils/path.py @@ -476,3 +476,34 @@ def check_for_old_config(ipython_dir=None): IPython and want to suppress this warning message, set `c.InteractiveShellApp.ignore_old_config=True` in the new config.""") +def get_security_file(filename, profile='default'): + """Return the absolute path of a security file given by filename and profile + + This allows users and developers to find security files without + knowledge of the IPython directory structure. The search path + will be ['.', profile.security_dir] + + Parameters + ---------- + + filename : str + The file to be found. If it is passed as an absolute path, it will + simply be returned. + profile : str [default: 'default'] + The name of the profile to search. Leaving this unspecified + The file to be found. If it is passed as an absolute path, fname will + simply be returned. + + Returns + ------- + Raises :exc:`IOError` if file not found or returns absolute path to file. + """ + # import here, because profiledir also imports from utils.path + from IPython.core.profiledir import ProfileDir + try: + pd = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), profile) + except Exception: + # will raise ProfileDirError if no such profile + raise IOError("Profile %r not found") + return filefind(filename, ['.', pd.security_dir]) +