Exemple #1
0
def CMDsearch(parser):
    """Search for a file"""
    if prelaunch.is_prelaunched_process() and (
            not message_loop.supports_prelaunch()):
        print "Prelaunching not available for current UI."
        return 255

    parser.add_option('--ok',
                      dest='ok',
                      action='store_true',
                      default=False,
                      help='Output "OK" before results')
    parser.add_option('--lisp-results',
                      dest='lisp_results',
                      action='store_true',
                      default=False,
                      help='Output results as a lisp-formatted list')
    parser.add_option(
        '--results-file',
        dest='results_file',
        action='store',
        help='Output results to the provided file instead of stdout')
    parser.add_option('--skip-ui-if-exact-match',
                      dest='skip_if_exact',
                      action='store_true',
                      default=False,
                      help="Don't show UI if there's an exact match")
    parser.add_option(
        '--only-if-exact-match',
        dest='only_if_exact',
        action='store_true',
        default=False,
        help="Print only if there is an exact match, nothing otherwise")
    parser.add_option(
        '--current-filename',
        dest='current_filename',
        action='store',
        default=None,
        help=
        "Hints quickopen about the current buffer to improve search relevance."
    )
    parser.add_option(
        '--open-filenames',
        dest='open_filenames',
        action='store',
        default=[],
        help=
        "Hints quickopen about the filenames currently open to improve search relevance."
    )
    (options, args) = parser.parse_args()

    message_loop.ensure_has_message_loop()

    if not trace_is_enabled() and options.trace:
        trace_enable("%s.trace" % sys.argv[0])
    db = open_db(options)

    def print_results(res, canceled):
        if options.ok and not canceled:
            print "OK"

        if options.results_file:
            ofile = open(options.results_file, 'w')
        else:
            ofile = sys.stdout

        if options.lisp_results:
            ofile.write("(%s)\n" % (" ".join(['"%s"' % x for x in res])))
        else:
            ofile.write("\n".join(res))
        ofile.write("\n")

        if options.results_file:
            ofile.close()

    search_args = {}
    if options.current_filename:
        search_args["current_filename"] = options.current_filename
    if options.open_filenames:
        # Switch the options to the parsed form so the open dialog can use it directly.
        options.open_filenames = split_open_filenames(options.open_filenames)
        search_args["open_filenames"] = options.open_filenames
    # FIXME: Modify emacs to not use this option anymore and then remove it.
    if options.skip_if_exact:
        res = db.search(args[0], exact_match=True, **search_args)
        if len(res.filenames) == 1:
            print_results(res.filenames, False)
            return 0
    if options.only_if_exact:
        res = db.search(args[0], exact_match=True, **search_args)
        if len(res.filenames) == 1:
            print_results(res.filenames, False)
        return 0

    if len(args):
        initial_filter = " ".join(args)
    else:
        initial_filter = None

    from src import open_dialog
    open_dialog.run(options, db, initial_filter,
                    print_results)  # will not return on osx.
