示例#1
0
def run_command_in_existing(daemon_host, daemon_port, args):
    # Prelaunched processes are DISPLAY-specific
    if sys.platform == "darwin":
        if os.getenv("DISPLAY"):
            display = os.getenv("DISPLAY")
        else:
            display = "cocoa"
    else:
        if os.getenv("DISPLAY"):
            display = os.getenv("DISPLAY")
        else:
            display = "terminal"

    # Get the pid of an existing quickopen process via
    # quickopend. This routes through prelaunchd.py
    conn = httplib.HTTPConnection(daemon_host, daemon_port, True)
    try:
        conn.request("GET", "/existing_quickopen/%s" % display)
    except socket.error:
        from db_status import DBStatus

        return "%s.\n" % DBStatus.not_running_string()

    res = conn.getresponse()
    assert res.status == 200
    port = int(res.read())

    # Get a connection to the prelaunched process.
    # We may have to try a few times --- it may be coming up still.
    connected = False
    s = None
    for i in range(20):  # 5 seconds
        try:
            s = socket.socket()
            s.connect(("localhost", port))
            break
        except:
            time.sleep(0.25)
    if not s:
        raise Exception("Could not connect to the provided process.")
    try:
        f = s.makefile()

        # Send our commandline to the existing quickopend. Pass with it our
        # daemon_host and daemon_port so that it tries talking to the same quickopend
        # instance as us.
        full_args = list(args)
        full_args.extend(["--host", daemon_host])
        full_args.extend(["--port", str(daemon_port)])
        f.write(repr(full_args))
        f.write("\n")
        f.flush()

        # Wait for the result of the quickopening. It comes over as a repr'd string
        # so eval it to get the real multi-line string.
        l = eval(f.readline(), {}, {})
        return l
    finally:
        s.close()
示例#2
0
def CMDreindex(parser):
  """Begins to reindex the quickopen database"""
  (options, args) = parser.parse_args()
  db = open_db(options)
  try:
    db.begin_reindex()
    print "Reindexing has begun."
  except IOError:
    print "%s." % DBStatus.not_running_string()
示例#3
0
def CMDreindex(parser):
    """Begins to reindex the quickopen database"""
    (options, args) = parser.parse_args()
    db = open_db(options)
    try:
        db.begin_reindex()
        print "Reindexing has begun."
    except IOError:
        print "%s." % DBStatus.not_running_string()
示例#4
0
文件: db.py 项目: danakj/quickopen
  def status(self):
    if self._pending_indexer:
      if isinstance(self._pending_indexer, DBIndexer): # is an integer briefly between _set_dirty and first step_indexer
        if self._cur_shard_manager:
          status = "syncing: %s, %s" % (self._pending_indexer.progress, self._cur_shard_manager.status)
        else:
          status = "first-time sync: %s" % self._pending_indexer.progress
      else:
        status = "sync scheduled"
    else:
      if self._cur_shard_manager:
        status = "up-to-date: %s" % self._cur_shard_manager.status
      else:
        status = "sync required"

    res = DBStatus()
    res.is_up_to_date = self.is_up_to_date
    res.has_index = self.has_index
    res.status = status
    return res
示例#5
0
文件: db.py 项目: zqureshi/quickopen
    def status(self):
        if self._pending_indexer:
            # Is an integer briefly between _set_dirty and first step_indexer
            if not isinstance(self._pending_indexer, int):
                if self._cur_shard_manager:
                    status = "syncing: %s, %s" % (
                        self._pending_indexer.progress,
                        self._cur_shard_manager.status)
                else:
                    status = "first-time sync: %s" % self._pending_indexer.progress
            else:
                status = "sync scheduled"
        else:
            if self._cur_shard_manager:
                status = "up-to-date: %s" % self._cur_shard_manager.status
            else:
                status = "sync required"

        res = DBStatus()
        res.is_up_to_date = self.is_up_to_date
        res.has_index = self.has_index
        res.status = status
        return res
示例#6
0
    def __init__(self, options, db, initial_filter=None):
        self._filter_text = ""
        if initial_filter:
            self._filter_text = initial_filter
        self._db = db
        self._frontend_status = None
        self._backend_status = DBStatus()
        self._can_process_queries = False
        self._db_is_up_to_date = True
        self._last_search_query = None
        self._pending_search = None
        self._options = options
        self._print_results_cb = None
        if initial_filter:
            self.should_position_cursor_for_replace = False
        else:
            self.should_position_cursor_for_replace = True

        # First tick should be fast.
        message_loop.post_delayed_task(self.on_tick, 0)
