Logo Search packages:      
Sourcecode: ranger version File versions  Download package

def ranger::core::runner::Runner::__call__ (   self,
  action = None,
  try_app_first = False,
  app = 'default',
  files = None,
  mode = 0,
  flags = '',
  wait = True,
  popen_kws 
)
Run the application in the way specified by the options.

Returns False if nothing can be done, None if there was an error,
otherwise the process object returned by Popen().

This function tries to find an action if none is defined.

Definition at line 117 of file runner.py.

                                                   :
            """
            Run the application in the way specified by the options.

            Returns False if nothing can be done, None if there was an error,
            otherwise the process object returned by Popen().

            This function tries to find an action if none is defined.
            """

            # Find an action if none was supplied by
            # creating a Context object and passing it to
            # an Application object.

            context = Context(app=app, files=files, mode=mode,
                        flags=flags, wait=wait, popen_kws=popen_kws,
                        file=files and files[0] or None)

            if self.apps:
                  if try_app_first and action is not None:
                        test = self.apps.apply(app, context)
                        if test:
                              action = test
                  if action is None:
                        action = self.apps.apply(app, context)
                        if action is None:
                              return self._log("No action found!")

            if action is None:
                  return self._log("No way of determining the action!")

            # Preconditions

            context.squash_flags()
            popen_kws = context.popen_kws  # shortcut

            toggle_ui = True
            pipe_output = False
            wait_for_enter = False
            devnull = None

            popen_kws['args'] = action
            if 'shell' not in popen_kws:
                  popen_kws['shell'] = isinstance(action, str)
            if 'stdout' not in popen_kws:
                  popen_kws['stdout'] = sys.stdout
            if 'stderr' not in popen_kws:
                  popen_kws['stderr'] = sys.stderr

            # Evaluate the flags to determine keywords
            # for Popen() and other variables

            if 'p' in context.flags:
                  popen_kws['stdout'] = PIPE
                  popen_kws['stderr'] = PIPE
                  toggle_ui = False
                  pipe_output = True
                  context.wait = False
            if 's' in context.flags or 'd' in context.flags:
                  devnull_writable = open(os.devnull, 'w')
                  devnull_readable = open(os.devnull, 'r')
                  for key in ('stdout', 'stderr'):
                        popen_kws[key] = devnull_writable
                  popen_kws['stdin'] = devnull_readable
            if 'd' in context.flags:
                  toggle_ui = False
                  context.wait = False
            if 'w' in context.flags:
                  if not pipe_output and context.wait: # <-- sanity check
                        wait_for_enter = True

            # Finally, run it

            if toggle_ui:
                  self._activate_ui(False)
            try:
                  process = None
                  try:
                        process = Popen(**popen_kws)
                  except Exception as e:
                        self._log("Failed to run: " + str(action))
                  else:
                        if context.wait:
                              waitpid_no_intr(process.pid)
                        if wait_for_enter:
                              press_enter()
            finally:
                  if devnull:
                        devnull.close()
                  if toggle_ui:
                        self._activate_ui(True)
                  if pipe_output and process:
                        return self(action='less', app='pager', try_app_first=True,
                                    stdin=process.stdout)
                  return process

Generated by  Doxygen 1.6.0   Back to index