File: merge-debian-changelogs

package info (click to toggle)
netperfmeter 1.9.6-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,736 kB
  • sloc: cpp: 8,261; ansic: 1,617; sh: 1,146; python: 339; perl: 108; makefile: 7
file content (135 lines) | stat: -rwxr-xr-x 4,443 bytes parent folder | download
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Packaging Scripts
# Copyright (C) 2021-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: dreibh@simula.no
#

import glob
import os
import re
import sys
import time


#  ====== Handle arguments ==================================================
if len(sys.argv) < 3:
  sys.stderr.write('Usage: ' + sys.argv[0] + ' ppa_changelog distribution_changelog\n')
  sys.exit(1)

changelogNamePPA          = sys.argv[1]
changelogNameDistribution = sys.argv[2]

changelogFilePPA          = open(changelogNamePPA, 'r', encoding='utf-8')
changelogFileDistribution = open(changelogNameDistribution, 'r', encoding='utf-8')

changelogContentsPPA = changelogFilePPA.readlines()
changelogContentsDistribution = changelogFileDistribution.readlines()


# ====== Merge changelogs ===================================================
re_entry_header = re.compile(r'^([a-zA-Z0-9-]+ \([0-9a-zA-Z\.~+]+-[0-9]*)')
re_entry_footer = re.compile(r'^ -- .*')
re_empty        = re.compile(r'^\S*$')

topics = [
   { 'regexp': re.compile(r'^  \* .*ew upstream (version|release).*$'), 'count': 0, 'max': 1 },
   { 'regexp': re.compile(r'^  \* .*standards version.*$'),             'count': 0, 'max': 1 },
   { 'regexp': re.compile(r'^  \* .*debian/compat:.*$'),                'count': 0, 'max': 0 }
]

# ------ Get latest entry from distribution changelog -----------------------
match = re_entry_header.match(changelogContentsDistribution[0])
if match == None:
   sys.stderr.write('ERROR: Bad header in ' + changelogNameDistribution + '!\n')
   sys.exit(1)
latestDistributionEntry = match.group(1)

# ------ Join all new entries from PPA changelog ----------------------------
result = []

entries                           = 0
insideEntry                       = False
foundLatestDistributionEntryInPPA = False
firstFooter                       = None
for line in changelogContentsPPA:
   # ------ Begin of an entry -----------------------------------------------
   match = re_entry_header.match(line)
   if match != None:

      entries = entries + 1
      if entries == 1:
         result.append(line)
         result.append('\n')

      # ------ Done? --------------------------------------------------------
      elif line[0:len(latestDistributionEntry)] == latestDistributionEntry:
         foundLatestDistributionEntryInPPA = True
         break

      continue

   # ------ Empty line ------------------------------------------------------
   match = re_empty.match(line)
   if match != None:
      continue

   # ------ End of an entry -------------------------------------------------
   match = re_entry_footer.match(line)
   if match != None:
      if entries == 1:
         firstFooter = line
      continue

   # ------ Topics ----------------------------------------------------------
   skip = False
   for topic in topics:
      match = topic['regexp'].match(line)
      if match != None:
         topic['count'] = topic['count'] + 1
         if topic['count'] > topic['max']:
            skip = True
            break
   if skip == True:
      continue

   # ------ Add line to output ----------------------------------------------
   if line[0] == ' ':
      result.append(line)
      continue

   # ------ Something is wrong ----------------------------------------------
   sys.stderr.write('ERROR: Unexpected line: ' + line + '!\n')
   sys.exit(1)


result.append('\n')
result.append(firstFooter)


if foundLatestDistributionEntryInPPA == False:
   sys.stderr.write('ERROR: Did not found the latest distribution entry in the PPA changelog!\n')
   sys.exit(1)


# ------ Print results ------------------------------------------------------
for line in result:
   sys.stdout.write(line)
sys.stdout.write('\n')
for line in changelogContentsDistribution:
   sys.stdout.write(line)