summaryrefslogtreecommitdiff
path: root/start_mx.py
diff options
context:
space:
mode:
Diffstat (limited to 'start_mx.py')
-rwxr-xr-xstart_mx.py143
1 files changed, 99 insertions, 44 deletions
diff --git a/start_mx.py b/start_mx.py
index b4d7f9d..79943d9 100755
--- a/start_mx.py
+++ b/start_mx.py
@@ -1,23 +1,29 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
- ____
- | mx |
- |____|_______________________
- | |
- | An encrypting remailer. |
- |_________________________|
-
-@author Isis Agora Lovecruft <isis@leap.se>, 0x2cdb8b35
-@version 0.0.1
+ ____
+ | MX |_________________________
+ ___|____| An encrypting remailer |________
+ | |__________________________| |
+ | is designed for use on a mail exchange |
+ | with OpenPGP implementations and Postfix, |
+ | and is part of the Leap Encryption Access |
+ | Project platform. |
+ |___________________________________________|
+
+ authors: Isis Agora Lovecruft, <isis@leap.se> 0x2cdb8b35
+ license: AGPLv3, see included LICENCE file.
+ copyright: copyright (c) 2013 Isis Agora Lovecruft
"""
-from os import getcwd
-from os import path as ospath
+from __future__ import print_function
+from os import getcwd
+from os import path as ospath
import sys
+
application_name = "leap_mx"
def __get_dirs__():
@@ -29,62 +35,111 @@ def __get_dirs__():
ours = ospath.join(leap, application_name.replace('_', '/'))
return repo, leap, ours
+## Set the $PYTHONPATH:
+repo, leap, ours = __get_dirs__()
+sys.path[:] = map(ospath.abspath, sys.path)
+sys.path.insert(0, leap)
+
+## Now we should be able to import ourselves without installation:
+try:
+ from leap.mx import runner
+ from leap.mx.util import config, log, version
+except ImportError, ie:
+ print("%s \nExiting... \n" % ie.message)
+ sys.exit(1)
+
+try:
+ from twisted.python import usage, runtime
+ from twisted.python.util import spewer
+except ImportError, ie:
+ print("This software requires Twisted>=12.0.2, please see the README for")
+ print("help on using virtualenv and pip to obtain requirements.")
+
+
+class MXOptions(usage.Options):
+ """
+ Command line options for leap_mx.
+ """
+ #longdesc = str(" ")
+ optParameters = [
+ ['config', 'c', 'mx.conf', 'Config file to use'],]
+ optFlags = [
+ ['all-tests', 'a', 'Run all unittests'],
+ ['verbose', 'v', 'Increase logging verbosity'],]
+
+ def opt_version(self):
+ """
+ Print leap_mx version and exit
+ """
+ print("Version: %s" % version.getVersion())
+ sys.exit(0)
-if __name__ == "__main__":
- ## Set the $PYTHONPATH:
- repo, leap, ours = __get_dirs__()
- sys.path[:] = map(ospath.abspath, sys.path)
- sys.path.insert(0, leap)
+ def opt_help(self):
+ """
+ Print this cruft
+ """
+ import __main__
+ print("%s" % __main__.__doc__)
+ self.getUsage()
- ## Now we should be able to import ourselves without installation:
- try:
- from leap.mx import runner
- from leap.mx.util import config, log, version
- except ImportError, ie:
- print "%s\nExiting...\n" % ie.message
- sys.exit(1)
+ def opt_spewer(self):
+ """
+ Print *all of the things*. Useful for debugging.
+ """
+ sys.settrace(spewer)
+
+ def parseArgs(self):
+ """
+ Called with the remaining commandline options which were unrecognised.
+ """
+ log.warn("Couldn't recognise option: %s" % self)
- config.filename = 'mx.conf'
- config.loadConfig()
- ## xxx fixme version requires twisted...
+if __name__ == "__main__":
dependency_check = runner.CheckRequirements(version.getPackageName(),
version.getPipfile())
+ mx_options = MXOptions()
+ if len(sys.argv) <= 1:
+ mx_options.opt_help()
+ sys.exit(0)
- from twisted.python import usage, runtime
- from twisted.internet import reactor
+ try:
+ mx_options.parseOptions()
+ except UsageError, ue:
+ print("%s" % ue.message)
+ sys.exit(1)
+
+ options = mx_options.opts
+
+ ## Get the config settings:
+ config.filename = options['config']
+ config.loadConfig()
if config.basic.enable_logfile:
+ ## Log to file:
logfilename = config.basic.logfile
logfilepath = ospath.join(repo, 'logs')
log.start(logfilename, logfilepath)
else:
+ ## Otherwise just log to stdout:
log.start()
log.msg("Testing logging functionality")
- log.debug("Running %s, with Python %s"
- % (application_name, runtime.shortPythonVersion()))
- log.debug("Platform: %s" % runtime.platform.getType())
- log.debug("Thread support: %s" % str(runtime.platform.supportsThreads()))
-
- mx_options = MXOptions()
- mx_options.parseOptions(sys.argv)
-
- if len(sys.argv) <= 0:
- print mx_options.getUsage()
- sys.exit(0)
+ if runtime.platform.supportsThreads():
+ thread_support = "with thread support."
else:
- options = mx_options
+ thread_support = "without thread support."
+ log.debug("Running %s, with Python %s on %s platform %s"
+ % (application_name, runtime.shortPythonVersion(),
+ runtime.platform.getType(), thread_support))
+
if options['verbose']:
config.basic.debug = True
if options['test']:
from leap.mx import tests ## xxx this needs an __init__.py
- tests.run() ## xxx need /leap/mx/tests.py
- elif options['conf'] and os.path.isfile(options['conf']):
- config.parse()
- runner.run()
+ tests.run()
else:
mx_options.getUsage()
sys.exit(1)