This file is indexed.

/usr/lib/python2.7/dist-packages/xxdiff/scripts/filter.py is in xxdiff-scripts 1:4.0.1+dfsg-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
# This file is part of the xxdiff package.  See xxdiff for license and details.

"""
xx-filter [<options>] <cmd>

Run a command to perform replacements in files and confirm the application of
changes via xxdiff.

This program walks a directory hierarchy, selects some files to be processed by
filenames (or by default, process all files found), then the given filter
command is run with the selected file as input and its output captured,
compared, if the files differ, a graphical diff is presented to ask the user
whether he wants to apply the changes or not.
"""

__author__ = "Martin Blais <blais@furius.ca>"
__depends__ = ['xxdiff', 'Python-2.4']


# stdlib imports.
import sys, os, filecmp
from os.path import *
from subprocess import Popen, PIPE

# xxdiff imports.
import xxdiff.scripts
import xxdiff.xformloop


class FilterTransformer(xxdiff.xformloop.Transformer):
    """
    Transformer that greps the file for a regular expression, and if it matches,
    runs it through a sed command.
    """
    def __init__(self, opts, filtcmd):
        xxdiff.xformloop.Transformer.__init__(self, opts)
        self.filtcmd = filtcmd

    def transform(self, fn, outf):
        # Open input file.
        inf = file(fn, 'r')

        # Run the user's command.
        p = Popen(self.filtcmd, shell=True, stdin=inf, stdout=outf, stderr=PIPE)

        # Note: we do not check the return code, because we do not know the
        # client's convention for the program he invokes.
        returncode = p.wait()

        # Hmmm... what should we do with errors?
        errors = p.stderr.read()

        # Check if the files differ and indicate to process if so.
        #
        # Note: using filecmp should be faster than intercepting and reading all
        # the files in memory, because hopefully they are only reading and
        # comparing chunks at a time to bail out when there is a difference
        # instead of reading the whole data in memory before comparison.
        return not filecmp.cmp(fn, outf.name)


def parse_options():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())

    opts, args, selector = xxdiff.xformloop.parse_args(parser)

    # Check that we got two arguments
    if len(args) != 1:
        parser.error("You must specify a filter command to run on the files.")
    filtcmd = args[0]

    # Force to always perform a diff on output.
    opts.verbose = 2

    return filtcmd, opts, selector


def filter_main():
    """
    Main program for find-grep-sed script.
    """
    # Parse the options.
    filtcmd, opts, selector = parse_options()

    # Create an appropriate transformer.
    xformer = FilterTransformer(opts, filtcmd)

    try:
        decision_map = xxdiff.xformloop.transform_replace_loop(
            opts, selector, xformer, sys.stdout)
    finally:
        xxdiff.xformloop.postloop_footer(opts)


def main():
    xxdiff.scripts.interruptible_main(filter_main)

if __name__ == '__main__':
    main()