2013-07-09 09:06:41 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
import webnotes, os, subprocess, tempfile, json, datetime
|
|
|
|
|
|
|
|
@webnotes.whitelist()
|
|
|
|
def get():
|
|
|
|
with open("../app/home/page/latest_updates/latest_updates.json", "r") as lufile:
|
|
|
|
return json.loads(lufile.read())
|
|
|
|
|
|
|
|
def make():
|
|
|
|
def add_to_logs(out, repo):
|
|
|
|
out.seek(0)
|
|
|
|
last_commit = None
|
|
|
|
for l in out.readlines():
|
|
|
|
if last_commit is not None:
|
|
|
|
if l.startswith("Date:"):
|
|
|
|
last_commit["date"] = l[8:-1]
|
|
|
|
last_commit["datetime"] = datetime.datetime.strptime(last_commit["date"][:-6], "%a %b %d %H:%M:%S %Y")
|
|
|
|
if l.startswith("Author:"):
|
|
|
|
last_commit["author"] = l[8:-1]
|
|
|
|
if l.startswith(" "):
|
|
|
|
last_commit["message"] = l[4:-1]
|
2013-07-09 11:12:36 +00:00
|
|
|
|
2013-07-09 09:06:41 +00:00
|
|
|
if l.startswith("commit"):
|
|
|
|
last_commit = {
|
|
|
|
"repo": repo,
|
|
|
|
"commit": l.split(" ")[1][:-1]
|
|
|
|
}
|
|
|
|
logs.append(last_commit)
|
|
|
|
|
|
|
|
os.chdir("lib")
|
|
|
|
logs = []
|
|
|
|
out_lib = tempfile.TemporaryFile()
|
2013-07-09 11:12:36 +00:00
|
|
|
subprocess.call("git --no-pager log -n 200 --no-color", shell=True, stdout=out_lib)
|
2013-07-09 09:06:41 +00:00
|
|
|
add_to_logs(out_lib, "lib")
|
|
|
|
|
|
|
|
os.chdir("../app")
|
|
|
|
out_app = tempfile.TemporaryFile()
|
2013-07-09 11:12:36 +00:00
|
|
|
subprocess.call("git --no-pager log -n 200 --no-color", shell=True, stdout=out_app)
|
2013-07-09 09:06:41 +00:00
|
|
|
add_to_logs(out_app, "app")
|
|
|
|
|
|
|
|
logs.sort(key=lambda a: a["datetime"], reverse=True)
|
|
|
|
for a in logs:
|
|
|
|
del a["datetime"]
|
|
|
|
|
|
|
|
for i in xrange(len(logs)):
|
|
|
|
if i and logs[i]["message"]==logs[i-1]["message"]:
|
|
|
|
logs[i]["delete"] = True
|
|
|
|
|
|
|
|
if logs[i]["message"].startswith("Merge branch") or "[" not in logs[i]["message"]:
|
|
|
|
logs[i]["delete"] = True
|
|
|
|
|
|
|
|
logs = filter(lambda a: a if not a.get("delete") else None, logs)
|
|
|
|
|
|
|
|
os.chdir("..")
|
|
|
|
with open("app/home/page/latest_updates/latest_updates.json", "w") as lufile:
|
|
|
|
lufile.write(json.dumps(logs, indent=1, sort_keys=True))
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
make()
|