def CMDsearch(parser):
  """Search for a file"""
  if prelaunch.is_prelaunched_process() and (
    not message_loop.supports_prelaunch()):
    print "Prelaunching not available for current UI."
    return 255

  parser.add_option('--ok', dest='ok', action='store_true', default=False, help='Output "OK" before results')
  parser.add_option('--lisp-results', dest='lisp_results', action='store_true', default=False, help='Output results as a lisp-formatted list')
  parser.add_option('--results-file', dest='results_file', action='store', help='Output results to the provided file instead of stdout')
  parser.add_option('--skip-ui-if-exact-match', dest='skip_if_exact', action='store_true', default=False, help="Don't show UI if there's an exact match")
  parser.add_option('--only-if-exact-match', dest='only_if_exact', action='store_true', default=False, help="Print only if there is an exact match, nothing otherwise")
  parser.add_option('--current-filename', dest='current_filename', action='store', default=None, help="Hints quickopen about the current buffer to improve search relevance.")
  parser.add_option('--open-filenames', dest='open_filenames', action='store', default=[], help="Hints quickopen about the filenames currently open to improve search relevance.")
  (options, args) = parser.parse_args()

  message_loop.ensure_has_message_loop()

  if not trace_is_enabled() and options.trace:
    trace_enable("%s.trace" % sys.argv[0])
  db = open_db(options)

  def print_results(res, canceled):
    if options.ok and not canceled:
      print "OK"

    if options.results_file:
      ofile = open(options.results_file, 'w')
    else:
      ofile = sys.stdout

    if options.lisp_results:
      ofile.write("(%s)\n" % (" ".join(['"%s"' % x for x in res])))
    else:
      ofile.write("\n".join(res))
    ofile.write("\n")

    if options.results_file:
      ofile.close()

  search_args = {}
  if options.current_filename:
    search_args["current_filename"] = options.current_filename
  if options.open_filenames:
    # Switch the options to the parsed form so the open dialog can use it directly.
    options.open_filenames = split_open_filenames(options.open_filenames)
    search_args["open_filenames"] = options.open_filenames
  # FIXME: Modify emacs to not use this option anymore and then remove it.
  if options.skip_if_exact:
    res = db.search(args[0], exact_match=True, **search_args)
    if len(res.filenames) == 1:
      print_results(res.filenames, False)
      return 0
  if options.only_if_exact:
    res = db.search(args[0], exact_match=True, **search_args)
    if len(res.filenames) == 1:
      print_results(res.filenames, False)
    return 0

  if len(args):
    initial_filter = " ".join(args)
  else:
    initial_filter = None

  import src.open_dialog as open_dialog
  open_dialog.run(options, db, initial_filter, print_results) # will not return on osx.
Exemple #3
0
def main(main_name):
    """The main entry point to the bootstrapper. Call this with the module name to
  use as your main app."""
    # prelaunch should bypass full bootstrap
    if prelaunch_client.is_prelaunch_client(sys.argv):
        # This is a lightweight import due to lazy initialization of the message loop.
        import message_loop
        if message_loop.supports_prelaunch():
            return sys.exit(prelaunch_client.main(sys.argv))

        # Remove the prelaunch command from the argv and proceed as normal.
        prelaunch_client.remove_prelaunch_from_sys_argv()

    if sys.platform == 'darwin':
        if ('--chrome' in sys.argv):
            sys.argv.insert(1, '--main-name')
            sys.argv.insert(2, main_name)
            sys.exit(run())

        if ('--curses' in sys.argv):
            sys.argv.insert(1, '--main-name')
            sys.argv.insert(2, main_name)
            sys.exit(run())

        # Try using chrome.
        import message_loop_chrome
        if message_loop_chrome.supported():
            sys.argv.insert(1, '--main-name')
            sys.argv.insert(2, main_name)
            sys.exit(run())

        # To use wx-widgets on darwin, we need to be in 32 bit mode. Import of wx
        # will fail if you run python in 64 bit mode, which is default in 10.6+. :'(
        # It is depressingly hard to force python into 32 bit mode reliably across
        # computers, for some reason. So, we try two approaches known to work... one
        # after the other.
        wx_found_but_failed = False
        try:
            import wx
        except ImportError:
            if str(sys.exc_value).find("no appropriate 64-bit") != -1:
                wx_found_but_failed = True

        if wx_found_but_failed:
            # Switch the executable to /usr/bin/python2.6 if we are implicitly running
            # 2.6 via /usr/bin/python. For some reason, neither the arch trick nor the
            # env trick work if you use /usr/bin/python
            if sys.version.startswith(
                    "2.6") and sys.executable == '/usr/bin/python':
                if os.path.exists('/usr/bin/python2.6'):
                    executable = '/usr/bin/python2.6'
                else:
                    executable = sys.executable
            else:
                executable = sys.executable

            # try using the versioner trick
            if '--triedenv' not in sys.argv:
                os.putenv('VERSIONER_PYTHON_PREFER_32_BIT', 'yes')
                args = [executable, sys.argv[0], '--triedenv']
                args.extend(sys.argv[1:])
                os.execve(args[0], args, os.environ)

            # last chance...
            if '--triedarch' not in sys.argv:
                args = [
                    "/usr/bin/arch", "-i386", executable, sys.argv[0],
                    '--triedarch'
                ]
                args.extend(sys.argv[1:])
                os.execv(args[0], args)

            # did we already try one of the tricks below? Bail out to prevent recursion...
            print "Your system's python is 64 bit, and all the tricks we know to get it into 32b mode failed."
            sys.exit(255)

        else:
            try:
                sys.argv.remove('--triedenv')
            except:
                pass
            try:
                sys.argv.remove('--triedarch')
            except:
                pass
            sys.argv.insert(1, '--main-name')
            sys.argv.insert(2, main_name)
            sys.exit(run())

    else:
        sys.argv.insert(1, '--main-name')
        sys.argv.insert(2, main_name)
        sys.exit(run())
