Esempio n. 1
0
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()
Esempio n. 2
0
def do_who(self, params):
    
    # todo:
    # if I subscribe to a channel, I should be warned when people join/leave

    if params:

        channel= params[0]
        if channel[0]!='#':
            self.show('\'%s\' is not a valid channel name. Channel names begin with \'#\''\
                      %channel)
            return
        else:
            pipe = self.node.retrieve(hash.hash_of('channel subscribe '+channel), \
                                      settings.channel_redundancy)
            empty_text = _('Nobody')
            single_text = _('1 person')
            show_ip=1
            show_number=0

            root = search.Search_tree_interior(
                lambda self=self: pipe, [], [], 'people', '',\
                '', empty_text,single_text,1)

            self.lock.acquire()
            self.identity_list =root.list
            self.root=root
            self.lock.release()

            self.show('People listening on channel '+channel+':')
            self.show_interior(root)

    else:

        self.show(_('Watched people currently online:'))
        self.app.name_server.lock.acquire()
        values = self.app.name_server.acquaintances.values()
        self.app.name_server.lock.release()

        for acq in values:
            acq.lock.acquire()
            name = acq.nickname
            acq.lock.release()

            acq.start_watching(self.node)
            #while not acq.watched:
            #    time.sleep(0.1)
            acq.lock.acquire()
            online = acq.online
            address = acq.address
            acq.lock.release()
            if online:
                self.show(name+' ')
Esempio n. 3
0
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()
Esempio n. 4
0
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()
Esempio n. 5
0
    wodge = g.get('wodge')
    if type(wodge) != types.DictionaryType:
        print _("Warning: ignoring non-dictionary wodge: "), `wodge`
        continue
    
    enc = {}
    for key in ('subject', 'human-name', 'text'):
        val = wodge.get(key)
        if type(val) not in (types.StringType, types.UnicodeType):
            print _("Warning: ignoring wodge with non-text '%s': %s") % (key, `val`)
        enc[key] = html_encode(val)
    val = wodge.get('post-time')
    if type(val) != types.LongType:
        print _("Warning: ignoring wodge with non-long 'post-time': %s") % `val`

    wodge_hash = hash.hash_of(string.join([force_unicode(wodge[key]) for key in ('subject', 'human-name', 'text')], u'\0').encode('utf8', 'replace'))
    wodge_hash_str = hash.hash_to_url(wodge_hash)[len('circle-file:'):]
    basename = 'goss_' + wodge_hash_str + '.html'
    href = '"' + basename + '"'
    subj = enc['subject']
    if not subj:
        subj = '(None)'
    subj_rows.append((-wodge['post-time'], tr(td(enc['human-name']) + td(a(subj, href=href)))))

    date = chat.standard2host_timestamp(wodge['post-time'])

    lines = [
     '<html>',
     '<head>',
     '<title>Gossip: ' + subj + '</title>',
     '</head>',
Esempio n. 6
0
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)
Esempio n. 7
0
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)
Esempio n. 8
0
def do_who(self, params):
    
    # todo:
    # if I subscribe to a channel, I should be warned when people join/leave

    if params:

        channel= params[0]
        if channel[0]!='#':
            self.show('\'%s\' is not a valid channel name. Channel names begin with \'#\'\n'\
                      %channel,'grey')
            return
        else:
            pipe = self.node.retrieve(hash.hash_of('channel subscribe '+channel), \
                                      settings.channel_redundancy)
            empty_text = _('Nobody')
            single_text = _('1 person')
            show_ip=1
            show_number=0

            root = search.Search_tree_interior(
                lambda self=self: pipe, [], [], 'people', '',\
                '', empty_text,single_text,1)

            self.lock.acquire()
            self.identity_list =root.list
            self.root=root
            self.lock.release()

            str = 'People listening on channel '+channel
            first_field=self.get_field()
            self.show_before(first_field, str+':\n')
            self.show_interior(root,first_field,1)

    else:

        field = self.show(_('Watched people currently online:\n'))
        new_field = self.get_field_after(field,'person')
        field = new_field

        self.app.name_server.lock.acquire()
        values = self.app.name_server.acquaintances.values()
        self.app.name_server.lock.release()

        n = [0]
        fields = { }
        for item in values:
            if item.watch:
                n[0] = n[0]+1
                fields[item], field = field, self.get_field_after(field,'person')

        if n[0]:
            field.show(' ...\n')
            for acq in fields.keys():

                acq.lock.acquire()
                name = acq.nickname
                acq.lock.release()

                acq.start_watching(self.node)
                while not acq.watched:
                    print "yy"
                    time.sleep(0.1)

                acq.lock.acquire()
                online = acq.online
                address = acq.address
                acq.lock.release()

                if online:
                    fields[acq].show( name+' ','people')
                    fields[acq].name = acq.name
                else:
                    fields[acq].show('')
                fields[acq].close()

                self.lock.acquire()
                n[0] = n[0] - 1
                if n[0] == 0:
                    field.show('\n')
                    field.close()
                self.lock.release()

        else:
            field.show('\n')
            field.close()
