-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease_pothos_repo
executable file
·139 lines (114 loc) · 4.67 KB
/
release_pothos_repo
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
#!/usr/bin/env python3
import os
import re
import sys
import datetime
import email.utils
from pothos_scripts_common import *
def main():
#resources to write
repoDir = os.path.abspath(sys.argv[1])
assert(os.path.exists(repoDir))
changelogPath = os.path.join(repoDir, 'Changelog.txt')
debChangelogPath = os.path.join(repoDir, 'debian', 'changelog')
debControlPath = os.path.join(repoDir, 'debian', 'control')
debCopyrightPath = os.path.join(repoDir, 'debian', 'copyright')
debRulesPath = os.path.join(repoDir, 'debian', 'rules')
#extract branch, ensure up to date
branchName = git_cmd(repoDir, 'rev-parse', '--abbrev-ref', 'HEAD').strip()
#maintainer
debfullname = os.environ.get('DEBFULLNAME')
debemail = os.environ.get('DEBEMAIL')
assert(debfullname)
assert(debemail)
#get a new date
date = datetime.datetime.now()
yyyymmdd = '%s-%0.2d-%0.2d'%(date.year, date.month, date.day)
rfc2822 = email.utils.format_datetime(date)
#modifications to the control
debControlOut = list()
for line in open(debControlPath).readlines():
if line.startswith('Standards-Version:'):
line = 'Standards-Version: %s\n'%get_standards_version()
debControlOut.append(line)
#modifications to the changelog
changelogOut = list()
changelogReplaced = False
for line in open(changelogPath).readlines():
m = re.match('^Release ([\.0-9a-z]+) \(pending\)$', line.strip())
if m and not changelogReplaced:
changelogReplaced = True
line = line.replace('pending', yyyymmdd)
changelogHeader = line.strip()
version = m.groups()[0]
changelogOut.append(line)
assert(changelogReplaced)
assert(changelogHeader)
assert(version)
#modifications to the copyright
debCopyrightOut = list()
for line in open(debCopyrightPath).readlines():
m = re.match('Copyright \(c\) ((\d+)-(\d+)) %s <%s>'%(debfullname, debemail), line.strip())
if m:
line = line.replace(m.groups()[0], '%s-%d'%(m.groups()[1], date.year))
debCopyrightOut.append(line)
#extract deb source name
debSource = None
for line in open(debControlPath).readlines():
if line.startswith('Source:'):
debSource = line.split('Source:')[1].strip()
debVer = version + '-1'
#write entry into the debian changelog
debChangelogEntry = """\
%s (%s) unstable; urgency=low
* %s
-- %s <%s> %s"""%(
debSource, debVer, changelogHeader, debfullname, debemail, rfc2822)
debChangelogOut = debChangelogEntry + '\n\n' + open(debChangelogPath).read()
#making a tag and pushing it
tags = git_cmd(repoDir, 'tag', '-n').strip().splitlines()
if not tags: raise Exception("No tags found in git tag -n")
tag0 = tags[0]
try:
tag_name, tag_desc = tag0.split(' ', 1)
tag_desc = tag_desc.strip()
tag_prefix, tag_oldver = tag_name.rsplit('-', 1)
except Exception as ex:
raise Exception("Failed to parse '%s': %s"%(tag0, str(ex)))
#known project renames for git tags
if tag_prefix == 'pothos-gui': tag_prefix = 'pothos-flow'
if tag_prefix == 'pothos-sdr': tag_prefix = 'pothos-soapy'
print('Commit summary:')
print(' branch=%s'%branchName)
print(' version=%s'%version)
commitMessage = '%s: changelog entry for %s'%(debSource, version)
print(' '+commitMessage)
print(' Maintainer %s <%s>'%(debfullname, debemail))
print(' Date in YYYY-MM-DD = %s'%yyyymmdd)
print(' Date in RFC-2822 = %s'%rfc2822)
print('Tag parser summary:')
print(' tag_prefix=%s'%tag_prefix)
print(' tag_oldver=%s'%tag_oldver)
print(' tag_desc=%s'%tag_desc)
print('Creating new tag:')
newTagName = tag_prefix + '-' + version
newTagDesc = tag_desc.replace(tag_oldver, version)
print(' newTagName=%s'%newTagName)
print(' newTagDesc=%s'%newTagDesc)
input("Press Enter to continue...")
#pull before making any changes
git_cmd(repoDir, 'pull', 'origin', branchName)
#ensure rules is executable
os.system('chmod +x %s'%debRulesPath)
#write the new files result
open(changelogPath, 'w').write(''.join(changelogOut))
open(debControlPath, 'w').write(''.join(debControlOut))
open(debChangelogPath, 'w').write(debChangelogOut)
open(debCopyrightPath, 'w').write(''.join(debCopyrightOut))
#make the commit, make the tag
git_cmd(repoDir, 'commit', '-a', '-m', commitMessage)
git_cmd(repoDir, 'tag', '-a', newTagName, '-m', newTagDesc)
#push the branch, push the tag
git_cmd(repoDir, 'push', 'origin', branchName)
git_cmd(repoDir, 'push', 'origin', newTagName)
if __name__ == '__main__': main()