commit 94a7ee19f64bf8abe8ad5178f98d10426c10e0db Author: kudrom kudrom@riseup.net Date: Tue Jul 15 17:07:26 2014 +0200
Make optional the execution of check_incoherences from read_config. --- ooni/errors.py | 4 ++++ ooni/oonicli.py | 10 ++++++++-- ooni/settings.py | 10 ++++++---- 3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/ooni/errors.py b/ooni/errors.py index cd71316..3c9d86f 100644 --- a/ooni/errors.py +++ b/ooni/errors.py @@ -302,6 +302,10 @@ class ReportLogExists(Exception): class InvalidConfigFile(Exception): pass
+class ConfigFileIncoherent(Exception): + pass + + def get_error(error_key): if error_key == 'test-helpers-key-missing': return CouldNotFindTestHelper diff --git a/ooni/oonicli.py b/ooni/oonicli.py index 7c3e9a2..cd9f4a9 100644 --- a/ooni/oonicli.py +++ b/ooni/oonicli.py @@ -4,7 +4,7 @@ import yaml
from twisted.python import usage from twisted.python.util import spewer -from twisted.internet import defer +from twisted.internet import defer, reactor
from ooni import errors, __version__
@@ -111,7 +111,13 @@ def runWithDirector(logging=True, start_tor=True): config.global_options = global_options config.set_paths() config.initialize_ooni_home() - config.read_config_file() + d = config.read_config_file(check_incoherences=True) + + @d.addErrback + def shutdown(failure): + failure.trap(errors.ConfigFileIncoherent) + log.err("Shutting down until ooniprobe.conf is coherent.") + reactor.callWhenRunning(reactor.stop)
if global_options['verbose']: config.advanced.debug = True diff --git a/ooni/settings.py b/ooni/settings.py index 91d2f76..5bc367e 100644 --- a/ooni/settings.py +++ b/ooni/settings.py @@ -12,6 +12,7 @@ import txtorcon
from ooni import otime, geoip from ooni.utils import Storage, log +from ooni import errors
class OConfig(object): @@ -99,7 +100,7 @@ class OConfig(object): w.write(line)
@defer.inlineCallbacks - def read_config_file(self): + def read_config_file(self, check_incoherences=False): if not os.path.exists(self.config_file): print "Configuration file does not exist." self._create_config_file() @@ -116,9 +117,10 @@ class OConfig(object): self.set_paths()
# The incoherent checks must be performed after OConfig is in a valid state to runWithDirector - coherent = yield self.check_incoherences(configuration) - if not coherent: - sys.exit(6) + if check_incoherences: + coherent = yield self.check_incoherences(configuration) + if not coherent: + raise errors.ConfigFileIncoherent
@defer.inlineCallbacks def check_incoherences(self, configuration):
tor-commits@lists.torproject.org