コード例 #1
0
 def chooseFile(self, default, size, saveas, isdir):
     self.file = default
     self.fileSize = formatSize(size)
     if saveas == '':
         saveas = default
     self.downloadTo = os.path.abspath(saveas)
     return saveas
コード例 #2
0
 def chooseFile(self, default, size, saveas, isdir):
     self.file = default
     self.fileSize = formatSize(size)
     if saveas == '':
         saveas = default
     self.downloadTo = os.path.abspath(saveas)
     return saveas
コード例 #3
0
    def display(self, data):
        if self.changeflag.is_set():
            return

        inchar = self.mainwin.getch()
        if inchar == 12:  # ^L
            self._remake_window()

        self.mainwin.erase()
        if data:
            self._display_data(data)
        else:
            self.mainwin.addnstr(1,
                                 int(self.mainwinw / 2) - 5, 'no torrents', 12,
                                 curses.A_BOLD)
        totalup = 0
        totaldn = 0
        for entry in data:
            #entry = (name, status, progress, peers, seeds, seedsmsg, dist,
            #         uprate, downrate, upamount, downamount, size, t, msg)
            totalup += entry[7]
            totaldn += entry[8]

        totalup = '%s/s' % formatSize(totalup)
        totaldn = '%s/s' % formatSize(totaldn)

        self.totalwin.erase()
        self.totalwin.addnstr(0, self.mainwinw - 27, 'Totals:', 7,
                              curses.A_BOLD)
        self.totalwin.addnstr(0, self.mainwinw - 20 + (10 - len(totaldn)),
                              totaldn, 10, curses.A_BOLD)
        self.totalwin.addnstr(0, self.mainwinw - 10 + (10 - len(totalup)),
                              totalup, 10, curses.A_BOLD)

        curses.panel.update_panels()
        curses.doupdate()

        return inchar in (ord('q'), ord('Q'))
コード例 #4
0
    def display(self, data):
        if self.changeflag.isSet():
            return

        inchar = self.mainwin.getch()
        if inchar == 12:  # ^L
            self._remake_window()

        self.mainwin.erase()
        if data:
            self._display_data(data)
        else:
            self.mainwin.addnstr(1, int(self.mainwinw / 2) - 5,
                                 'no torrents', 12, curses.A_BOLD)
        totalup = 0
        totaldn = 0
        for entry in data:
            #entry = (name, status, progress, peers, seeds, seedsmsg, dist,
            #         uprate, downrate, upamount, downamount, size, t, msg)
            totalup += entry[7]
            totaldn += entry[8]

        totalup = '%s/s' % formatSize(totalup)
        totaldn = '%s/s' % formatSize(totaldn)

        self.totalwin.erase()
        self.totalwin.addnstr(0, self.mainwinw - 27, 'Totals:', 7,
                              curses.A_BOLD)
        self.totalwin.addnstr(0, self.mainwinw - 20 + (10 - len(totaldn)),
                              totaldn, 10, curses.A_BOLD)
        self.totalwin.addnstr(0, self.mainwinw - 10 + (10 - len(totalup)),
                              totalup, 10, curses.A_BOLD)

        curses.panel.update_panels()
        curses.doupdate()

        return inchar in (ord('q'), ord('Q'))
