Skip to content

Commit

Permalink
Added --output-dir flag in download command
Browse files Browse the repository at this point in the history
Ticket: CFE-3684
Signed-off-by: Victor Moene <victor.moene@northern.tech>
  • Loading branch information
victormlg committed Dec 12, 2024
1 parent 6fccfb4 commit 181689e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions cf_remote/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def install(
return errors


def _iterate_over_packages(tags=None, version=None, edition=None, download=False):
def _iterate_over_packages(tags=None, version=None, edition=None, download=False, output_dir=None):
releases = Releases(edition)
print("Available releases: {}".format(releases))

Expand All @@ -296,7 +296,7 @@ def _iterate_over_packages(tags=None, version=None, edition=None, download=False
else:
for artifact in artifacts:
if download:
download_package(artifact.url, checksum=artifact.checksum)
download_package(artifact.url, directory=output_dir, checksum=artifact.checksum)
else:
print(artifact.url)
return 0
Expand All @@ -307,8 +307,8 @@ def list_command(tags=None, version=None, edition=None):
return _iterate_over_packages(tags, version, edition, False)


def download(tags=None, version=None, edition=None):
return _iterate_over_packages(tags, version, edition, True)
def download(tags=None, version=None, edition=None, output_dir=None):
return _iterate_over_packages(tags, version, edition, True, output_dir)


def _get_aws_creds_from_env():
Expand Down
8 changes: 7 additions & 1 deletion cf_remote/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def _get_arg_parser():
)
sp.add_argument("tags", metavar="TAG", nargs="*")

sp.add_argument("--output-dir",
"-o",
help="Where to download",
type=str
)

sp = subp.add_parser(
"run", help="Run the command given as arguments on the given hosts"
)
Expand Down Expand Up @@ -310,7 +316,7 @@ def run_command_with_args(command, args):
)
elif command == "download":
return commands.download(
tags=args.tags, version=args.version, edition=args.edition
tags=args.tags, version=args.version, edition=args.edition, output_dir=args.output_dir
)
elif command == "run":
return commands.run(hosts=args.hosts, raw=args.raw, command=args.remote_command)
Expand Down
5 changes: 3 additions & 2 deletions cf_remote/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ def get_json(url):
return data


def download_package(url, path=None, checksum=None):
def download_package(url, path=None, directory=None, checksum=None):


if checksum and not SHA256_RE.match(checksum):
user_error("Invalid checksum or unsupported checksum algorithm: '%s'" % checksum)

if not path:
filename = os.path.basename(url)
directory = cf_remote_packages_dir()
if not directory :
directory = cf_remote_packages_dir()
mkdir(directory)
path = os.path.join(directory, filename)

Expand Down

0 comments on commit 181689e

Please sign in to comment.