Esempio n. 9
0
    wind = gtk.Window()
    vbox = gtk.VBox(gtk.FALSE,5)
    
    widget = Helpful_label('Name:','Enter your name here.\n\neg: John Smith')
    vbox.pack_start(widget)

    widget = Text(50,1)
    widget.write("""Hello world! What a wonderful world.
    Supercalafragalisticexpialadociousiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii Yay Yay.\n\nYay!
    http://thecircle.org.au\n <({http://thecircle.org.au>)}""")
    gtk.timeout_add(3000, widget.write, """Hello world!
    What a wonderful world. Supercalafragalisticexpialadocious
    Yay Yay.\n\nYay!""")
    vbox.pack_start(widget)

    widget = Signature(hash.hash_of('bob'))
    vbox.pack_start(widget)
    # Proof of @R43: @E24.
    
    widget = File_selector_widget('/home/pfh',1)
    vbox.pack_start(widget)

    widget = Network_topology()
    widget.hashtable_running = 1
    vbox.pack_start(widget)
    
    widget = Toggle_icon('>')
    vbox.pack_start(widget)
    
    wind.add(vbox)
    #wind.set_size_request(400,400)
Esempio n. 10
0
def find_task(daemon,query,input,output,connection):
    global http_mode,http_port,http_socket


    file=open(utility.find_file("ui_http/search.html"))
    str=file.read()
    file.close()

    if http_mode=='local':
        image_tag = "<img src=\"file://"+utility.find_file("pixmaps/circle-logo.png")\
                    +"\" title=\"\" alt=\"\" border=0 style=\"width: 150px; height: 50px;\"> "
        hostname = 'localhost'
    else:
        image_tag = "<img src=\"http://thecircle.org.au/circle-logo.png\" "\
                    +" title=\"\" alt=\"\" border=0 style=\"width: 150px; height: 50px;\"> "
        hostname = 'thecircle.dyndns.org'

    try:
        output.write('HTTP/1.1 200 OK\n')
        output.write('content-type: text/html\n')
        output.write('Cache-control: max-age=60\n')
        output.write('\n')
        output.write(str%(hostname,http_port,hostname,http_port,image_tag))
        output.flush()
    except:
        return
    
    for char in '+-_.,?()![]':
        query = query.replace(char," ")
    query=query.lower()
    list=query.split()
    if list:
        key=list[0]
        pipe = daemon.node.retrieve(hash.hash_of('identity-name '+key), settings.identity_redundancy)
    else:
        pipe = daemon.node.retrieve(hash.hash_of('service identity'), settings.identity_redundancy)
        
    results = []
    while not pipe.finished():

        list = pipe.read_all()
        prev_pair = None
        for pair in list:
            if pair == prev_pair:
                continue
            link, item = prev_pair = pair

            try:
                item = utility.check_and_demangle_item(item)
            except:
                continue

            if item['key'] not in results:
                results.append(item['key'])
                name = hash.hash_of(safe_pickle.dumps(item['key']))                
                check.check_is_name(name)
                str = "circle-person:"+string.join(map(lambda a:hex(ord(a))[2:], name), '')

                try:
                    output.write("<p class=g><t><b>\n")
                    output.write(item['name'])
                    output.write(" ("+utility.force_string(item['human-name'])+")")
                    output.write("</b><br>")
                    if item['description']:
                        output.write(
                                "<font size=-1>"+utility.force_string(item['description'])+"<br></font>")
                    output.write("<font color=#008000 size=-1> "+str+"</font></p>\n")
                except:
                    return
                
        time.sleep(0.5)
        try:
            output.flush()
        except:
            return
        

    pipe.stop()
    try:
        if not results:
            output.write("<br><br><p>Your search: <b>"+key+"</b> did not match any circle user.</p>")
        else:
            if results.__len__()==1:
                what = "one identity"
            else:
                what = "%d identities"%results.__len__()
            if query:
                msg = "Returned " + what + " matching <b>\"" + query + "\"</b>."
            else:
                msg = "Returned " + what +"."
            output.write("<p><br>"+msg+"</p>")
            output.write("<hr><p class=g align=\"right\"></font size=-1>"\
                         +utility.force_string(random.choice(settings.gratuitous_plugs))+"</font></p><hr>")
            
        output.write("</body></html>")
        input.close()
        output.close()
        connection.close()
    except:
        return
    print "returned %d people for \"%s\""%(results.__len__(), query)
    sys.stdout.flush()
Esempio n. 11
0
def search_task(daemon,query,input,output,connection):
    global http_mode,http_port,http_socket
    global http_socket

    file=open(utility.find_file("ui_http/search.html"))
    str=file.read()
    file.close()    
    if http_mode=='local':
        image_tag = "<img src=\"file://"+utility.find_file("pixmaps/circle-logo.png")\
                    +"\" title=\"\" alt=\"\" border=0 style=\"width: 150px; height: 50px;\"> "
        hostname = 'localhost'
    else:
        image_tag = "<img src=\"http://thecircle.org.au/circle-logo.png\" "\
                    +" title=\"\" alt=\"\" border=0 style=\"width: 150px; height: 50px;\"> "
        hostname = 'thecircle.dyndns.org'

    for char in '+-_.,?()![]':
        query = query.replace(char," ")
    query=query.lower()
    list=query.split()
    if list:
        key=list[0]
    else:
        key=''

    try:        
        output.write('HTTP/1.1 200 OK\n')
        output.write('content-type: text/html\n')
        output.write('Cache-control: max-age=60\n')
        output.write('\n')
        output.write(str%(hostname,http_port,hostname,http_port,image_tag))
        output.flush()
        if key.__len__()<3:
            output.write("<p>Keyword %s too short: must be at least 3 characters<p></body></html>"%key)
            input.close()
            output.close()
            connection.close()
            return    
    except:
        return
        
    pipe = daemon.node.retrieve(hash.hash_of(key))
    results = []
    restricted = 0
    while not pipe.finished() and not restricted:
        for item in pipe.read_all():

            if results.__len__()==100:
                restricted = 1
                break
            
            if item[1]['name'] not in results:
                results.append(item[1]['name'])
                filename = utility.force_string(item[1]['filename'])
                extension = string.split(string.split(filename,'.')[-1],'-')[0]
                lext = string.lower(extension)
                if lext in ['mp3','ogg']:
                    music=1
                else:
                    music=0
                if item[1].has_key('music_title'):
                    ref = utility.force_string(item[1]['music_title'])
                    if ref.strip()=='':
                        ref= filename
                else:
                    ref = utility.force_string(item[1]['filename'])

                try:
                    output.write("<p class=g><t>\n")
                    output.write(url(stress(ref,key),\
                                     hash.hash_to_url(item[1]['name']),filename,http_port))
                    output.write("<br><font size=-1>")

                    if music:
                        line=0
                        if item[1].has_key('music_artist'):
                            artist_str="Artist:"+stress(utility.force_string(item[1]['music_artist']),key)
                            output.write(artist_str)
                            line=1
                        if item[1].has_key('music_album'):
                            if item[1]['music_album']!='':
                                album_str=" Album:"+stress(utility.force_string(item[1]['music_album']),key)
                                output.write(album_str)
                                line=1
                        if line:
                            output.write("<br>")

                    #line=0
                    #if item[1].has_key('rate'):
                    #    output.write("Rate:"+item[1]['rate']+".")
                    #    line=1
                    #if item[1].has_key('freq'):
                    #    output.write("   Frequency:"+item[1]['freq']+".")
                    #    line=1
                    #if item[1].has_key('misc'):
                    #    output.write("   --  "+item[1]['misc'])
                    #    line=1
                    #if line:
                    #    output.write("<br>")

                    output.write("File name: "+stress(filename,key))
                    output.write("<br>")
                    if item[1].has_key('mime'):
                        if item[1]['mime'] != 'unknown':
                            output.write('Mime: '+item[1]['mime'].replace(' \x08',''))
                            output.write("<br>")

                    if item[1].has_key('generic'):
                        output.write(item[1]['generic'].replace('\x08',''))
                        output.write("<br>")
                    else:
                        for i in item[1].items():
                            if i[0] not in ['keywords',
                                            'mime','length',
                                            'name','filename',
                                            'type','music_album',
                                            'music_artist','music_title']:
                                output.write(i[0]+':'+stress(i[1],key)+'  ')
                                output.write("<br>")

                    output.write("<font color=#008000>"+hash.hash_to_url(item[1]['name'])+" -  "\
                                 +utility.human_size(item[1]['length'])+"- </font>")

                    #output.write("<font color=#656565>Sources:<a href="">Sources</a></font>")
                    output.write("</font></p>\n")
                except:
                    return

        time.sleep(0.5)
        try:
            output.flush()
        except:
            return
    pipe.stop()
    try:
        if not results:
            output.write("<br><br><p>Your search: <b>"+key+"</b> did not match any document.</p>")
        else:
            if restricted:
                output.write("<p><br>Displaying only 100 results for <b>%s</b></p>" % key)
            else:
                output.write("<p><br>Found %d files matching <b>%s</b></p>" % (results.__len__(),key))
            output.write("<hr><p class=g align=\"right\"></font size=-1>"\
                         +utility.force_string(random.choice(settings.gratuitous_plugs))+"</font></p><hr>")
        output.write("</body></html>")
        input.close()
        output.close()
        connection.close()
    except:
        pass
    print "returned %d files for \"%s\""%(results.__len__(), query)
    sys.stdout.flush()
Esempio n. 12
0
def search_for_people_on_channel(channel, node,app):
    pipe = node.retrieve(hash.hash_of('channel subscribe '+channel), settings.channel_redundancy)
    Searcher(_('People on %s')%channel,pipe, node,app).start()
Esempio n. 13
0
def search_for_all_channels(node,app):
    pipe = node.retrieve(hash.hash_of('channel exists'), settings.channel_redundancy)
    Searcher(_('All channels'),pipe, node,app).start()
Esempio n. 14
0
def search_for_all_people(node,app):
    pipe = node.retrieve(hash.hash_of('service identity'), settings.identity_redundancy)
    Searcher(_('All people'),pipe, node,app).start()