3 import sys, getopt, subprocess, re
6 out.write("usage: gpgrep PATTERN FILENAME\n")
8 opts, args = getopt.getopt(sys.argv[1:], "h")
18 pattern = re.compile(args[0], re.IGNORECASE)
19 except Exception as exc:
20 sys.stderr.write("gpgrep: %s: %s\n" % (args[0], exc))
23 efp = open(args[1], "r")
24 except OSError as exc:
25 sys.stderr.write("gpgrep: %s: %s\n" % (args[1], exc.strerror))
27 with efp, subprocess.Popen(["gpg", "--quiet", "--decrypt", "--armor"], stdin=efp, stdout=subprocess.PIPE, universal_newlines=True) as gpg:
29 for line in gpg.stdout:
31 if len(line) > 0 and not line[0].isspace() and pattern.search(line):
32 sys.stdout.write("%s\n" % (line))
33 for line in gpg.stdout:
35 if line == "" or not line[0].isspace():
37 sys.stdout.write("%s\n" % (line))
43 sys.stderr.write("gpgrep: gpg failed\n")