From a0a2a0e57156fba738651baf8ff9e60334808e52 Mon Sep 17 00:00:00 2001 From: Jiyeong Seok Date: Wed, 23 Feb 2022 14:47:48 +0900 Subject: [PATCH] Modify to get the source url for pypi Signed-off-by: Jiyeong Seok --- src/fosslight_util/_get_downloadable_url.py | 17 ++++++++--------- tests/test_download.py | 5 ++++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/fosslight_util/_get_downloadable_url.py b/src/fosslight_util/_get_downloadable_url.py index 760a91e..66e45cd 100755 --- a/src/fosslight_util/_get_downloadable_url.py +++ b/src/fosslight_util/_get_downloadable_url.py @@ -46,15 +46,14 @@ def get_download_location_for_pypi(link): content = urlopen(pypi_url).read().decode('utf8') bs_obj = BeautifulSoup(content, 'html.parser') - tr_list = bs_obj.find('div', {'id': 'files'}).findAll('tr') - for i in tr_list: - td = i.findAll('td') - for td_i in td: - str_i = str(td_i).replace('\n', ' ') - if re.findall(r'File type[\s]*(Source)[\s]*', str_i): - new_link = i.find('a').attrs['href'] - ret = True - break + card_file_list = bs_obj.findAll('div', {'class': 'card file__card'}) + + for card_file in card_file_list: + file_code = card_file.find('code').text + if file_code == "source": + new_link = card_file.find('a').attrs['href'] + ret = True + break except Exception as error: ret = False logger.warning('Cannot find the link for pypi (url:'+link+') '+str(error)) diff --git a/tests/test_download.py b/tests/test_download.py index 9fe3c59..78a4ae0 100755 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -6,7 +6,10 @@ def main(): - cli_download_and_extract("https://github.com/LGE-OSS/example", "test_result/download", "test_result/download_log") + cli_download_and_extract("https://github.com/LGE-OSS/example", + "test_result/download/example", "test_result/download_log/example") + cli_download_and_extract("https://pypi.org/project/filelock/3.4.1", + "test_result/download/filelock", "test_result/download_log/filelock") if __name__ == '__main__':