Last active
April 22, 2016 03:20
-
-
Save ihji/9e886cd6b014b3f139537a9b96378883 to your computer and use it in GitHub Desktop.
upload local ivy cache to nexus hosted remote maven repo
This file contains 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/python3 | |
import sys,os,subprocess | |
from os.path import join,isfile | |
from urllib.parse import urljoin | |
import xml.etree.ElementTree as ET | |
REPO_URL = "http://myrepo/nexus/content/repositories/ivy-releases/" | |
CREDENTIAL = "admin:passwd" | |
def upload(f,url): | |
target_url = urljoin(REPO_URL,url) | |
cmd = ["curl","--upload-file",f,"-u",CREDENTIAL,target_url] | |
print("upload {} -> {}".format(f,target_url)) | |
subprocess.call(cmd) | |
if __name__ == '__main__': | |
target = sys.argv[1] | |
for base, dirs, files in os.walk(target): | |
for name in files: | |
if name.startswith("ivy-") and name.endswith(".xml"): | |
xml = join(base, name) | |
print("processing:", xml) | |
root = ET.parse(xml).getroot() | |
info_attr = root.find("info").attrib | |
organization = info_attr["organisation"] | |
module = info_attr["module"] | |
revision = info_attr["revision"] | |
scala_version = info_attr.get("{http://ant.apache.org/ivy/extra}scalaVersion") | |
sbt_version = info_attr.get("{http://ant.apache.org/ivy/extra}sbtVersion") | |
url_base = [ | |
organization, "/", module, "/", | |
"scala_{}/".format(scala_version) if scala_version else "", | |
"sbt_{}/".format(sbt_version) if sbt_version else "", | |
revision, "/"] | |
ivy_url_list = url_base + ["ivys/ivy.xml"] | |
ivy_url = ''.join(ivy_url_list) | |
upload(xml, ivy_url) | |
artifacts = root.findall("publications/artifact") | |
for a in artifacts: | |
artifacts_attr = a.attrib | |
artifact_name = artifacts_attr["name"] | |
artifact_type = artifacts_attr["type"] | |
artifact_ext = artifacts_attr["ext"] | |
artifact = join(base,"{}s/{}-{}.{}".format(artifact_type,artifact_name,revision,artifact_ext)) | |
artifact_url_list = url_base + [artifact_type, "s/", artifact_name, ".", artifact_ext] | |
artifact_url = ''.join(artifact_url_list) | |
if isfile(artifact): | |
upload(artifact, artifact_url) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment