コード例 #1
0
ファイル: downloader.py プロジェクト: tangleibest/untitled
 def _check_download(self, monitor, link, size, file_size, file_path):
     ''' Verify the downloaded file's size by means of two criteria:
     The content-length header sent from the hoster must match
     exactly.
     The config parameter min_size defines what is considered to be a
     faulty file, i.e. the link checker didn't detect the file to be
     invalid, but it is small enough to just be the hoster's error
     page.
     '''
     if size < self._min_size:
         msg = 'File smaller than required ({}): {!s}'
         self._fail(monitor, link,
                    msg.format(sizeof_fmt(size), monitor.release))
     elif size != file_size and file_size != -1:
         msg = 'Filesize mismatch in download of {!s}:'
         self._fail(monitor, link, msg.format(monitor.release))
         msg = 'Got {}, expected {}.'
         self.log.error(msg.format(size, file_size))
         try:
             file_path.unlink()
         except IOError:
             msg = 'Couldn\'t delete broken download of {}.'
             self.log.warn(msg.format(monitor.release))
     else:
         self._releases.update_by_id(monitor.id,
                                     download_path=str(file_path),
                                     download_date_stamp=now_unix())
         self._releases.mark_episode_downloaded(monitor)
         return True
コード例 #2
0
ファイル: torrent.py プロジェクト: tangleibest/untitled
 def parse(torr):
     td = Map(torr)
     name = '{} {}'.format(title_long, td.get('quality') | '')
     size = td.get('size_bytes') | 0
     size_str = sizeof_fmt(str(size))
     seeds = td.get('seeds') | 0
     hsh = td.get('hash') | 'no_hash'
     magnet_link = yify_magnet(title, hsh)
     return SearchResult(name, size, size_str, seeds, magnet_link)
コード例 #3
0
ファイル: torrent.py プロジェクト: tangleibest/untitled
 def _init_params(self):
     self.text = [
         'Total: {}'.format(sizeof_fmt(self.total_size)),
         'Toggle [a]ll or individual files, toggle [f]lat display,'
         ' [r]emove or [d]ownload selected files.'
     ]
     self._type = FilePickerList
     self._simple = ['f', 'd', 'r']
     self._enter = 'q'
コード例 #4
0
ファイル: torrent.py プロジェクト: tangleibest/untitled
 def _init_params(self):
     self.text = [
         'Total: {}'.format(sizeof_fmt(self.total_size)),
         'Download [a]ll ([z]ipped), select a directory or'
         ' [p]arent, toggle [s]election mode or [f]lat display'
         ' or [q]uit.'
     ]
     self._type = SpecifiedChoice
     self._simple = ['s', 'p', 'q', 'a', 'f', 'z']
     self._enter = 's'
コード例 #5
0
ファイル: __init__.py プロジェクト: tangleibest/untitled
 def _init_choice(self):
     urls = [d.url for d in self._downloaders]
     sizes = [d.file_size_str for d in self._downloaders]
     _format = '{u: <{ua}} | {s: >{sa}}'
     max_url = maxlen(*urls)
     max_size = maxlen(*sizes)
     lines = [
         _format.format(u=u, s=s, ua=max_url, sa=max_size)
         for u, s in zip(urls, sizes)
     ]
     total_size = sum([d.file_size for d in self._downloaders])
     text = [
         'Total: {}'.format(sizeof_fmt(total_size)),
         'Download [a]ll, [m]ultiple, [n]one, a single file or [q]uit?'
     ]
     self._choice = SpecifiedChoice(lines,
                                    simple=['a', 'n', 'm', 'q'],
                                    enter='a',
                                    text_post=text,
                                    values=self._downloaders)
コード例 #6
0
ファイル: torrent.py プロジェクト: tangleibest/untitled
 def _size_strings(self):
     return [sizeof_fmt(s) for s in self._sizes]
コード例 #7
0
 def size_string(self):
     return '{}: {} => {}'.format(self.filename, sizeof_fmt(self.size),
                                  sizeof_fmt(self.target_size))
コード例 #8
0
 def _print_progress(self):
     text = self._format(self._percent, sizeof_fmt(self._progress),
                         self._size_string, self._rate_string)
     self._terminal.pop()
     self._terminal.push(text)
     self._terminal.flush()
コード例 #9
0
 def file_size_str(self):
     return sizeof_fmt(self.file_size)
コード例 #10
0
 def _rate_string(self):
     return sizeof_fmt(self._rate, prec=2) if self._have_size else '??'
コード例 #11
0
 def _size_string(self):
     return sizeof_fmt(self._file_size) if self._have_size else '??'
コード例 #12
0
 def __init__(self, dir, wanted, avail):
     from tek.tools import sizeof_fmt
     text = 'Not enough space in directory "{}" ({} needed, {} available)'
     text = text.format(dir, sizeof_fmt(wanted), sizeof_fmt(avail))
     super(NotEnoughDiskSpace, self).__init__(text)
コード例 #13
0
ファイル: errors.py プロジェクト: tek/pytek
 def __init__(self, dir, wanted, avail):
     from tek.tools import sizeof_fmt
     text = 'Not enough space in directory "{}" ({} needed, {} available)'
     text = text.format(dir, sizeof_fmt(wanted), sizeof_fmt(avail))
     super(NotEnoughDiskSpace, self).__init__(text)
コード例 #14
0
ファイル: tools_test.py プロジェクト: tek/pytek
 def sizeof_fmt(self):
     sizeof_fmt(1450000, prec=3, bi=False).should.equal('1.450 MB')
     sizeof_fmt(1450000, bi=True).should.equal('1.4 MB')
コード例 #15
0
 def size_str(self):
     return sizeof_fmt(self.size)