-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbump
executable file
·183 lines (149 loc) · 5.63 KB
/
bump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/python
# -*- coding: utf-8 -*-
# A semi-automatic bump script
import os
import sys
import pisi
import time
from optparse import OptionParser
RELEASE = """\
<Update release="%s"%s>
<Date>%s</Date>
<Version>%s</Version>
<Comment>%s</Comment>%s
<Name>%s</Name>
<Email>%s</Email>
</Update>
"""
TRANSLATIONS = """\
<?xml version="1.0" ?>
<PISI>
<Source>
<Name>%s</Name>
<Summary xml:lang="tr">Add a summary for the package</Summary>
<Description xml:lang="tr">Add a description for the package.</Description>
</Source>
</PISI>
"""
def get_and_save_user_info():
name = "PACKAGER_NAME"
email = "PACKAGER_EMAIL"
conf_file = os.path.expanduser("~/.packagerinfo")
if os.path.exists(conf_file):
# Read from it
name, email = open(conf_file, "r").read().strip().split(",")
else:
print "Please enter your full name as seen in pspec files"
name = raw_input("> ")
print "Please enter your e-mail as seen in pspec files"
email = raw_input("> ")
print "Saving packager info into %s" % conf_file
open(conf_file, "w").write("%s,%s" % (name, email))
return name, email
def increment_release(pspec, comment, packager_name, packager_email,
critical_packages, sec_packages,
bumptype, version):
last = pisi.specfile.SpecFile("pspec.xml").history[0]
release = int(last.release) + 1
# FIXME: Write something useful to guess version from source archive
# And add comment = "Version bump."
if not version:
version = last.version
date = time.strftime("%Y-%m-%d")
if bumptype:
updatetype = " type=\"%s\"" % bumptype
else:
updatetype=""
crit_or_sec = ""
if sec_packages:
for pkg in sec_packages:
crit_or_sec += "\n <Type package=\"%s\">security</Type>" % pkg
elif critical_packages:
for pkg in critical_packages:
crit_or_sec += "\n <Type package=\"%s\">critical</Type>" % pkg
global RELEASE
new_release = RELEASE % (release, updatetype, date, version, comment,
crit_or_sec,
packager_name,
packager_email)
return pspec.replace("<History>\n", "<History>\n%s" % new_release)
def update_sha1sum(pspec):
sums = []
for archive in pisi.specfile.SpecFile('pspec.xml').source.archive:
uri = os.path.basename(archive.uri)
sh = os.popen("sha1sum /var/cache/pisi/archives/%s" % uri).read().split()[0]
sums.append(sh)
print sums
sumi = 0
if len(sums) > 0:
ret = []
for line in pspec.split("\n"):
if " <Archive" in line:
nls = line.split("sha1sum=\"")
nl = nls[0] + "sha1sum=\"%s\"" % sums[sumi] + nls[1].split("\"", 1)[1]
ret.append(nl)
sumi += 1
else:
ret.append(line)
return "\n".join(ret)
if __name__ == "__main__":
usage = "Usage: %s <Release comment> [Bumped version] [options]"
parser = OptionParser(usage)
parser.add_option("-n", "--no-increment",
dest="no_increment",
default=False,
help="Do not increment release, just update sha1sums.",
action="store_true")
parser.add_option("-c", "--critical",
dest="critical",
default=None,
help="Mark update as critical and add Type=critical for those packages",
action="append")
parser.add_option("-s", "--security",
dest="security",
default=None,
help="Mark update as security and add Type=security for those packages",
action="append")
parser.add_option("--all-critical",
dest="bumptype",
action="store_const",
const="critical",
help="Mark the update critical for all packages [old way]")
parser.add_option("--all-security",
dest="bumptype",
action="store_const",
const="security",
help="Mark the update security for all packages [old way]")
(options,args) = parser.parse_args()
try:
comment = args[0]
except IndexError:
print "You should write a comment for the bump!!"
sys.exit(1)
if len(args) > 1:
version = args[1]
else:
version = None
pspec = open("pspec.xml", "r").read().strip()
# First fetch the tarball
if os.getenv("USER") != "root":
os.system("sudo pisi build pspec.xml --fetch")
else:
os.system("pisi build pspec.xml --fetch")
# Update sha1sum
pspec = update_sha1sum(pspec)
# Add translations.xml
if not os.path.exists("translations.xml"):
open("translations.xml", "w").write(TRANSLATIONS % os.path.basename(os.getcwd()))
os.system("svn add translations.xml")
packager_name, packager_email = get_and_save_user_info()
if options.no_increment:
new_pspec = pspec
else:
# Increment release
new_pspec = increment_release(pspec, comment, packager_name, packager_email,
options.critical, options.security,
options.bumptype, version)
open("pspec.xml", "w").write(new_pspec)
# To put a newline at the end of the pspec.xml
open("pspec.xml", "a").write("\n")