Skip to content

Commit

Permalink
another useful metadata diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Sep 21, 2018
1 parent ef8fc43 commit ad88bf8
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions APS_BlueSky_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
~ExcelDatabaseFileBase
~ExcelDatabaseFileGeneric
~ipython_profile_name
~text_encode
~to_unicode_or_bust
"""

Expand All @@ -20,9 +23,7 @@


def text_encode(source):
"""
encode ``source`` using the default codepoint
"""
"""encode ``source`` using the default codepoint"""
return source.encode(errors='ignore')


Expand Down Expand Up @@ -137,3 +138,25 @@ def handleExcelRowEntry(self, entry):
key = str(self._index_)
self.db[key] = entry
self._index_ += 1


def ipython_profile_name():
"""
return the name of the current ipython profile or `None`
Example (add to default RunEngine metadata)::
RE.md['ipython_profile'] = str(ipython_profile_name())
print("using profile: " + RE.md['ipython_profile'])
"""
import IPython.paths
import IPython.core.profileapp
import IPython.core.profiledir

path = IPython.paths.get_ipython_dir()
ipd = IPython.core.profiledir.ProfileDir()
for p in IPython.core.profileapp.list_profiles_in(path):
pd = ipd.find_profile_dir_by_name(path, p)
if os.path.dirname(__file__) == pd.startup_dir:
return p

0 comments on commit ad88bf8

Please sign in to comment.