-
Notifications
You must be signed in to change notification settings - Fork 19
/
filter-debian-changelog
executable file
·112 lines (95 loc) · 3.89 KB
/
filter-debian-changelog
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Debian/Ubuntu Packaging Scripts
# Copyright (C) 2002-2024 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Contact: [email protected]
# This script filters debian/changelog entries:
# Usage: filter-debian-changelog [regexp_for_last_entry|FIRST]
# * Empty entries get dropped.
# * Stop, if entry matches regexp_for_last_entry argument.
# * Stop after first entry, if regexp_for_last_entry = FIRST.
# Example: filter-debian-changelog "Mon, 31 Oct 2016 08:08:08 \+0200"
# Note the \+, otherwise '+' is interpreted as regexp!
import glob
import os
import re
import sys
import time
# ====== Handle arguments ==================================================
if len(sys.argv) < 2:
sys.stderr.write('Usage: ' + sys.argv[0] + ' regexp_for_last_entry|FIRST\n')
sys.exit(1)
if sys.argv[1] == '':
re_last_entry = None
elif sys.argv[1] == 'FIRST':
re_last_entry = re.compile(r'^.*$')
else:
re_last_entry = re.compile(r'^.*' + sys.argv[1])
re_begin_of_entry = re.compile(r'^[a-zA-Z].*$')
re_end_of_entry = re.compile(r'^ --.*$')
re_empty = re.compile(r'^$')
re_item = re.compile(r'^ *')
re_item_is_itp = re.compile(r'^(.*Closes:.*ITP.*|.*ITP.*Closes:.*)$')
entries = 0
entryContentLines = 0
entryContent = ''
entryIsITP = False
contents = sys.stdin.readlines()
for line in contents:
# ====== Begin of entry ==================================================
if entryContentLines == 0:
if re_begin_of_entry.match(line):
entryContent = line
entryContentLines = 1
# ====== Within entry ====================================================
else:
# ------ End of entry -------------------------------------------------
if re_end_of_entry.match(line):
entryContent = entryContent + line + '\n'
if entryContentLines > 1:
entries = entries + 1
# ------ Print entry --------------------------------------------
if not entryIsITP:
sys.stdout.write(entryContent)
# ------ Print entry with ITP -----------------------------------
# Special case: The ITP package for Debian must only contain the
# ITP entry with ITP item and nothing else!
else:
splittedITPEntry = entryContent.splitlines()
i = 0
for itpLine in splittedITPEntry:
i = i + 1
if (i <= 2) or (i >= len(splittedITPEntry) - 2):
sys.stdout.write(itpLine + '\n')
elif re_item_is_itp.match(itpLine) != None:
sys.stdout.write(itpLine + '\n')
break # ITP -> done!
entryContent = ''
entryIsITP = False
# ------ Check for match with last entry regexp in argument --------
if re_last_entry != None:
if re_last_entry.match(line) != None:
break
entryContentLines = 0
# ------ Part of entry ------------------------------------------------
else:
if re_item.match(line):
entryContent = entryContent + line
entryContentLines = entryContentLines + 1
if re_item_is_itp.match(line):
entryIsITP = True