Browse Source

Merge sync into imap

PYADPT-55
David 6 years ago
parent
commit
057750840e
  1. 4
      dependencies.txt
  2. 12
      src/pEpmodule.cc
  3. 28
      test/sync_handshake.py
  4. 13
      test/sync_test.py
  5. 17
      utils/pEp

4
dependencies.txt

@ -0,0 +1,4 @@
pEpPythonAdapter => Python 3
=> g++ | clang | CL.EXE
-> boost::python
-> pEpEngine

12
src/pEpmodule.cc

@ -113,6 +113,11 @@ namespace pEp {
{ {
adapter.shutdown_sync(); adapter.shutdown_sync();
} }
void debug_color(int ansi_color)
{
::set_debug_color(adapter.session(), ansi_color);
}
} }
} }
@ -370,7 +375,7 @@ BOOST_PYTHON_MODULE(pEp)
.def("__deepcopy__", &Message::deepcopy) .def("__deepcopy__", &Message::deepcopy)
.def("__copy__", &Message::copy); .def("__copy__", &Message::copy);
// basic API // basic API and key management API
def("update_identity", &pEp::PythonAdapter::update_identity, def("update_identity", &pEp::PythonAdapter::update_identity,
"update_identity(ident)\n" "update_identity(ident)\n"
@ -475,7 +480,7 @@ BOOST_PYTHON_MODULE(pEp)
.value("SYNC_NOTIFY_TIMEOUT" , SYNC_NOTIFY_TIMEOUT) .value("SYNC_NOTIFY_TIMEOUT" , SYNC_NOTIFY_TIMEOUT)
.value("SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED" , SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED) .value("SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED" , SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED)
.value("SYNC_NOTIFY_ACCEPTED_GROUP_CREATED", SYNC_NOTIFY_ACCEPTED_GROUP_CREATED) .value("SYNC_NOTIFY_ACCEPTED_GROUP_CREATED", SYNC_NOTIFY_ACCEPTED_GROUP_CREATED)
.value("SYNC_NOTIFY_OVERTAKEN" , SYNC_NOTIFY_OVERTAKEN) .value("SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED", SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED)
.value("SYNC_NOTIFY_SOLE" , SYNC_NOTIFY_SOLE) .value("SYNC_NOTIFY_SOLE" , SYNC_NOTIFY_SOLE)
.value("SYNC_NOTIFY_IN_GROUP" , SYNC_NOTIFY_IN_GROUP); .value("SYNC_NOTIFY_IN_GROUP" , SYNC_NOTIFY_IN_GROUP);
@ -518,6 +523,9 @@ BOOST_PYTHON_MODULE(pEp)
"call this from another thread to shut down the sync thread\n" "call this from another thread to shut down the sync thread\n"
); );
def("debug_color", &pEp::PythonAdapter::debug_color,
"for debug builds set ANSI color value");
// codecs // codecs
call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search)); call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search));

28
test/sync_handshake.py

@ -51,10 +51,11 @@ SYNC_HANDSHAKE_ACCEPTED = 0
SYNC_HANDSHAKE_REJECTED = 1 SYNC_HANDSHAKE_REJECTED = 1
the_end = False the_end = False
end_on = ( end_on = [
pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED, pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED,
pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_GROUP_CREATED pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_GROUP_CREATED,
) pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_DEVICE_ACCEPTED,
]
def print_msg(p): def print_msg(p):
@ -125,8 +126,9 @@ def getMessageToSend(msg):
class UserInterface(pEp.UserInterface): class UserInterface(pEp.UserInterface):
def notifyHandshake(self, me, partner, signal): def notifyHandshake(self, me, partner, signal):
output("on " + device_name + " signal " + str(signal) + " for identities " + str(me.fpr) + " " + print(colored(str(signal), "yellow"), end=" ")
str(partner.fpr)) output("on " + device_name + "" if not me.fpr else
"for identities " + str(me.fpr) + " " + str(partner.fpr))
if me.fpr and partner.fpr: if me.fpr and partner.fpr:
assert me.fpr != partner.fpr assert me.fpr != partner.fpr
@ -135,6 +137,11 @@ class UserInterface(pEp.UserInterface):
pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_ADD_OUR_DEVICE, pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_ADD_OUR_DEVICE,
pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_FORM_GROUP pEp.sync_handshake_signal.SYNC_NOTIFY_INIT_FORM_GROUP
): ):
if isinstance(end_on, list):
end_on.extend([
pEp.sync_handshake_signal.SYNC_NOTIFY_SOLE,
pEp.sync_handshake_signal.SYNC_NOTIFY_IN_GROUP,
])
try: try:
if options.reject: if options.reject:
self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED) self.deliverHandshakeResult(SYNC_HANDSHAKE_REJECTED)
@ -159,6 +166,12 @@ def run(name, color=None, imap=False):
if color: if color:
global output global output
output = lambda x: print(colored(x, color)) output = lambda x: print(colored(x, color))
if color == "red":
pEp.debug_color(31)
elif color == "green":
pEp.debug_color(32)
elif color == "cyan":
pEp.debug_color(36)
if imap: if imap:
me = pEp.Identity(settings.IMAP_EMAIL, name + " of " + settings.IMAP_USER, name) me = pEp.Identity(settings.IMAP_EMAIL, name + " of " + settings.IMAP_USER, name)
@ -222,6 +235,8 @@ if __name__=="__main__":
optParser.add_option("-j", "--multi-threaded", action="store_true", optParser.add_option("-j", "--multi-threaded", action="store_true",
dest="multithreaded", dest="multithreaded",
help="use multithreaded instead of single threaded implementation") help="use multithreaded instead of single threaded implementation")
optParser.add_option("-n", "--noend", action="store_true",
dest="noend", help="do not end")
options, args = optParser.parse_args() options, args = optParser.parse_args()
if not options.exec_for: if not options.exec_for:
@ -233,6 +248,9 @@ if __name__=="__main__":
except TypeError: except TypeError:
end_on = (end_on,) end_on = (end_on,)
if options.noend:
end_on = (None,)
multithreaded = options.multithreaded multithreaded = options.multithreaded
run(options.exec_for, options.color) run(options.exec_for, options.color)

