From e813eddb39ff509cc600582476d74438683b9aaa 2012-05-24 21:55:52 From: MinRK Date: 2012-05-24 21:55:52 Subject: [PATCH] add locate subcommands for IPython --- diff --git a/IPython/core/profileapp.py b/IPython/core/profileapp.py index 4520c4a..34215c8 100644 --- a/IPython/core/profileapp.py +++ b/IPython/core/profileapp.py @@ -85,6 +85,8 @@ ipython profile create foo --parallel # also stage parallel config files _main_examples = """ ipython profile create -h # show the help string for the create subcommand ipython profile list -h # show the help string for the list subcommand + +ipython profile locate foo # print the path to the directory for profile 'foo' """ #----------------------------------------------------------------------------- @@ -115,6 +117,18 @@ def list_bundled_profiles(): return profiles +class ProfileLocate(BaseIPythonApplication): + description = """print the path an IPython profile dir""" + + def parse_command_line(self, argv=None): + super(ProfileLocate, self).parse_command_line(argv) + if self.extra_args: + self.profile = self.extra_args[0] + + def start(self): + print self.profile_dir.location + + class ProfileList(Application): name = u'ipython-profile' description = list_help @@ -277,8 +291,9 @@ class ProfileApp(Application): examples = _main_examples subcommands = Dict(dict( - create = (ProfileCreate, "Create a new profile dir with default config files"), - list = (ProfileList, "List existing profiles") + create = (ProfileCreate, ProfileCreate.description.splitlines()[0]), + list = (ProfileList, ProfileList.description.splitlines()[0]), + locate = (ProfileLocate, ProfileLocate.description.splitlines()[0]), )) def start(self): diff --git a/IPython/frontend/terminal/ipapp.py b/IPython/frontend/terminal/ipapp.py index 638f243..68ff662 100755 --- a/IPython/frontend/terminal/ipapp.py +++ b/IPython/frontend/terminal/ipapp.py @@ -78,6 +78,9 @@ ipython help notebook # show the help for the notebook subcmd ipython profile create foo # create profile foo w/ default config files ipython help profile # show the help for the profile subcmd + +ipython locate # print the path to the IPython directory +ipython locate profile foo # print the path to the directory for profile `foo` """ #----------------------------------------------------------------------------- @@ -191,6 +194,21 @@ aliases.update(dict( # Main classes and functions #----------------------------------------------------------------------------- + +class LocateIPythonApp(BaseIPythonApplication): + description = """print the path to the IPython dir""" + subcommands = Dict(dict( + profile=('IPython.core.profileapp.ProfileLocate', + "print the path to an IPython profile directory", + ), + )) + def start(self): + if self.subapp is not None: + return self.subapp.start() + else: + print self.ipython_dir + + class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): name = u'ipython' description = usage.cl_usage @@ -230,6 +248,9 @@ class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): console=('IPython.frontend.terminal.console.app.ZMQTerminalIPythonApp', """Launch the IPython terminal-based Console.""" ), + locate=('IPython.frontend.terminal.ipapp.LocateIPythonApp', + LocateIPythonApp.description + ), )) # *do* autocreate requested profile, but don't create the config file.