Skip to content

Commit

Permalink
Fix some download content bugs. Show progress status on terminal if r…
Browse files Browse the repository at this point in the history
…un as a cli
  • Loading branch information
Manish Kumar committed Feb 12, 2020
1 parent 88a6e67 commit e16620d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ src/py2pip/config.py
src/py2pip/parser.py
src/py2pip/process.py
src/py2pip/simulator.py
src/py2pip/utils.py
4 changes: 4 additions & 0 deletions scripts/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e

# Ensure local dir set
mkdir -p ~/.local/py2pip
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ def read(*names):
"Development Status :: 5 - Production/Stable",
"Environment :: No Input/Output (Daemon)",
"Framework :: AsyncIO",
"Framework :: Scrapy",
"Framework :: aiohttp",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3 :: Only",
'License :: OSI Approved :: MIT License',
"Operating System :: POSIX :: Linux",
"Topic :: Internet :: WWW/HTTP",
Expand Down Expand Up @@ -86,7 +87,7 @@ def read(*names):
],
entry_points={
'console_scripts': [
'py2pip=__main__:main',
'py2pip=py2pip.__main__:main',
]
},
cmdclass={
Expand Down
4 changes: 2 additions & 2 deletions src/py2pip/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ def main():
log_file_path = pathlib.Path(option.log_file_name)
log = get_logger(log_file_path, option.enable_debug)

py2pip_manager = Py2PIPManager(option.package, option.python_support, option.install, log)
py2pip_manager = Py2PIPManager(option.package, option.python_support, option.install, log, show_progress=True)

stime = time.time()
result = py2pip_manager.run()
etime = time.time()
print(f'Support Version: {result}\nExecution time: {etime - stime}')
print(f'Execution time: {etime - stime}\nSupported Version: {result}\n')

except ValueError as e:
print(f'Error: {str(e)}')
Expand Down
4 changes: 4 additions & 0 deletions src/py2pip/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ async def process(self, content, py_version, pkg_version):
version_ul_node = soup.find('div', attrs={'class': 'vertical-tabs__tabs'}).find(
'ul', attrs={'class': 'sidebar-section__classifiers'})

if not version_ul_node:
self.log.debug('No classifiers found. {pkg_version}')
return

for li in version_ul_node.children:
if isinstance(li, str):
continue
Expand Down
33 changes: 30 additions & 3 deletions src/py2pip/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import asyncio
import subprocess
import sys
import time

from py2pip import config
from py2pip.parser import ParseHistoryHTML, ParsePackageVersionHTML
Expand Down Expand Up @@ -33,20 +34,32 @@ def __init__(self, project_name, support_py_version, install=False, log=Logger()
"""
self.package_history_url = config.PIPServer.HOST + config.PIPServer.PATH.format(project=project_name)
self.log = log
self.running = True

self.package = project_name
self.install = install
self.support_py_version = support_py_version
self.enable_event_debug = kwargs.get('enable_debug', False)
self.show_progress = kwargs.get('show_progress', False) # Show the progress status on Terminal

self.history_page_parser = ParseHistoryHTML(self.log)
self.history_versions_page_parser = ParsePackageVersionHTML(self.log)

async def show_progress_msg(self):
while True:
if not self.running:
return
print('Running', end="\r")
for i in range(4):
await asyncio.sleep(.3)
print(f"Running{'.'*i}", end="\r")

await asyncio.sleep(.5)

def start(self):
self.log.info(f'Commence io loop...')
self.loop = asyncio.get_event_loop()
self.loop.set_debug(enabled=self.enable_event_debug)

self.loop.run_until_complete(self.process_package_history_page()) # close will have no effect if called with run_until_complete

def get_support_pkg_version(self):
Expand All @@ -59,6 +72,7 @@ def run(self):
self.start()

# Return value upon completion
self.running = False
return self.get_support_pkg_version()

async def process_versions_page(self, session):
Expand All @@ -72,6 +86,8 @@ async def process_versions_page(self, session):
for pkg_version, pkg_data in version_list.items():
url = pkg_data['url']
await self.read_version_page(session, url, pkg_version)
else:
self.running = False

async def read_version_page(self, session, url, package_version):
"""
Expand All @@ -98,7 +114,18 @@ async def process_history_page(self, session):
self.log.error(f'{response.status}: PyPi Package {self.package_history_url} is {response.reason}')

async def process_package_history_page(self):
self.log.info('Create client session and read page')

if self.show_progress:
task = asyncio.create_task(self.show_progress_msg())

async with aiohttp.ClientSession() as session:
await self.process_history_page(session)
if self.history_page_parser.get_versions():
await self.process_versions_page(session)
if not self.history_page_parser.get_versions():
self.running = False
return

await self.process_versions_page(session)

if self.show_progress:
await task
4 changes: 0 additions & 4 deletions src/py2pip/scripts/postinstall.sh

This file was deleted.

0 comments on commit e16620d

Please sign in to comment.