Skip to content

Instantly share code, notes, and snippets.

@paul-hammant
Last active May 14, 2017 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paul-hammant/919a735c80c619f8e78b9d5d1b47c6b6 to your computer and use it in GitHub Desktop.
Save paul-hammant/919a735c80c619f8e78b9d5d1b47c6b6 to your computer and use it in GitHub Desktop.
Git as part of Maven Central?
# pip3 install sh
from sh import wget, unzip, mkdir, cd, git, touch, rm, du
root = "http://central.maven.org/maven2/"
def doGAV(url, v, suffix):
op = wget("-qO-", root + url + "/" + v + "/index.html")
for line in op.splitlines():
if v + suffix + ".jar\"" in line:
fn = line.split("\"")[1].replace("/","")
print(fn)
git("rm", "-r", "*")
git("commit", "-m", v)
wget(root + url + "/" + v + "/" + fn)
sizeK = int(du("-s", "-k", fn).split("\t")[0])
unzip(fn)
rm(fn)
git("add", ".")
git("commit", "-m", v, "--amend")
git("tag", v)
return sizeK
return 0
def doGA(g, a, suffix):
url = g.replace(".","/") + "/" + a
op = wget("-qO-", root + url + "/index.html")
versions = []
sizeK = []
for line in op.splitlines():
if "href" in line and ".." not in line and "maven-metadata.xml" not in line:
v = line.split("\"")[1].replace("/","")
versions.append(v)
# Sorting not needed - not change in the size of the .git folder
# - diffs might look a mess though
# - breaks anyway on alpha chars
# versions.sort(key=lambda s: [int(u) for u in s.split('.')])
print(str(versions))
for v in versions:
sizeK.append(doGAV(url, v, suffix))
ct = 0
totSize = 0
for v in sizeK:
if v > 0:
ct += 1
totSize += v
print("For " + g + ":" + a + ", total size for " + str(ct) + " original versions: " + "{0:.{1}f}".format(totSize/1024,1) + "M")
git("repack", "-ad")
afterK = int(du("-s", "-k", ".git").split("\t")[0])
print("Afterwards the .git folder is: " + "{0:.{1}f}".format(afterK/1024,1) + "M")
rm("-rf", "work")
mkdir("work")
cd("work")
git("init")
touch("dummy")
git("add", ".")
git("commit", "-m", "start")
# TODO make is so that you could invoke doGA() time in one script
doGA("com.thoughtworks.xstream", "xstream", "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment