def get_most_frequent(self, limit=5): """ Returns most frequent apps TODO: rename to `get_most_recent` and update method to remove old apps :param int limit: limit :rtype: class:`ResultList` """ # pylint: disable=relative-beyond-top-level # import here to avoid circular deps. from ulauncher.search.apps.AppResultItem import AppResultItem from ulauncher.search.apps.AppDb import AppDb app_db = AppDb.get_instance() return [ AppResultItem(i) for i in islice( filter( None, map( lambda r: app_db.get_by_path(r[0]), sorted(self._records.items(), key=itemgetter(1), reverse=True))), 0, limit) ]
def _get_app_desktop(self): """ Returns path to desktop file """ for info in AppDb.get_instance().get_records().values(): if info['name'].lower() == 'ulauncher': return info['desktop_file']
def _get_app_desktop(self): """ :rtype: str :returns: path to desktop file """ record = AppDb.get_instance().get_by_name('Ulauncher') if record: return record['desktop_file']
def on_query(self, query): custom_items = [GoogleResultItem(), WikipediaResultItem(), StackoverflowResultItem()] default_items = custom_items[:2] action_item = next((i for i in custom_items if query.startswith('%s ' % i.get_keyword())), None) if action_item: result_list = (action_item,) else: result_list = AppDb.get_instance().find(query) # add web search items result_list.extend(custom_items) if not len(result_list) and query: # default search map(lambda i: i.set_default_search(True), custom_items) result_list = default_items return ActionList((RenderResultListAction(result_list),))
def start(): """ Add all known .desktop files to the DB and start inotify watcher """ db = AppDb.get_instance() t0 = time() logger.info('Started scanning desktop dirs') for app in find_apps_cached(): db.put_app(app) logger.info('Scanned desktop dirs in %.2f seconds', (time() - t0)) wm = pyinotify.WatchManager() handler = AppNotifyEventHandler(db) notifier = pyinotify.ThreadedNotifier(wm, handler) notifier.setDaemon(True) logger.debug('Start watching desktop files...') notifier.start() # pylint: disable=no-member mask = pyinotify.IN_CREATE | pyinotify.IN_DELETE | pyinotify.IN_MODIFY | \ pyinotify.IN_MOVED_FROM | pyinotify.IN_MOVED_TO wm.add_watch(DESKTOP_DIRS, mask, rec=True, auto_add=True)
def app_db(self): return AppDb(':memory:').open()
def app_db(self, app_icon_cache): return AppDb(':memory:', app_icon_cache).open()
def app_db(self): return AppDb('test')
def __init__(self, search_modes): self.search_modes = search_modes self.app_db = AppDb.get_instance()