Exemple #4
0
def main(main_name):
  """The main entry point to the bootstrapper. Call this with the module name to
  use as your main app."""
  # prelaunch should bypass full bootstrap
  if prelaunch_client.is_prelaunch_client(sys.argv):
    # This is a lightweight import due to lazy initialization of the message loop.
    import message_loop
    if message_loop.supports_prelaunch():
      return sys.exit(prelaunch_client.main(sys.argv))

    # Remove the prelaunch command from the argv and proceed as normal.
    prelaunch_client.remove_prelaunch_from_sys_argv()

  if sys.platform == 'darwin':
    if ('--chrome' in sys.argv):
      sys.argv.insert(1, '--main-name')
      sys.argv.insert(2, main_name)
      sys.exit(run())

    if ('--curses' in sys.argv):
      sys.argv.insert(1, '--main-name')
      sys.argv.insert(2, main_name)
      sys.exit(run())

    # Try using chrome.
    import message_loop_chrome
    if message_loop_chrome.supported():
      sys.argv.insert(1, '--main-name')
      sys.argv.insert(2, main_name)
      sys.exit(run())

    # To use wx-widgets on darwin, we need to be in 32 bit mode. Import of wx
    # will fail if you run python in 64 bit mode, which is default in 10.6+. :'(
    # It is depressingly hard to force python into 32 bit mode reliably across
    # computers, for some reason. So, we try two approaches known to work... one
    # after the other.
    wx_found_but_failed = False
    try:
      import wx
    except ImportError:
      if str(sys.exc_value).find("no appropriate 64-bit") != -1:
        wx_found_but_failed = True

    if wx_found_but_failed:
      # Switch the executable to /usr/bin/python2.6 if we are implicitly running
      # 2.6 via /usr/bin/python. For some reason, neither the arch trick nor the
      # env trick work if you use /usr/bin/python
      if sys.version.startswith("2.6") and sys.executable == '/usr/bin/python':
        if os.path.exists('/usr/bin/python2.6'):
          executable = '/usr/bin/python2.6'
        else:
          executable = sys.executable
      else:
        executable = sys.executable

      # try using the versioner trick
      if '--triedenv' not in sys.argv:
        os.putenv('VERSIONER_PYTHON_PREFER_32_BIT', 'yes')
        args = [executable, sys.argv[0], '--triedenv']
        args.extend(sys.argv[1:])
        os.execve(args[0], args, os.environ)

      # last chance...
      if '--triedarch' not in sys.argv:
        args = ["/usr/bin/arch", "-i386", executable, sys.argv[0], '--triedarch']
        args.extend(sys.argv[1:])
        os.execv(args[0], args)

      # did we already try one of the tricks below? Bail out to prevent recursion...
      print "Your system's python is 64 bit, and all the tricks we know to get it into 32b mode failed."
      sys.exit(255)

    else:
      try:
        sys.argv.remove('--triedenv')
      except:
        pass
      try:
        sys.argv.remove('--triedarch')
      except:
        pass
      sys.argv.insert(1, '--main-name')
      sys.argv.insert(2, main_name)
      sys.exit(run())

  else:
    sys.argv.insert(1, '--main-name')
    sys.argv.insert(2, main_name)
    sys.exit(run())