This file is indexed.

/usr/lib/python3/dist-packages/debmake/kludge.py is in debmake 4.2.9-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/python3
# vim:se tw=0 sts=4 ts=4 et ai:
"""
Copyright © 2014 Osamu Aoki

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
import collections
import glob
import itertools
import operator
import os
import re
import sys
import debmake.checkdep5
import debmake.scanfiles

re_round0 = re.compile(r'\.0')

def copydiff(mode, pedantic):
    ###########################################################################
    # parse existing debian/copyright against source tree
    ###########################################################################
    if not os.path.isfile('debian/copyright'):
        print('E: You need debian/copyright.')
        exit(1)
    with open('debian/copyright', mode='r', encoding='utf-8') as f:
        lines = f.readlines()
    patterns_for_license = []
    license = ''
    default_license = ''
    f_file = False
    f_cont = False
    f_license = False
    patterns = []
    iptn = -1
    licenses_old = {}
    file_to_pattern = {}
    for line in lines + ['']: # easy sure EOF
        line = line.rstrip()
        if line == '':
            # summarize data
            if patterns_for_license != [] and license != '':
                for ptn in patterns_for_license:
                    patterns.append(ptn)
                    if ptn == '*':
                        default_license = license
                    iptn += 1 # 0, 1, 2, 3 ...
                    globbed_file_or_dirs = glob.glob(ptn)
                    if globbed_file_or_dirs:
                        for file_or_dir in globbed_file_or_dirs:
                            if os.path.isfile(file_or_dir):
                                file_to_pattern[file_or_dir] = (iptn, ptn)
                                licenses_old[file_or_dir] = license
                                debmake.debug.debug('Dn: Pattern #{:02}: {}, file={}, {}'.format(iptn, ptn, file_or_dir, license), type='n')
                            elif os.path.isdir(file_or_dir):
                                for dir, subdirs, files in os.walk(file_or_dir):
                                    #debmake.debug.debug('Dn: Pattern #{:02}: {}, dir={}, files={}'.format(iptn, ptn, dir, files), type='n')
                                    for file in files:
                                        filepath = os.path.join(dir, file)
                                        file_to_pattern[filepath] = (iptn, ptn)
                                        licenses_old[filepath] = license
                                        debmake.debug.debug('Dn: Pattern #{:02}: {}, filepath={}, {}'.format(iptn, ptn, filepath, license), type='n')
                    else:
                        file_to_pattern['__MISSING__'] = (iptn, ptn)
                        licenses_old['__MISSING__'] = license
                        debmake.debug.debug('Dn: Pattern #{:02}: {}, file={}, {}'.format(iptn, ptn, '__MISSING__', license), type='n')
            # Next stanza
            patterns_for_license = []
            license = ''
            f_file = False
            f_cont = False
            f_license = False
        elif line[:6].lower() == 'files:':
            patterns_for_license += line[6:].split()
            f_file = True
            f_cont = True
        elif line[:8].lower() == 'license:':
            license = line[8:].strip()
            f_cont = False
        elif f_cont == True and line[:1] == ' ':
            patterns_for_license += line.split()
        elif f_cont == True and line[:1] == '\t':
            patterns_for_license += line.split()
        elif line[:1].lower() != ' ':
            f_cont = False
        else:
            pass
    nptn = iptn + 1
    ###########################################################################
    iptn_to_ptn = {}
    iptn_to_files = collections.defaultdict(list)
    for file, (iptn, ptn) in file_to_pattern.items():
        iptn_to_ptn[iptn] = ptn
        iptn_to_files[iptn].append(file)
        debmake.debug.debug('Dn: file="{}", iptn="{}", ptn="{}"'.format(file, iptn, ptn), type='n')
    if nptn != len(iptn_to_ptn):
        print("W: ***** Number of patterns unused: {} out of range(0, {}) *****".format(nptn - len(iptn_to_ptn), nptn), file=sys.stderr)
    ###########################################################################
    # scan copyright of the source tree and create license_new[]
    ###########################################################################
    (nonlink_files, xml_html_files, binary_files, huge_files, extcount, extcountlist) = debmake.scanfiles.scanfiles()
    data_new = debmake.checkdep5.checkdep5(nonlink_files, mode=1, pedantic=pedantic)
    licenses_new = {}
    for (licenseid, licensetext, files, copyright_lines) in data_new:
        licenseid = licenseid.strip()
        debmake.debug.debug('Dn: debian/copyright: "{}": {}'.format(licenseid, files), type='n')
        for file in files:
            licenses_new[file] = licenseid
    ###########################################################################
    # generate data with before/after
    ###########################################################################
    data = []
    for iptn in range(0, nptn):
        if iptn in iptn_to_ptn.keys():
            ptn = iptn_to_ptn[iptn]
            files = iptn_to_files[iptn]
        else:
            print('W: ***** Pattern #{:02}: "{}" unused, reorder debian/copyright *****'.format(iptn, patterns[iptn]), file=sys.stderr)
        for file in files:
            old = licenses_old[file]
            if file in licenses_new.keys():
                new = licenses_new[file]
            else:
                new = ''
            if new == '_SAME_' and default_license != '':
                new = default_license
            if old == new and mode <= 5:
                printdiff = False # exact match
            elif old.lower() == new.lower() and mode <= 4:
                printdiff = False # case insensitive match
            elif old.lower() == re_round0.sub('', new.lower()) and mode <= 4:
                printdiff = False # ignore tailing .0
            elif new =='' and mode <= 3:
                printdiff = False
            elif new[:2] == '__' and mode <= 2:
                printdiff = False
            else: # (old, new) not the same or mode >= 6
                printdiff = True
            data.append((iptn, ptn, file, printdiff, old, new))
    return data

def kludge(mode, pedantic):
    basedata = copydiff(mode, pedantic)
    iptn_group_data = []
    data = sorted(basedata, key=operator.itemgetter(0))
    for k, g in itertools.groupby(basedata, operator.itemgetter(0)):
        iptn_group_data.append(list(g))      # Store group iterator as a list
    data_iptn_licenses = []
    for iptn_group in iptn_group_data:
        licenses_group_data = []
        iptn_group = sorted(iptn_group, key=operator.itemgetter(4, 5))
        for k, g in itertools.groupby(iptn_group, operator.itemgetter(4, 5)):
            licenses_group_data.append(list(g))      # Store group iterator as a list
        data_iptn_licenses.append(licenses_group_data)
    print('=== debian/copyright checked for {} data ==='.format(len(basedata)))
    outdata = []
    for match_iptn in data_iptn_licenses:
        for match_licenses in match_iptn:
            files = []
            for match_iptn_licenses in match_licenses:
                (iptn, ptn, file, printdiff, old, new) = match_iptn_licenses
                if printdiff:
                    files.append(file)
            if files:
                outdata.append((iptn, ptn, files, printdiff, old, new))
    for outx in outdata:
        (iptn, ptn, files, printdiff, old, new) = outx
        print('Pattern #{:02}: {}'.format(iptn, ptn))
        print('  File: {}'.format('\n        '.join(files)))
        print('- {}'.format(old))
        print('+ {}'.format(new))
        print()

##############################################################################
if __name__ == '__main__':
    kludge(1, False)