Import backend using backend name.
[electrum-server.git] / server.py
index dc551ed..f0b2b41 100755 (executable)
--- a/server.py
+++ b/server.py
@@ -23,7 +23,7 @@ def attempt_read_config(config, filename):
         with open(filename, 'r') as f:
             config.readfp(f)
     except IOError:
-        print "Could not read %s. Falling back." % filename
+        pass
 
 def create_config():
     config = ConfigParser.ConfigParser()
@@ -42,7 +42,7 @@ def create_config():
     config.set('database', 'database', 'abe')
     config.set('server', 'backend', 'abe')
 
-    for path in ('', '/etc/'):
+    for path in ('/etc/', ''):
         filename = path + 'electrum.conf'
         attempt_read_config(config, filename)
 
@@ -86,10 +86,10 @@ if __name__ == '__main__':
         # NativeServer cannot be used with libbitcoin
         native_port = None
         config.set('server', 'native_port', '')
-        from modules.python_bitcoin import BlockchainProcessor
-    elif backend_name == "abe":
-        from modules.abe import AbeProcessor as BlockchainProcessor
-    else:
+    try:
+        backend = __import__("modules." + backend_name,
+                             fromlist=["BlockchainProcessor"])
+    except ImportError:
         sys.stderr.write('Unknown backend specified\n')
         sys.exit(-1)
 
@@ -98,7 +98,7 @@ if __name__ == '__main__':
     shared = dispatcher.shared
 
     # Create and register processors
-    chain_proc = BlockchainProcessor(config)
+    chain_proc = backend.BlockchainProcessor(config)
     dispatcher.register('blockchain', chain_proc)
 
     server_proc = ServerProcessor(config)