13
test/sync_test.py

@ -90,6 +90,8 @@ if __name__ == "__main__":
help="setup environment, then stop") help="setup environment, then stop")
optParser.add_option("-p", "--print", action="store_true", dest="print", optParser.add_option("-p", "--print", action="store_true", dest="print",
help="print sync message trace in inbox") help="print sync message trace in inbox")
optParser.add_option("-n", "--noend", action="store_true", dest="noend",
help="do not end")
optParser.add_option("-E", "--end-on", dest="notifications", optParser.add_option("-E", "--end-on", dest="notifications",
help="end test on these notifications") help="end test on these notifications")
optParser.add_option("-3", "--third-device", action="store_true", dest="third", optParser.add_option("-3", "--third-device", action="store_true", dest="third",
@ -118,6 +120,14 @@ if __name__ == "__main__":
if options.cleanall: if options.cleanall:
rmrf("Backup") rmrf("Backup")
if options.setup_only:
os.makedirs("TestInbox", exist_ok=True)
setup("Phone")
setup("Laptop")
if options.third:
setup("Pad")
elif options.backup: elif options.backup:
rmrf("Backup") rmrf("Backup")
@ -167,6 +177,9 @@ if __name__ == "__main__":
try: None in end_on try: None in end_on
except TypeError: except TypeError:
end_on = (end_on,) end_on = (end_on,)
elif options.noend:
end_on = (None,)
Phone = Process(target=test_for, args=("Phone", "red", end_on, Phone = Process(target=test_for, args=("Phone", "red", end_on,
options.multithreaded, options.imap)) options.multithreaded, options.imap))
Laptop = Process(target=test_for, args=("Laptop", "green", end_on, Laptop = Process(target=test_for, args=("Laptop", "green", end_on,

17
utils/pEp

@ -26,6 +26,8 @@ parser.add_argument('--decrypt', '-d', help='decrypt p≡p message',
action='store_true', dest='decrypt') action='store_true', dest='decrypt')
parser.add_argument('--import', '-i', help='import key data in PGP format', parser.add_argument('--import', '-i', help='import key data in PGP format',
action='store_true', dest='keyimport') action='store_true', dest='keyimport')
parser.add_argument('--export', '-x', help='export key data in PGP format',
action='store_true', dest='keyexport')
parser.add_argument('--version', '-V', help='show program version', parser.add_argument('--version', '-V', help='show program version',
action='store_true', dest='version') action='store_true', dest='version')
parser.add_argument('files', metavar='FILE', nargs='*', parser.add_argument('files', metavar='FILE', nargs='*',
@ -33,8 +35,8 @@ parser.add_argument('files', metavar='FILE', nargs='*',
args = parser.parse_args() args = parser.parse_args()
if not(args.encrypt) and not(args.decrypt) and not (args.keyimport) and not(args.version): if not(args.encrypt) and not(args.decrypt) and not (args.keyimport) and not (args.keyexport) and not(args.version):
print('use either --encrypt, --decrypt or --import', file=sys.stderr) print('use either --encrypt, --decrypt, --import or --export', file=sys.stderr)
sys.exit(2) sys.exit(2)
if args.version: if args.version:
@ -85,6 +87,17 @@ try:
except RuntimeError: except RuntimeError:
print("error importing key(s)", file=sys.stderr) print("error importing key(s)", file=sys.stderr)
elif args.keyexport:
if filename == '-':
text = sys.stdin.read()
else:
with open(filename, "rb") as f:
text = f.read()
try:
import_key(text)
except RuntimeError:
print("error exporting key(s)", file=sys.stderr)
except KeyboardInterrupt: except KeyboardInterrupt:
print('\n', file=sys.stderr) print('\n', file=sys.stderr)
sys.exit(1) sys.exit(1)

Loading…
Cancel
Save