def search_for_people(str, node,app): list = string.split(utility.remove_accents(str.lower())) if not list: raise error.Error(_("Please specify some keywords to search for.\n" +\ "For example, their name or username.")) largest,keywords,anti_keywords,title = utility.parse_keywords(list) pipe = node.retrieve(hash.hash_of('identity-name '+largest), settings.identity_redundancy) Searcher(_('People matching: ')+title,pipe, node,app,keywords,anti_keywords).start()
def search_for_auctions(str, node, app, notebook=None): temp_list = string.split(str) list = [ ] for item in temp_list: if len(item) >= settings.min_search_keyword_len: list.append(utility.remove_accents(item.lower())) if not list: raise error.Error(_("Please specify some keywords to search for.\n" +\ "(keywords must contain at least %d letters)") \ % settings.min_search_keyword_len) largest,keywords,anti_keywords,title = utility.parse_keywords(list) if not keywords: raise error.Error(_("Please specify at least one positive keyword.\n" )) pipe = node.retrieve(hash.hash_of('auction-name '+largest),settings.identity_redundancy) Searcher(title,pipe, node,app,notebook,keywords,anti_keywords).start()
def search_for_files(str, node, app, notebook=None,mime=''): temp_list = string.split(str) list = [ ] for item in temp_list: if len(item) >= settings.min_search_keyword_len: list.append(utility.remove_accents(item.lower())) if not list: raise error.Error(_("Please specify some keywords to search for.\n" +\ "(keywords must contain at least %d letters)") \ % settings.min_search_keyword_len) largest,keywords,anti_keywords,title = utility.parse_keywords(list) if not keywords: raise error.Error( _("Please specify at least one positive search term (i.e. not preceded by !).\n" )) pipe = node.retrieve(hash.hash_of(largest)) Searcher(title, pipe, node, app, notebook, keywords, anti_keywords, mime).start()
def do_find(self, param): if param: param = param[0] else: param = '' list = string.split(string.lower(utility.remove_accents(param))) online_only = 0 show_ip=0 show_number=0 while '--online' in list: list.remove('--online') online_only = 1 while list and list[0][0]=='-': option=list[0] list.remove(option) for opt in option[1:]: if opt=='n': show_number=1 elif opt=='i': show_ip=1 elif opt=='h': show_ip=2 elif opt=='o': online_only=1 else: raise error.Error(_('Unrecognized option \''+opt+'\'.\n'\ +'Available /find options are:\n'\ +' -o : online people\n'\ +' -n : number results\n' +' -i : display IP address\n' +' -h : display hostname')) #if not self.use_gtk: # show_number=1 largest,keywords,anti_keywords,title = utility.parse_keywords(list) if list: pipe = self.app.node.retrieve( hash.hash_of('identity-name '+largest), settings.identity_redundancy) else: pipe = self.app.node.retrieve( hash.hash_of('service identity'), settings.identity_redundancy) empty_text = _('Nobody') single_text = _('1 person') # there should be 2 child classes root = search.Search_tree_interior( lambda self=self: pipe, keywords, anti_keywords, 'people', '',\ '', empty_text,single_text,online_only) self.lock.acquire() self.identity_list = root.list self.root=root self.lock.release() str = 'people' if not list and not online_only: str = 'all ' + str if online_only: str = 'online ' + str str=str[0].upper()+str[1:] if list: str=str+' matching %s'%title first_field=self.get_field() self.show_before(first_field, str+':\n') self.show_interior(root,first_field,show_ip)
def do_search(self, param): """search for files. called from mainthread""" if param: param = param[0] else: param = '' list = string.split(string.lower(utility.remove_accents(param))) show_url=0 show_number=0 mime='' local_only=0 remote_only=0 while list and list[0][0]=='-': option=list[0] list.remove(option) for opt in option[1:]: if opt=='u': show_url=1 elif opt=='n': show_number=1 elif opt=='a': mime='audio' elif opt=='v': mime='video' elif opt=='l': local_only=1 elif opt=='r': remote_only=1 elif opt=='i': mime='image' elif opt=='t': mime='text' else: raise error.Error(_('Unrecognized option \''+opt+'\'.\n'\ +'Available /search options are:\n'\ +' -u : display url\n'\ +' -n : number results\n' +' -l : only local files\n' +' -r : only remote files\n' +' -a : only audio files\n' +' -t : only text files\n' +' -v : only video files\n' +' -i : only images')) #if not self.use_gtk: # show_number=1 largest,keywords,anti_keywords,title = utility.parse_keywords(list) if keywords: pipe = self.app.node.retrieve(hash.hash_of(largest),1,0,local_only) #if self.app.overnet and not local_only: # self.app.overnet.retrieve(largest,pipe) else: self.show('Please specify at least one positive search term (i.e. not preceded by !).\n','grey') return empty_text = _('None') single_text = _('1 file') # todo: search tree interior should have two child classes for files and people... # about filtering: the pipe should already contain the right information.. root = search.Search_tree_interior( lambda self=self: pipe, keywords, anti_keywords, 'files', mime,'', \ empty_text,single_text,0,remote_only) self.lock.acquire() self.file_list=root.list self.root=root self.lock.release() str = 'files' if mime: str = mime+' ' + str if list: str=str+' matching %s'%title if remote_only: str= 'remote '+str if local_only: str= 'local '+str str=str[0].upper()+str[1:] first_field=self.get_field() self.show_before(first_field, str+':\n') self.show_interior(root,first_field,show_url)