Skip to content

Commit

Permalink
Changed downloaded packages copied to output_dir
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Moene <[email protected]>
  • Loading branch information
victormlg committed Dec 11, 2024
1 parent 00c7718 commit 42c4afc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
18 changes: 17 additions & 1 deletion cf_remote/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
import os
import shutil
import sys
import time
from multiprocessing.dummy import Pool
Expand All @@ -22,6 +23,7 @@
cf_remote_packages_dir,
)
from cf_remote.utils import (
mkdir,
save_file,
strip_user,
read_json,
Expand Down Expand Up @@ -296,7 +298,21 @@ def _iterate_over_packages(tags=None, version=None, edition=None, download=False
else:
for artifact in artifacts:
if download:
download_package(artifact.url, directory=output_dir)
package_path = download_package(artifact.url)
if output_dir :
output_dir = os.path.normpath(output_dir)
parent = os.path.dirname(output_dir)
if not os.path.exists(parent):
user_error("'{}' doesn't exist. Make sure this path is correct and exists.".format(parent))
mkdir(output_dir)

filename = os.path.basename(artifact.url)
output_path = os.path.join(output_dir, filename)
tmp_filename = '.{}.tmp'.format(filename)
tmp_output_path = os.path.join(output_dir, tmp_filename)

shutil.copyfile(package_path, tmp_output_path)
os.rename(tmp_output_path, output_path)
else:
print(artifact.url)
return 0
Expand Down
1 change: 1 addition & 0 deletions cf_remote/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def cfengine_dir(subdir=None):
override_dir = os.getenv("CF_REMOTE_DIR")

if override_dir:
override_dir = os.path.normpath(override_dir)
parent = os.path.dirname(override_dir)

if not os.path.exists(parent):
Expand Down
5 changes: 2 additions & 3 deletions cf_remote/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ def get_json(url):
return data


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

Expand Down

0 comments on commit 42c4afc

Please sign in to comment.