Skip to content

Commit 2af57ba

Browse files
committed
Unzip the notice files end with gz
1 parent fd428e6 commit 2af57ba

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/fosslight_android/check_notice_file.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from ._common import NOTICE_FILE_NAME
1111
from fosslight_util.constant import LOGGER_NAME
1212
import re
13+
import gzip
14+
import shutil
1315

1416
logger = logging.getLogger(LOGGER_NAME)
1517
CANNOT_FIND_MSG = "CANNOT_FIND_NOTICE_HTML"
@@ -73,11 +75,24 @@ def find_bin_in_notice(binary_file_name, notice_file_list):
7375

7476
def find_files_by_extension(path):
7577
extensions = ['.html', '.xml']
78+
GZ_EXTENSION = '.gz'
7679
files = []
80+
try:
81+
gz_files = [os.path.join(path, f) for f in os.listdir(path) if f.endswith(GZ_EXTENSION)]
82+
for gz_file in gz_files:
83+
unzip_file = gz_file.replace('.gz', '')
84+
if not os.path.isfile(unzip_file):
85+
with gzip.open(gz_file, 'rb') as f_in:
86+
with open(unzip_file, 'wb') as f_out:
87+
shutil.copyfileobj(f_in, f_out)
88+
except Exception as error:
89+
logger.info(f"Fail unzip gz file:{error}")
90+
7791
for extension in extensions:
7892
files = [os.path.join(path, f) for f in os.listdir(path) if f.endswith(extension)]
7993
if len(files) > 0:
8094
break
95+
8196
return files
8297

8398

0 commit comments

Comments
 (0)