示例#7
0
def run_command_in_existing(daemon_host, daemon_port, args, auto_start=True):
    # Prelaunched processes are DISPLAY-specific
    if sys.platform == 'darwin':
        if os.getenv('DISPLAY'):
            display = os.getenv('DISPLAY')
        else:
            display = 'cocoa'
    else:
        if os.getenv('DISPLAY'):
            display = os.getenv('DISPLAY')
        else:
            display = 'terminal'

    def existing_quickopen_port():
        conn = httplib.HTTPConnection(daemon_host, daemon_port, True)
        conn.request('GET', '/existing_quickopen/%s' % display)
        res = conn.getresponse()
        assert res.status == 200
        port = int(res.read())
        return port

    # Get the pid of an existing quickopen process via
    # quickopend. This routes through prelaunchd.py
    try:
        port = existing_quickopen_port()
    except socket.error:
        if not auto_start:
            from db_status import DBStatus
            return "%s.\n" % DBStatus.not_running_string()

        # quickopend not started; attempt once to start it automatically
        import StringIO
        try:
            # Squelch any output from starting the db
            orig_stdout = sys.stdout
            orig_stderr = sys.stderr
            sys.stdout = StringIO.StringIO()
            sys.stderr = sys.stdout

            sys.path.append(
                os.path.join(os.path.dirname(__file__),
                             "../third_party/py_trace_event/"))
            import db_proxy
            db_proxy.DBProxy.try_to_start_quickopend(daemon_port)
            try:
                port = existing_quickopen_port()
            except socket.error:
                from db_status import DBStatus
                return "%s.\n" % DBStatus.not_running_string()
        finally:
            sys.stdout = orig_stdout
            sys.stderr = orig_stderr

    # Get a connection to the prelaunched process.
    # We may have to try a few times --- it may be coming up still.
    connected = False
    s = None
    for i in range(20):  # 5 seconds
        try:
            s = socket.socket()
            s.connect((daemon_host, port))
            break
        except:
            time.sleep(0.25)
    if not s:
        raise Exception("Could not connect to the provided process.")
    try:
        f = s.makefile()

        # Send our commandline to the existing quickopend. Pass with it our
        # daemon_host and daemon_port so that it tries talking to the same quickopend
        # instance as us.
        full_args = list(args)
        full_args.extend(["--host=%s" % daemon_host])
        full_args.extend(["--port=%s" % str(daemon_port)])
        f.write(repr(full_args))
        f.write("\n")
        f.flush()

        # Wait for the result of the quickopening. It comes over as a repr'd string
        # so eval it to get the real multi-line string.
        l = eval(f.readline(), {}, {})
        return l
    finally:
        s.close()
示例#8
0
def run_command_in_existing(daemon_host, daemon_port, args, auto_start=True):
  # Prelaunched processes are DISPLAY-specific
  if sys.platform == 'darwin':
    if os.getenv('DISPLAY'):
      display = os.getenv('DISPLAY')
    else:
      display = 'cocoa'
  else:
    if os.getenv('DISPLAY'):
      display = os.getenv('DISPLAY')
    else:
      display = 'terminal';

  def existing_quickopen_port():
      conn = httplib.HTTPConnection(daemon_host, daemon_port, True)
      conn.request('GET', '/existing_quickopen/%s' % display)
      res = conn.getresponse()
      assert res.status == 200
      port = int(res.read())
      return port

  # Get the pid of an existing quickopen process via
  # quickopend. This routes through prelaunchd.py
  try:
    port = existing_quickopen_port()
  except socket.error:
    if not auto_start:
      from db_status import DBStatus
      return "%s.\n" % DBStatus.not_running_string()

    # quickopend not started; attempt once to start it automatically
    import StringIO
    try:
      # Squelch any output from starting the db
      orig_stdout = sys.stdout
      orig_stderr = sys.stderr
      sys.stdout = StringIO.StringIO()
      sys.stderr = sys.stdout

      sys.path.append(os.path.join(os.path.dirname(__file__), "../third_party/py_trace_event/"))
      import db_proxy
      db_proxy.DBProxy.try_to_start_quickopend(daemon_port)
      try:
        port = existing_quickopen_port()
      except socket.error:
        from db_status import DBStatus
        return "%s.\n" % DBStatus.not_running_string()
    finally:
      sys.stdout = orig_stdout
      sys.stderr = orig_stderr

  # Get a connection to the prelaunched process.
  # We may have to try a few times --- it may be coming up still.
  connected = False
  s = None
  for i in range(20): # 5 seconds
    try:
      s = socket.socket()
      s.connect((daemon_host, port))
      break
    except:
      time.sleep(0.25)
  if not s:
    raise Exception("Could not connect to the provided process.")
  try:
    f = s.makefile()

    # Send our commandline to the existing quickopend. Pass with it our
    # daemon_host and daemon_port so that it tries talking to the same quickopend
    # instance as us.
    full_args = list(args)
    full_args.extend(["--host=%s" % daemon_host])
    full_args.extend(["--port=%s" % str(daemon_port)])
    f.write(repr(full_args))
    f.write("\n")
    f.flush()

    # Wait for the result of the quickopening. It comes over as a repr'd string
    # so eval it to get the real multi-line string.
    l = eval(f.readline(), {}, {})
    return l
  finally:
    s.close()
示例#9
0
 def status(self):
   try:
     d = self._req('GET', '/status')
     return DBStatus.from_dict(d)
   except IOError:
     return DBStatus.not_running()