コード例 #5
0
    def _display_data(self, data):
        if 3 * len(data) <= self.mainwinh:
            self.scroll_pos = 0
            self.scrolling = False
        elif self.scroll_time + DOWNLOAD_SCROLL_RATE < time.time():
            self.scroll_time = time.time()
            self.scroll_pos += 1
            self.scrolling = True
            if self.scroll_pos >= 3 * len(data) + 2:
                self.scroll_pos = 0

        i = int(self.scroll_pos / 3)
        self.disp_line = (3 * i) - self.scroll_pos
        self.disp_end = False

        while not self.disp_end:
            ii = i % len(data)
            if i and not ii:
                if not self.scrolling:
                    break
                self._display_line('')
                if self._display_line(''):
                    break
            (name, status, progress, peers, seeds, _, dist, uprate, dnrate,
             upamt, dnamt, size, t, msg) = data[ii]
            if t is not None and t > 0:
                status = 'ETA in ' + formatIntClock(t)
            name = ljust(name, self.mainwinw - 32)
            size = rjust(formatSize(size), 8)
            uprate = rjust('%s/s' % formatSize(uprate), 10)
            dnrate = rjust('%s/s' % formatSize(dnrate), 10)
            line = "%3d %s%s%s%s" % (ii + 1, name, size, dnrate, uprate)
            self._display_line(line, True)
            if peers + seeds:
                datastr = '    ({}) {} - {} up {} dn - {} peers {} seeds ' \
                    '{:.3f} dist copies'.format(
                        progress, status, formatSize(upamt), formatSize(dnamt),
                        peers, seeds, dist)
            else:
                datastr = '    ({}) {} - {} up {} dn'.format(
                    progress, status, formatSize(upamt), formatSize(dnamt))
            self._display_line(datastr)
            self._display_line('    ' + ljust(msg, self.mainwinw - 4))
            i += 1
コード例 #6
0
    def _display_data(self, data):
        if 3 * len(data) <= self.mainwinh:
            self.scroll_pos = 0
            self.scrolling = False
        elif self.scroll_time + DOWNLOAD_SCROLL_RATE < time.time():
            self.scroll_time = time.time()
            self.scroll_pos += 1
            self.scrolling = True
            if self.scroll_pos >= 3 * len(data) + 2:
                self.scroll_pos = 0

        i = int(self.scroll_pos / 3)
        self.disp_line = (3 * i) - self.scroll_pos
        self.disp_end = False

        while not self.disp_end:
            ii = i % len(data)
            if i and not ii:
                if not self.scrolling:
                    break
                self._display_line('')
                if self._display_line(''):
                    break
            (name, status, progress, peers, seeds, _, dist, uprate, dnrate,
             upamt, dnamt, size, t, msg) = data[ii]
            if t > 0:
                status = 'ETA in ' + formatIntClock(t)
            name = ljust(name, self.mainwinw - 32)
            size = rjust(formatSize(size), 8)
            uprate = rjust('%s/s' % formatSize(uprate), 10)
            dnrate = rjust('%s/s' % formatSize(dnrate), 10)
            line = "%3d %s%s%s%s" % (ii + 1, name, size, dnrate, uprate)
            self._display_line(line, True)
            if peers + seeds:
                datastr = '    ({}) {} - {} up {} dn - {} peers {} seeds ' \
                    '{:.3f} dist copies'.format(
                        progress, status, formatSize(upamt), formatSize(dnamt),
                        peers, seeds, dist)
            else:
                datastr = '    ({}) {} - {} up {} dn'.format(
                    progress, status, formatSize(upamt), formatSize(dnamt))
            self._display_line(datastr)
            self._display_line('    ' + ljust(msg, self.mainwinw - 4))
            i += 1
コード例 #7
0
ファイル: track.py プロジェクト: AchillesA/BitTornado
    def get_infopage(self):
        try:
            if not self.config['show_infopage']:
                return (404, 'Not Found', {'Content-Type': 'text/plain',
                                           'Pragma': 'no-cache'}, alas)
            red = self.config['infopage_redirect']
            if red:
                return (302, 'Found', {'Content-Type': 'text/html',
                                       'Location': red},
                        '<A HREF="' + red + '">Click Here</A>')

            s = StringIO()
            s.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" '
                    '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n'
                    '<html><head><title>BitTorrent download info</title>\n')
            if self.favicon is not None:
                s.write('<link rel="shortcut icon" href="/favicon.ico">\n')
            s.write('</head>\n<body>\n<h3>BitTorrent download info</h3>\n'
                    '<ul>\n<li><strong>tracker version:</strong> %s</li>\n'
                    '<li><strong>server time:</strong> %s</li>\n'
                    '</ul>\n' % (version, isotime()))
            if self.config['allowed_dir']:
                if self.show_names:
                    names = [(self.allowed[hash]['name'], hash)
                             for hash in self.allowed]
                else:
                    names = [(None, hash) for hash in self.allowed]
            else:
                names = [(None, hash) for hash in self.downloads]
            if not names:
                s.write('<p>not tracking any files yet...</p>\n')
            else:
                names.sort()
                tn = 0
                tc = 0
                td = 0
                tt = 0  # Total transferred
                ts = 0  # Total size
                nf = 0  # Number of files displayed
                if self.config['allowed_dir'] and self.show_names:
                    s.write('<table summary="files" border="1">\n'
                            '<tr><th>info hash</th><th>torrent name</th>'
                            '<th align="right">size</th><th align="right">'
                            'complete</th><th align="right">downloading</th>'
                            '<th align="right">downloaded</th>'
                            '<th align="right">transferred</th></tr>\n')
                else:
                    s.write('<table summary="files">\n'
                            '<tr><th>info hash</th><th align="right">complete'
                            '</th><th align="right">downloading</th>'
                            '<th align="right">downloaded</th></tr>\n')
                for name, hash in names:
                    l = self.downloads[hash]
                    n = self.completed.get(hash, 0)
                    tn = tn + n
                    c = self.seedcount[hash]
                    tc = tc + c
                    d = len(l) - c
                    td = td + d
                    if self.config['allowed_dir'] and self.show_names:
                        if hash in self.allowed:
                            nf = nf + 1
                            sz = self.allowed[hash]['length']  # size
                            ts = ts + sz
                            szt = sz * n   # Transferred for this torrent
                            tt = tt + szt
                            if self.allow_get == 1:
                                linkname = '<a href="/file?info_hash=' + \
                                    urllib.quote(hash) + '">' + name + '</a>'
                            else:
                                linkname = name
                            s.write('<tr><td><code>%s</code></td><td>%s</td>'
                                    '<td align="right">%s</td>'
                                    '<td align="right">%i</td>'
                                    '<td align="right">%i</td>'
                                    '<td align="right">%i</td>'
                                    '<td align="right">%s</td></tr>\n' %
                                    (hexlify(hash), linkname, formatSize(sz),
                                     c, d, n, formatSize(szt)))
                    else:
                        s.write('<tr><td><code>%s</code></td>'
                                '<td align="right"><code>%i</code></td>'
                                '<td align="right"><code>%i</code></td>'
                                '<td align="right"><code>%i</code></td>'
                                '</tr>\n' % (hexlify(hash), c, d, n))
                if self.config['allowed_dir'] and self.show_names:
                    s.write('<tr><td align="right" colspan="2">%i files</td>'
                            '<td align="right">%s</td><td align="right">%i'
                            '</td><td align="right">%i</td><td align="right">'
                            '%i</td><td align="right">%s</td></tr>\n' %
                            (nf, formatSize(ts), tc, td, tn, formatSize(tt)))
                else:
                    s.write('<tr><td align="right">%i files</td>'
                            '<td align="right">%i</td><td align="right">%i'
                            '</td><td align="right">%i</td></tr>\n' %
                            (nf, tc, td, tn))
                s.write('</table>\n<ul>\n'
                        '<li><em>info hash:</em> SHA1 hash of the "info" '
                        'section of the metainfo (*.torrent)</li>\n'
                        '<li><em>complete:</em> number of connected clients '
                        'with the complete file</li>\n'
                        '<li><em>downloading:</em> number of connected clients'
                        ' still downloading</li>\n'
                        '<li><em>downloaded:</em> reported complete downloads'
                        '</li>\n'
                        '<li><em>transferred:</em> torrent size * total '
                        'downloaded (does not include partial '
                        'transfers)</li>\n</ul>\n')

            s.write('</body>\n</html>\n')
            return (200, 'OK',
                    {'Content-Type': 'text/html; charset=iso-8859-1'},
                    s.getvalue())
        except Exception:
            print_exc()
            return (500, 'Internal Server Error',
                    {'Content-Type': 'text/html; charset=iso-8859-1'},
                    'Server Error')