Skip to content

Instantly share code, notes, and snippets.

@GeoffWilliams
Last active July 17, 2021 05:19
Show Gist options
  • Save GeoffWilliams/04d169c0b3e2f2148061dc1a5d195eda to your computer and use it in GitHub Desktop.
Save GeoffWilliams/04d169c0b3e2f2148061dc1a5d195eda to your computer and use it in GitHub Desktop.
Quick and dirty python script to output human readable artifact names for large downloads
#!/usr/bin/env python
"""artifactory download size
Usage:
artifactory_download_size.py <filename>
artifactory_download_size.py (-h | --help)
Options:
-h --help Show this screen
"""
from docopt import docopt
import json
import operator
from boltons.strutils import bytes2human
if __name__ == '__main__':
arguments = docopt(__doc__)
# input is obtained from artifactory:
# RT_USERNAME=...
# RT_PASSWORD=...
# curl -H "Content-Type: text/plain" -X POST -u$RT_USERNAME:$RT_PASSWORD \
# https://declarativesystems.jfrog.io/artifactory/api/search/aql \
# --data 'items.find().include("name", "repo", "size", "path", "stat.downloads")' > somefile.json
f = open(arguments["<filename>"])
data = json.load(f)
f.close()
# results is query output
print(f"data.results:{len(data['results'])}")
for item in data["results"]:
# bytes downloaded
item["bytes_downloaded"] = item["size"] * item["stats"][0]["downloads"]
data["results"].sort(key=operator.itemgetter('bytes_downloaded'))
print("name,\tpath,\tsize,\tdownloaded,\t bytes")
for item in data["results"]:
# only interestd in >5GB
if item['bytes_downloaded'] > 50000000000:
human_downloaded = bytes2human(item['bytes_downloaded'])
human_size = bytes2human(item['size'])
print(f"{item['name']}, {item['path']},\t {human_size},\t {human_downloaded},\t{item['bytes_downloaded']} ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment