linting and minor refactor

This commit is contained in:
Victor Shyba 2020-02-24 13:34:13 -03:00
parent abaac8ef48
commit b73c00943c
5 changed files with 27 additions and 25 deletions

View file

@ -45,6 +45,8 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends ffmpeg
- if: matrix.test == 'datanetwork'
run: sudo apt install -y --no-install-recommends libboost1.67-all-dev
- run: pip install tox-travis
- run: tox -e ${{ matrix.test }}

View file

@ -1,7 +1,7 @@
.PHONY: install tools lint test idea
install:
pip install -e git+https://github.com/shyba/libtorrent.git#egg=python-libtorrent
pip install https://s3.amazonaws.com/files.lbry.io/python_libtorrent-1.2.4-py2.py3-none-any.whl
CFLAGS="-DSQLITE_MAX_VARIABLE_NUMBER=2500000" pip install -U https://github.com/rogerbinns/apsw/releases/download/3.30.1-r1/apsw-3.30.1-r1.zip \
--global-option=fetch \
--global-option=--version --global-option=3.30.1 --global-option=--all \

View file

@ -74,9 +74,9 @@ class TorrentHandle:
self.metadata_completed.set()
log.info("Metadata completed for btih:%s - %s", status.info_hash, self.name)
if not status.is_seeding:
log.debug('%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d seeds: %d) %s - %s' % (
status.progress * 100, status.download_rate / 1000, status.upload_rate / 1000,
status.num_peers, status.num_seeds, status.state, status.save_path))
log.debug('%.2f%% complete (down: %.1f kB/s up: %.1f kB/s peers: %d seeds: %d) %s - %s',
status.progress * 100, status.download_rate / 1000, status.upload_rate / 1000,
status.num_peers, status.num_seeds, status.state, status.save_path)
elif not self.finished.is_set():
self.finished.set()
log.info("Torrent finished: %s", self.name)
@ -95,7 +95,7 @@ class TorrentHandle:
async def resume(self):
await self._loop.run_in_executor(
self._executor, self._handle.resume
self._executor, lambda: self._handle.resume() # pylint: disable=unnecessary-lambda
)
@ -108,28 +108,15 @@ class TorrentSession:
self.tasks = []
async def add_fake_torrent(self):
dir = mkdtemp()
info, btih = self._create_fake(dir)
tmpdir = mkdtemp()
info, btih = _create_fake_torrent(tmpdir)
flags = libtorrent.add_torrent_params_flags_t.flag_seed_mode
handle = self._session.add_torrent({
'ti': info, 'save_path': dir, 'flags': flags
'ti': info, 'save_path': tmpdir, 'flags': flags
})
self._handles[btih] = TorrentHandle(self._loop, self._executor, handle)
return btih
def _create_fake(self, dir):
# beware, that's just for testing
path = os.path.join(dir, 'tmp')
with open(path, 'wb') as myfile:
size = myfile.write(b'0' * 40 * 1024 * 1024)
fs = libtorrent.file_storage()
fs.add_file('tmp', size)
t = libtorrent.create_torrent(fs, 0, 4 * 1024 * 1024)
libtorrent.set_piece_hashes(t, dir)
info = libtorrent.torrent_info(t.generate())
btih = sha1(info.metadata()).hexdigest()
return info, btih
async def bind(self, interface: str = '0.0.0.0', port: int = 10889):
settings = {
'listen_interfaces': f"{interface}:{port}",
@ -216,6 +203,20 @@ def get_magnet_uri(btih):
return f"magnet:?xt=urn:btih:{btih}"
def _create_fake_torrent(tmpdir):
# beware, that's just for testing
path = os.path.join(tmpdir, 'tmp')
with open(path, 'wb') as myfile:
size = myfile.write(b'0' * 40 * 1024 * 1024)
file_storage = libtorrent.file_storage()
file_storage.add_file('tmp', size)
t = libtorrent.create_torrent(file_storage, 0, 4 * 1024 * 1024)
libtorrent.set_piece_hashes(t, tmpdir)
info = libtorrent.torrent_info(t.generate())
btih = sha1(info.metadata()).hexdigest()
return info, btih
async def main():
if os.path.exists("~/Downloads/ubuntu-18.04.3-live-server-amd64.torrent"):
os.remove("~/Downloads/ubuntu-18.04.3-live-server-amd64.torrent")

View file

@ -6,19 +6,19 @@ source =
lbry
.tox/*/lib/python*/site-packages/lbry
[cryptography.*,coincurve.*,pbkdf2]
[cryptography.*,coincurve.*,pbkdf2, libtorrent]
ignore_missing_imports = True
[pylint]
jobs=8
ignore=words,server,rpc,schema,winpaths.py,migrator,undecorated.py
extension-pkg-whitelist=libtorrent
max-parents=10
max-args=10
max-line-length=120
good-names=T,t,n,i,j,k,x,y,s,f,d,h,c,e,op,db,tx,io,cachedproperty,log,id,r,iv,ts,l
valid-metaclass-classmethod-first-arg=mcs
disable=
c-extension-no-member,
fixme,
broad-except,
no-else-return,

View file

@ -7,8 +7,7 @@ changedir = {toxinidir}/tests
setenv =
HOME=/tmp
commands =
pip install -U pip
pip install -e 'git+https://github.com/shyba/libtorrent.git#egg=python-libtorrent'
pip install https://s3.amazonaws.com/files.lbry.io/python_libtorrent-1.2.4-py2.py3-none-any.whl
pip install https://github.com/rogerbinns/apsw/releases/download/3.30.1-r1/apsw-3.30.1-r1.zip \
--global-option=fetch \
--global-option=--version --global-option=3.30.1 --global-option=--all \