Skip to content

Instantly share code, notes, and snippets.

@jgillis
Created June 24, 2015 06:18
Show Gist options
  • Save jgillis/ed2423a2c680df42a59f to your computer and use it in GitHub Desktop.
Save jgillis/ed2423a2c680df42a59f to your computer and use it in GitHub Desktop.
import os
import subprocess
import io
import shutil
dir = '/home/frs/project/casadi/CasADi/'
shutil.rmtree(os.path.join(dir,'branches'))
os.mkdir(os.path.join(dir,'branches'))
repo = 'casadi'
subprocess.Popen(["git","pull"],cwd=repo).wait()
branchdict = {}
for item in os.listdir(os.path.join(dir,'commits')):
if os.path.isdir(os.path.join(dir,'commits',item)):
print item
out,err = subprocess.Popen(["git","branch","-r","--contains",item],stdout=subprocess.PIPE,cwd=repo).communicate()
branches = [ e.split("/")[1] for e in out.split("\n")[:-1]]
out,err = subprocess.Popen(["git","describe",item],stdout=subprocess.PIPE,cwd=repo).communicate()
hversion = out.rstrip().replace("+-","-").replace("-g",".")
for b in branches:
if "->" in b: continue
entry = (item,hversion,os.stat(os.path.join(dir,'commits',item))[7])
if b=="develop":
b = "develop-branch"
if b in branchdict:
branchdict[b].append(entry)
else:
branchdict[b] = [entry]
for k,v in branchdict.items():
os.mkdir(os.path.join(dir,'branches',k))
with io.open(os.path.join(dir,'branches',k,'README.md'),'w', newline='\r\n') as f:
for r,h,t in sorted(v,key=lambda x: x[2],reverse=True):
f.write(u" * Link [%s](../../commits/%s)\n" % (h,r))
print t
newest_develop = sorted(branchdict["develop-branch"],key=lambda x: x[2],reverse=True)[0][0]
print newest_develop
subprocess.Popen("cp -r /home/project-web/casadi/htdocs/commits/%s/* /home/project-web/casadi/htdocs/" % newest_develop,shell=True).wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment