Exemplo n.º 1
0
    def update(drawing=drawing, usage_label=usage_label, node=node):

        usage_label.set_text(_('Network usage so far: ')
                             + utility.human_size(node.network_usage))
        
        if not drawing.flags() & gtk.VISIBLE:
            return 0

        drawing.queue_draw()
        return 1
Exemplo n.º 2
0
def do_stats(self, param):
    node = self.app.node
    node.acquire_lock('stat')
    try:
        tot = node.network_usage
        prof = node.network_profile
        npeers = len(node.peers)
    finally:
        node.release_lock('stat')
    str = (_('Network usage so far: %s\nNumber of known peers: %d\n')
           % (utility.human_size(tot), npeers))
    if param and param[0] in ('-p', '--profile'):
        str += _('Profile:\n')
        prof_items = map(lambda item: (item[1][1], item[1][0], item[0]),
                         prof.items())
        prof_items.sort()
        for nbytes,count,key in prof_items:
            str += (' ' + key + ': \t' + utility.human_size(nbytes)
                    + _(' in %d items\n') % count)
    self.show(str)
Exemplo n.º 3
0
    def update(self):
        for i in range(len(self.file_server.downloaders)):
            downloader= self.file_server.downloaders[i]
            if self.list.rows <i+1:
                self.list.append([downloader.basename,''])
            
            if not downloader.running:
                for field in downloader.fields:
                    if downloader.success:
                        field.show(_('done.\n'),['grey'])
                    else:
                        field.show(_('canceled.\n'),['grey'])
                    field.close()
                self.on_complete(i)
                break
            else:
                old_stats =  self.list.get_text(i,1)
                new_stats = ((" %d%% " % ((downloader.get_bytes_downloaded()+1)*100
                                          / (downloader.get_bytes_total()+1)))
                             + 'of ' + utility.human_size(downloader.get_bytes_total())
                             + '  ' + utility.human_size(downloader.get_speed()) + '/s'
                             + ' '  + downloader.get_remaining_time()
                             + '  (' + downloader.get_sources()) +')'

                if new_stats != old_stats:
                    self.list.set_text(i,1,new_stats)

                str= ("%d%% " % ((downloader.get_bytes_downloaded()+1)
                                 *100/ (downloader.get_bytes_total()+1)))
                if not downloader.authorized_links:
                    str = str +' '+ downloader.get_sources()
                else:
                    str = str + ' ' + utility.human_size(downloader.get_speed()) + '/s'\
                          + '\t'  + downloader.get_remaining_time()
                str = str + '\n'
                for field in downloader.fields:
                    if field.text != str:
                        field.show(str,['grey'])

        return 1
Exemplo n.º 4
0
        def show_interior_thread(root, self):

            size=0
            stats=''
            root.still_searching=1
            sleep_time= 0.01
            list = []
            while root.list:
                root.list.remove(root.list[0])
            while root.still_searching:

                yield 'sleep',sleep_time
                sleep_time=sleep_time*1.25
                root.update(self.app)
                children = root.get_children()

                for leaf in children:
                    if leaf not in list:
                        if leaf.item['type']=='directory':
                            leaf.expanded=0
                        elif leaf.item['type']== 'file':
                            size=size+leaf.item['length']

                        root.list.append(leaf)
                        number=len(root.list)
                        self.show("%d "%number + leaf.get_text()) 
                        list.append(leaf)

                root.update(self.app)

            root.pipe.stop()
            
            stats='    '*root.depth()+'%d %s'%(len(root.list),root.what)
            if root.what=='files':
                stats=stats +', '+utility.human_size(size)
            if not root.list:
                stats='    '*root.depth()+root.empty_text
            if len(root.list)==1:
                stats='    '*root.depth()+root.single_text                
            self.show(stats+'.')
Exemplo n.º 5
0
def do_get(self, param):
    """downloads a list of files from the last search results"""

    download_list=[]
    if param[0]=='*':
        self.lock.acquire()
        for item in self.file_list:
            if item.item['type']=='file':
                download_list.append(item)
        self.lock.release()
    else:
        for item in self.file_list:
            if utility.force_unicode(item.item['filename']) in param:
                download_list.append(item)
                
    if not download_list:
        self.show( 'unknown file %s.\n'%param[0],'grey')
        return

    last_field=self.get_field()
    first_field=self.get_field_before(last_field)
    bad_list = [ ]
    dir_list = [ ]
    size=0
    
    for item in download_list:        
        if item.item['type'] == 'file':
            downloader=self.app.file_server.download(
                item.item,item.sources,self.app.config['download_dir'],no_overload=1)
            if downloader:
                size=size+item.item['length']
            else:
                bad_list.append(item)

        elif item.item['type'] == 'directory':
            item.download(self.app)
            dir_list.append(item)
        else:
            raise error.Error("bug")
            
    if not download_list:
        str=_('The list of files is empty.\n')
    elif len(download_list)-len(bad_list)==0:
        str=_('Not downloading.\n')
    elif len(download_list)-len(bad_list)==1:
        if dir_list:            
            str=_('Downloading 1 directory. \n')
        else:
            str=_('Downloading 1 file. \n')
    else:
        str=_('Downloading %d files. \n')%(len(download_list)-len(bad_list))
        
    if bad_list:
        if len(bad_list)==len(download_list):
            str=_('Requested files are already in your directory. ')+str
        elif len(bad_list)==1:
            str=_('1 file already in your directory. ')+str
        else:
            str=_('%d files already in your directory. ')%len(bad_list)+str
    first_field.show(str,['grey'])
    first_field.close()
    if size:
        last_field.show(_('Total %s.\n'%utility.human_size(size)),['grey'])
    last_field.close()
Exemplo n.º 6
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()