adding command line tool

PYADPT-55
Volker Birk 6 years ago
parent 039354d7ad
commit 6bccdc275e
  1. 73
      utils/pEp

@ -0,0 +1,73 @@
#!env python3
# -*- coding: utf-8 -*-
"""
p≡p command line version 1.0
Copyleft 2016, p≡p foundation
written by Volker Birk
"""
from pEp import *
import argparse
import sys
parser = argparse.ArgumentParser(
description='provide p≡p functionality on the command line',
epilog='Copyleft 2016, p≡p foundation. All lefts reserved.'
)
parser.add_argument('--encrypt', '-e', help='encrypt p≡p message',
action='store_true', dest='encrypt')
parser.add_argument('--decrypt', '-d', help='decrypt p≡p message',
action='store_true', dest='decrypt')
parser.add_argument('--version', '-V', help='show program version',
action='store_true', dest='version')
parser.add_argument('files', metavar='FILE', nargs='*',
help='FILE with MIME text')
args = parser.parse_args()
if not(args.encrypt) and not(args.decrypt) and not(args.version):
print('use either --encrypt or --decrypt', file=sys.stderr)
sys.exit(2)
if args.version:
print(__doc__)
try:
if len(args.files) == 0:
args.files = ['-']
for filename in args.files:
if filename == '-':
text = ''
for line in sys.stdin.readlines():
if line[-2:] == '\r\n':
text += line
elif line[-1:] == '\n':
text += line[:-1] + '\r\n'
else:
text += line + '\r\n'
else:
with open(filename, "r") as f:
text = f.readall()
src = Message(text)
if args.encrypt:
src.dir = 1
dst = src.encrypt()
else:
src.dir = 0
dst, keys, rating, flags = src.decrypt()
print(str(dst))
except KeyboardInterrupt:
print('\n', file=sys.stderr)
sys.exit(1)
Loading…
Cancel
Save