Created
November 14, 2018 09:18
-
-
Save kumbasar/1ba2d1f49b7cfbb6efc51e24b65a004f to your computer and use it in GitHub Desktop.
Download the latest sub folder content from Artifactory using Python and wget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# pip3 install artifactory | |
import os | |
from artifactory import ArtifactoryPath | |
from pathlib import Path | |
ARTIFACTORY_URL = "https://localhost:8081/artifactory" | |
ARTIFACTORY_USER = 'admin' | |
ARTIFACTORY_APIKEY = 'admin' | |
ARTIFACTORY_PROJECT = "test/folder" | |
path = ArtifactoryPath(ARTIFACTORY_URL + '/' + ARTIFACTORY_PROJECT, auth=(ARTIFACTORY_USER, ARTIFACTORY_APIKEY), verify=False) | |
for p in path.glob("*.*.*"): | |
print(p) | |
latest_release = max(path.glob("*.*.*")) | |
path = ArtifactoryPath(latest_release, auth=(ARTIFACTORY_USER, ARTIFACTORY_APIKEY),verify=True) | |
for p in path: | |
print(p) | |
latest_build = max(path) | |
path = ArtifactoryPath(latest_build, auth=(ARTIFACTORY_USER, ARTIFACTORY_APIKEY),verify=True) | |
for p in path: | |
print(p) | |
print('\n\nLatest release build: ' + str(latest_build)) | |
print('\nBuild Release: ' + str(latest_build).split('/')[-2]) | |
print('Build Number: ' + str(latest_build).split('/')[-1]) | |
if not os.path.exists(ARTIFACTORY_PROJECT): | |
os.makedirs(ARTIFACTORY_PROJECT) | |
os.system('wget --user ' + ARTIFACTORY_USER + ' --password '+ ARTIFACTORY_APIKEY +' --directory-prefix ' + ARTIFACTORY_PROJECT + ' -r --no-parent -nH --cut-dirs=5 --reject "index.html*,' + str(latest_build).split('/')[-1] + '*" ' + str(latest_build)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Folder Structure:
test/folder
-- 1
-- 2
--- builds