Skip to content
Snippets Groups Projects
Commit 47866878 authored by www user for firmware's avatar www user for firmware
Browse files

move symlink creation to python

parent 14ed058c
No related branches found
No related tags found
No related merge requests found
...@@ -8,9 +8,4 @@ PIPELINE_ID_FILE="/home/www/html/firmware/gluon/.last-downloaded-pipeline-id" ...@@ -8,9 +8,4 @@ PIPELINE_ID_FILE="/home/www/html/firmware/gluon/.last-downloaded-pipeline-id"
MYDIR=$(readlink -f $(dirname "$0")) MYDIR=$(readlink -f $(dirname "$0"))
cd "$ARCHIVE_DIR" cd "$ARCHIVE_DIR"
downloaded_version=$("$MYDIR/download-latest-firmware-build.py" --pipeline-id-file "$PIPELINE_ID_FILE") "$MYDIR/download-latest-firmware-build.py" --pipeline-id-file "$PIPELINE_ID_FILE" --create-symlink "$EXPERIMENTAL_LINK"
downloaded_version_abs=$(readlink -f "$downloaded_version/images")
rm "$EXPERIMENTAL_LINK"
ln -s "$downloaded_version_abs" "$EXPERIMENTAL_LINK"
...@@ -17,6 +17,7 @@ PROJECT_ID = 1 ...@@ -17,6 +17,7 @@ PROJECT_ID = 1
ap = argparse.ArgumentParser() ap = argparse.ArgumentParser()
ap.add_argument("--pipeline-id", help="Pipeline ID to download. If omitted, download latest successfull.", default=None) ap.add_argument("--pipeline-id", help="Pipeline ID to download. If omitted, download latest successfull.", default=None)
ap.add_argument("--pipeline-id-file", help="Store downloaded Pipeline ID in this file and only download if latest pipeline ID doesn't match file contents") ap.add_argument("--pipeline-id-file", help="Store downloaded Pipeline ID in this file and only download if latest pipeline ID doesn't match file contents")
ap.add_argument("--create-symlink", help="Create symlink to downloaded firmware at the specified path")
args = ap.parse_args() args = ap.parse_args()
def find_version_from_archive(archive_file_list): def find_version_from_archive(archive_file_list):
...@@ -32,11 +33,11 @@ def find_version_from_archive(archive_file_list): ...@@ -32,11 +33,11 @@ def find_version_from_archive(archive_file_list):
def extract_zip(artifact_zipfile): def extract_zip(artifact_zipfile):
with zipfile.ZipFile(artifact_zipfile) as artifact_zip: with zipfile.ZipFile(artifact_zipfile) as artifact_zip:
version = find_version_from_archive(artifact_zip.infolist()) version = find_version_from_archive(artifact_zip.infolist())
print(f"Version is {version}")
with tempfile.TemporaryDirectory(dir=os.getcwd()) as tempdir: with tempfile.TemporaryDirectory(dir=os.getcwd()) as tempdir:
artifact_zip.extractall(tempdir) artifact_zip.extractall(tempdir)
outputdir = os.path.join(tempdir, "gluon", "output") outputdir = os.path.join(tempdir, "gluon", "output")
os.rename(outputdir, version) os.rename(outputdir, version)
return version
def find_latest_pipeline_id(): def find_latest_pipeline_id():
pipelines_request = requests.get("{}/projects/{}/pipelines".format(GITLAB_API_BASE, PROJECT_ID)) pipelines_request = requests.get("{}/projects/{}/pipelines".format(GITLAB_API_BASE, PROJECT_ID))
...@@ -74,7 +75,14 @@ for job in pipeline_jobs: ...@@ -74,7 +75,14 @@ for job in pipeline_jobs:
for chunk in artifact_request.iter_content(chunk_size=1024*1024): for chunk in artifact_request.iter_content(chunk_size=1024*1024):
artifact_temp.write(chunk) artifact_temp.write(chunk)
extract_zip(artifact_temp) downloaded_version = extract_zip(artifact_temp)
if args.create_symlink:
if os.path.islink(args.create_symlink):
os.remove(args.create_symlink)
images_dir = os.path.abspath(os.path.join(downloaded_version, "images"))
os.symlink(images_dir, args.create_symlink)
if args.pipeline_id_file: if args.pipeline_id_file:
with open(args.pipeline_id_file, "w") as pipeline_id_file: with open(args.pipeline_id_file, "w") as pipeline_id_file:
pipeline_id_file.write(str(pipeline_id)) pipeline_id_file.write(str(pipeline_id))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment