Skip to content

Commit

Permalink
- new build_prep.py replace build_prep.sh
Browse files Browse the repository at this point in the history
- rel-bump.py replace rel-bump.sh
- new ver-bump.py
  • Loading branch information
midnightercz committed Jan 17, 2014
1 parent 021f2f9 commit 58bbfe3
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 44 deletions.
164 changes: 164 additions & 0 deletions build_prep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#!/bin/env python
import subprocess
import sys
import pprint
import string
import json
from datetime import date

def is_commit_tag(commit):
p = subprocess.Popen(['git', 'describe',
'--tags', "--exact-match", "%s"%commit],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
return p.returncode is 0

def tag_to_commit(tag):
p = subprocess.Popen(['git', 'rev-parse', "%s^{commit}"%tag],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
if p.returncode:
return None
x = p.stdout.readline().strip()
return x

def commits_date(commits):
dates = []
for c in commits:
p = subprocess.Popen(['git', 'log', '-1', "--format=%at", "%s"%c],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
dates.append(int(p.stdout.read()))
return dates

def git_tags_chrono():
p = subprocess.Popen(['git', 'tag'], stdout=subprocess.PIPE)
p.wait()
if p.returncode:
return None
tags = [x.strip() for x in p.stdout]
dates = [commits_date([t]) for t in tags]
return [z[0] for z in sorted(zip(tags, dates), key=lambda x: x[1])]

def git_tags():
p = subprocess.Popen(['git', 'tag'], stdout=subprocess.PIPE)
if p.returncode:
return None
tags = [x.strip() for x in p.stdout]
return tags

def commits_for_tag(tags, tag):
index = tags.index(tag)
#print index
if index == 0:
prev = None
else:
prev = tags[index-1]
prev = tag_to_commit(prev)
tag = tag_to_commit(tag)
#print prev

commits = []
p = subprocess.Popen(['git', 'rev-list', '--all'], stdout=subprocess.PIPE)
start = False
for x in p.stdout:
x = x.strip()
#print x,tag
if not start and x == tag:
start = True
#print "start true"
if start:
commits.append(x)
if x == prev:
break
return commits

def log_for_commits(commits, _format=None):
log = []
if not _format:
_args = ['git', 'log', '-1']
else:
_args = ['git', 'log', '-1', '--format=%s'%_format]
for x in commits:
#print x
p = subprocess.Popen(_args + [x], stdout=subprocess.PIPE)
log.append([x.rstrip("\n") for x in p.stdout])
return log

def format_chlog_msg(msg):
msg = filter(lambda x: x != "", msg)
for x in range(0, len(msg)):
if not msg[x].startswith("- "):
msg[x] = "- "+msg[x]
return msg

def build_chlog(tags ,top='HEAD'):
f = open("chcommits", "r")
chcommits = set([x.strip() for x in f])
f.close()

log = []
for tag in tags:
head = log_for_commits([tag], _format="%ct%n%cn <%ce>%n%B")
head = ["*"]+head[0]
head_body = head[3:]
head = head[:3]
head[1] = date.fromtimestamp(int(head[1])).strftime("%a %b %d %Y")
head.append("-".join(tag.split("-")[1:]))
#print head

commits = commits_for_tag(tags, tag)
loc_chcommits = list(chcommits & set(commits))
loc_log = log_for_commits(loc_chcommits, _format="%B")
_log = [" ".join(head)]
_log.append("\n".join(format_chlog_msg(head_body)))
for x in loc_log:
_log.append("\n".join(format_chlog_msg(x)))
_log.append("")
#print _log

log.append("\n".join(_log))
return reversed(log)

if __name__ == "__main__":
vfp = open("version.json", "r")
version = json.load(vfp)
vfp.close()

subs = {}
try:
top_commit = tag_to_commit(sys.argv[1])
subs["GITREVLONG"] = tag_to_commit(sys.arv[1])
except IndexError:
top_commit = tag_to_commit("HEAD")
subs["GITREVLONG"] = tag_to_commit(top_commit)



subs.update(version)
tags = git_tags_chrono()
subs["CHANGELOG"] = "\n".join(build_chlog(tags, top_commit))

if not is_commit_tag(top_commit):
subs["SOURCE_URL_PATH"] = "archive/%{commit}/libcomps-%{commit}.tar.gz"
archive_name = "libcomps-%s.tar.gz"%(top_commit,)
else:
subs["SOURCE_URL_PATH"] = tags[-1]+".tar.gz"
archive_name = "%s.tar.gz"%(top_commit,)

subs["VERSION"] = "%s.%s.%s" % (subs["libcomps_VERSION_MAJOR"],
subs["libcomps_VERSION_MINOR"],
subs["libcomps_VERSION_PATCH"])
spec = open("libcomps.spec.in", "r")
specstr_in = spec.read()
spec.close()
specstr_out = string.Template(specstr_in).safe_substitute(subs)
spec = open("libcomps.spec", "w")
spec.write(specstr_out)
spec.close()

p = subprocess.Popen(['git', 'archive', top_commit, "--format=tar.gz",
"--prefix=libcomps-%s/"%(top_commit,), "-o",
archive_name])#,
#stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait()
26 changes: 0 additions & 26 deletions build_prep.sh

This file was deleted.

22 changes: 22 additions & 0 deletions chcommits
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
946584c5a01d83bf9ec4c26d3f9d73e37bfb5456
76764059f1085abbd0eeaeab64f45ec48a58ba4d
4e16e2a76d3ea6f3fd4d162b177fd8e45a641bf9
9a3e8428587ecb787d0febcf11d299f4c62488ed
5500d1275ce9288a763c957a23525aae25f283fb
e401de99222bac95e61b10836b230367a92f5e4f
f243b574c801244447b873c8e77b82b3318c09d4
5500d1275ce9288a763c957a23525aae25f283fb
997835ec69b72ded9acbd785502c5f3bbf888be8
8108808bbcdfacbb2732536ddcc05cd44318dd9c
08008e492804c488a4a97712785ed99880343d69
36fd42e21c7a4aaf605d8bd9407ae9023c1b95e3
706260866c0d2d5f48992d2140b96bf9f2b2a988
bba023bbfe75c628296cca40ffd96b2307a3c969
9c5895fd7e79884fe4e1e9d4aa7baa7d7207669d
e712e7584701de6ef05a160fc4e13d5cbff14192
06da994e7cfee729475e0bb134b1687fee45da5b
0a15705507075e32e929941b290ee8f2efeeb1f0
941627d53245ec695533520835ed1d2d3cc325d0
15c445abbed24beca686682d30dcff3d7b368478
c8faed2c202b6f1e788a1b4ba819487a4006537d

10 changes: 5 additions & 5 deletions libcomps.spec.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
%global commit @GITREVLONG@
%global commit ${GITREVLONG}

Name: libcomps
Version: @VERSION@
Release: @libcomps_RELEASE@%{?dist}
Version: ${VERSION}
Release: ${libcomps_RELEASE}%{?dist}
Summary: Comps XML file manipulation library

Group: Development/Libraries
License: GPLv2+
URL: https://github.com/midnightercz/libcomps/
Source0: https://github.com/midnightercz/libcomps/@SOURCE_URL_PATH@
Source0: https://github.com/midnightercz/libcomps/${SOURCE_URL_PATH}
BuildRequires: libxml2-devel
BuildRequires: check-devel
BuildRequires: expat-devel
Expand Down Expand Up @@ -132,4 +132,4 @@ rm -rf $buildroot


%changelog
@CHANGELOG@
${CHANGELOG}
2 changes: 1 addition & 1 deletion libcomps/version.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set (libcomps_VERSION_MAJOR 0)
set (libcomps_VERSION_MINOR 1)
set (libcomps_VERSION_PATCH 6)
set (libcomps_VERSION_PATCH 9)
set (libcomps_RELEASE 1)

8 changes: 4 additions & 4 deletions libcomps/version.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set (libcomps_VERSION_MAJOR @libcomps_VERSION_MAJOR@)
set (libcomps_VERSION_MINOR @libcomps_VERSION_MINOR@)
set (libcomps_VERSION_PATCH @libcomps_VERSION_PATCH@)
set (libcomps_RELEASE @libcomps_RELEASE@)
set (libcomps_VERSION_MAJOR ${libcomps_VERSION_MAJOR})
set (libcomps_VERSION_MINOR ${libcomps_VERSION_MINOR})
set (libcomps_VERSION_PATCH ${libcomps_VERSION_PATCH})
set (libcomps_RELEASE ${libcomps_RELEASE})

4 changes: 0 additions & 4 deletions rel-bump.cmake

This file was deleted.

24 changes: 24 additions & 0 deletions rel-bump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/env python
import json
import sys
import string

if __name__ == "__main__":
f = open("version.json", "r")
version = json.load(f)
f.close()
version["libcomps_RELEASE"] += 1

f = open("version.json", "w")
json.dump(version, f, indent=4)
f.close()

f = open("libcomps/version.cmake.in", "r")
version_in = f.read()
f.close()

version_out = string.Template(version_in).substitute(version)
f = open("libcomps/version.cmake", "w")
f.write(version_out)
f.close()

4 changes: 0 additions & 4 deletions rel-bump.sh

This file was deleted.

32 changes: 32 additions & 0 deletions ver-bump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/env python
import json
import sys
import string

if __name__ == "__main__":
f = open("version.json", "r")
version = json.load(f)
f.close()
try:
if sys.argv[1] == "major":
version["libcomps_VERSION_MAJOR"] += 1
elif sys.argv[1] == "minor":
version["libcomps_VERSION_MINOR"] += 1
elif sys.argv[1] == "patch":
version["libcomps_VERSION_PATCH"] += 1
except IndexError:
version["libcomps_VERSION_PATCH"] += 1

f = open("version.json", "w")
json.dump(version, f, indent=4)
f.close()

f = open("libcomps/version.cmake.in", "r")
version_in = f.read()
f.close()

version_out = string.Template(version_in).substitute(version)
f = open("libcomps/version.cmake", "w")
f.write(version_out)
f.close()

6 changes: 6 additions & 0 deletions version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"libcomps_VERSION_MAJOR": 0,
"libcomps_RELEASE": 1,
"libcomps_VERSION_MINOR": 1,
"libcomps_VERSION_PATCH": 6
}

0 comments on commit 58bbfe3

Please sign in to comment.