Skip to content

Commit bd606e6

Browse files
committed
Add additional argument fosslight_download
Signed-off-by: 석지영/책임연구원/SW공학(연)Open Source TP <[email protected]>
1 parent a01db74 commit bd606e6

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/fosslight_util/download.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import re
2828
from typing import Tuple
2929
import urllib.parse
30+
import json
3031

3132
logger = logging.getLogger(constant.LOGGER_NAME)
3233
compression_extension = {".tar.bz2", ".tar.gz", ".tar.xz", ".tgz", ".tar", ".zip", ".jar", ".bz2"}
@@ -96,7 +97,8 @@ def parse_src_link(src_link):
9697
def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_to: str = "",
9798
compressed_only: bool = False, ssh_key: str = "",
9899
id: str = "", git_token: str = "",
99-
called_cli: bool = True) -> Tuple[bool, str, str, str]:
100+
called_cli: bool = True,
101+
output: bool = False) -> Tuple[bool, str, str, str]:
100102
global logger
101103

102104
success = True
@@ -155,6 +157,17 @@ def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_
155157
success = False
156158
msg = str(error)
157159

160+
if output:
161+
output_result = {
162+
"success": success,
163+
"message": msg,
164+
"oss_name": oss_name,
165+
"oss_version": oss_version
166+
}
167+
output_json = os.path.join(log_dir, "fosslight_download_output.json")
168+
with open(output_json, 'w') as f:
169+
json.dump(output_result, f, indent=4)
170+
158171
logger.info(f"\n* FOSSLight Downloader - Result: {success} ({msg})")
159172
return success, msg, oss_name, oss_version
160173

@@ -478,10 +491,16 @@ def main():
478491
parser.add_argument('-s', '--source', help='Source link to download', type=str, dest='source')
479492
parser.add_argument('-t', '--target_dir', help='Target directory', type=str, dest='target_dir', default="")
480493
parser.add_argument('-d', '--log_dir', help='Directory to save log file', type=str, dest='log_dir', default="")
494+
parser.add_argument('-c', '--checkout_to', help='Checkout to specific branch or tag', type=str, dest='checkout_to', default="")
495+
parser.add_argument('-z', '--compressed_only', help='Download only compressed files', action='store_true', dest='compressed_only', default=False)
496+
parser.add_argument('-o', '--output', help='Generate output file', action='store_true', dest='output', default=False)
481497

482498
src_link = ""
483499
target_dir = os.getcwd()
484500
log_dir = os.getcwd()
501+
checkout_to = ""
502+
compressed_only = False
503+
output = False
485504

486505
try:
487506
args = parser.parse_args()
@@ -496,11 +515,19 @@ def main():
496515
target_dir = args.target_dir
497516
if args.log_dir:
498517
log_dir = args.log_dir
518+
if args.checkout_to:
519+
checkout_to = args.checkout_to
520+
if args.compressed_only:
521+
compressed_only = args.compressed_only
522+
if args.output:
523+
output = args.output
499524

500525
if not src_link:
501526
print_help_msg_download()
502527
else:
503-
cli_download_and_extract(src_link, target_dir, log_dir)
528+
cli_download_and_extract(src_link, target_dir, log_dir, checkout_to,
529+
compressed_only, "", "", "", False,
530+
output)
504531

505532

506533
if __name__ == '__main__':

0 commit comments

Comments
 (0)