changeset 1425:efa1983063d6

Orlandi: Better error messages when the pypaillier or commitment modules are not installed.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Thu, 14 Jan 2010 11:36:13 +0100
parents 681b1a6760ff
children 0cae74c348e8 2324d01c74e2 0164b895d948
files apps/benchmark.py viff/orlandi.py viff/test/test_orlandi_runtime.py
diffstat 3 files changed, 52 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/apps/benchmark.py	Mon Dec 14 17:02:00 2009 +0100
+++ b/apps/benchmark.py	Thu Jan 14 11:36:13 2010 +0100
@@ -70,10 +70,25 @@
 from viff.comparison import ComparisonToft05Mixin, ComparisonToft07Mixin
 from viff.equality import ProbabilisticEqualityMixin
 from viff.paillier import PaillierRuntime
-from viff.orlandi import OrlandiRuntime
 from viff.config import load_config
 from viff.util import find_prime
 
+try:
+    import commitment  
+except ImportError:
+    commitment = None
+
+try:
+    from pypaillier import encrypt_r, decrypt, tripple_2c, tripple_3a
+except:
+    pypaillier = None
+
+if commitment and pypaillier:
+    from viff.orlandi import OrlandiRuntime
+else:
+    OrlandiRuntime = None
+    OrlandiShare = None
+
 from benchutil import (SelfcontainedBenchmarkStrategy,
                        NeededDataBenchmarkStrategy,
                        ParallelBenchmark, SequentialBenchmark,
@@ -180,6 +195,15 @@
 
 
 # Identify the base runtime class.
+if options.runtime == "OrlandiRuntime" and not OrlandiRuntime:
+    print "Error: The following modules did not load correctly:"
+    if not commitment:
+        print "commitment"
+    if not pypaillier:
+        print "pypaillier"
+    if not OrlandiRuntime:
+        print "OrlandiRuntime"
+    exit(1)
 base_runtime_class = runtimes[options.runtime]
 
 # Identify the additional mixins.
--- a/viff/orlandi.py	Mon Dec 14 17:02:00 2009 +0100
+++ b/viff/orlandi.py	Thu Jan 14 11:36:13 2010 +0100
@@ -37,6 +37,13 @@
 
 try:
     from pypaillier import encrypt_r, decrypt, tripple_2c, tripple_3a
+
+except ImportError:
+    # The pypaillier module is not released yet, so we cannot expect
+    # the import to work.
+    print "Error: The pypaillier module or one of the used functions are not available."
+
+try:
     import commitment
     commitment.set_reference_string(23434347834783478783478L,
                                     489237823478234783478020L)
@@ -45,10 +52,7 @@
     # import to work. Catching the ImportError here allows the
     # benchmark and tests to import viff.orlandi without blowing up.
     # It is only if the OrlandiRuntime is used that things blow up.
-
-    # The pypaillier module is not released yet, so we cannot expect
-    # the import to work.
-    from viff.paillier import encrypt_r, decrypt
+    print "Error: The commitment module is not available."
 
 # import logging
 # LOG_FILENAME = 'logging_example.out'
--- a/viff/test/test_orlandi_runtime.py	Mon Dec 14 17:02:00 2009 +0100
+++ b/viff/test/test_orlandi_runtime.py	Thu Jan 14 11:36:13 2010 +0100
@@ -23,8 +23,15 @@
 from viff.config import generate_configs
 
 try:
-    from viff.orlandi import OrlandiRuntime, OrlandiShare
-    import commitment
+    import commitment  
+    try:
+        from pypaillier import encrypt_r, decrypt, tripple_2c, tripple_3a
+        from viff.orlandi import OrlandiRuntime, OrlandiShare
+    except ImportError:
+        pypaillier = None
+        OrlandiRuntime = None
+        OrlandiShare = None
+
 except ImportError:
     commitment = None
     OrlandiRuntime = None
@@ -852,7 +859,14 @@
         runtime.schedule_callback(shares_ready, cont)
         return shares_ready
 
+
+def skip_tests(module_name):
+    OrlandiAdvancedCommandsTest.skip = "Skipped due to missing " + module_name + " module."
+    OrlandiBasicCommandsTest.skip = "Skipped due to missing " + module_name + " module."
+    TripleGenTest.skip = "Skipped due to missing " + module_name + " module."
+
 if not commitment:
-    OrlandiAdvancedCommandsTest.skip = "Skipped due to missing commitment module."
-    OrlandiBasicCommandsTest.skip = "Skipped due to missing commitment module."
-    TripleGenTest.skip = "Skipped due to missing commitment module."
+    skip_tests("commitment")
+
+if not pypaillier:
+    skip_tests("pypaillier")