summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-01-19 13:58:11 +0100
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-01-19 13:59:05 +0100
commit93bc35da71c4eeb8e770ea266854b344e959655f (patch)
tree9d4cc21652d5fd2c049ca7255ae03edd895109e1
parentcd205b826ca9c1a65aee5d7005ce3853f57fcf0b (diff)
Issue #169: Allow custom home folder.
- add option --home /some/path to set a custom location for all user agent files.
-rw-r--r--service/pixelated/adapter/search/__init__.py11
-rw-r--r--service/pixelated/bitmask_libraries/session.py5
-rw-r--r--service/pixelated/config/app_factory.py13
-rw-r--r--service/pixelated/config/args.py2
-rw-r--r--service/test/support/integration/app_test_client.py2
-rw-r--r--service/test_requirements.txt1
6 files changed, 20 insertions, 14 deletions
diff --git a/service/pixelated/adapter/search/__init__.py b/service/pixelated/adapter/search/__init__.py
index 4425c7db..688fa4d3 100644
--- a/service/pixelated/adapter/search/__init__.py
+++ b/service/pixelated/adapter/search/__init__.py
@@ -32,13 +32,14 @@ import traceback
class SearchEngine(object):
- INDEX_FOLDER = os.path.join(os.environ['HOME'], '.leap', 'search_index')
+ DEFAULT_INDEX_HOME = os.path.join(os.environ['HOME'], '.leap')
DEFAULT_TAGS = ['inbox', 'sent', 'drafts', 'trash']
- def __init__(self, soledad_querier):
+ def __init__(self, soledad_querier, agent_home=DEFAULT_INDEX_HOME):
self.soledad_querier = soledad_querier
- if not os.path.exists(self.INDEX_FOLDER):
- os.makedirs(self.INDEX_FOLDER)
+ self.index_folder = os.path.join(agent_home, 'search_index')
+ if not os.path.exists(self.index_folder):
+ os.makedirs(self.index_folder)
self._index = self._create_index()
self._write_lock = Lock()
@@ -111,7 +112,7 @@ class SearchEngine(object):
def _create_index(self):
masterkey = self.soledad_querier.get_index_masterkey()
- storage = EncryptedFileStorage(self.INDEX_FOLDER, masterkey)
+ storage = EncryptedFileStorage(self.index_folder, masterkey)
return FileIndex.create(storage, self._mail_schema(), indexname='mails')
def index_mail(self, mail):
diff --git a/service/pixelated/bitmask_libraries/session.py b/service/pixelated/bitmask_libraries/session.py
index 1143eb52..158d6605 100644
--- a/service/pixelated/bitmask_libraries/session.py
+++ b/service/pixelated/bitmask_libraries/session.py
@@ -29,15 +29,16 @@ from .nicknym import NickNym
from .auth import LeapAuthenticator, LeapCredentials
from .soledad import SoledadSessionFactory, SoledadSession
from .smtp import LeapSmtp
+from .config import DEFAULT_LEAP_HOME
SESSIONS = {}
-def open(username, password, server_name):
+def open(username, password, server_name, leap_home=DEFAULT_LEAP_HOME):
certs_home = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "certificates"))
- config = LeapConfig(certs_home=certs_home)
+ config = LeapConfig(leap_home=leap_home, certs_home=certs_home)
provider = LeapProvider(server_name, config)
session = LeapSessionFactory(provider).create(LeapCredentials(username, password))
diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py
index 035a16b2..745db937 100644
--- a/service/pixelated/config/app_factory.py
+++ b/service/pixelated/config/app_factory.py
@@ -62,11 +62,12 @@ def update_info_sync_and_index_partial(sync_info_controller, search_engine, mail
return wrapper
-def init_leap_session(app):
+def init_leap_session(app, leap_home):
try:
leap_session = LeapSession.open(app.config['LEAP_USERNAME'],
app.config['LEAP_PASSWORD'],
- app.config['LEAP_SERVER_NAME'])
+ app.config['LEAP_SERVER_NAME'],
+ leap_home=leap_home)
except ConnectionError, error:
print("Can't connect to the requested provider", error)
sys.exit(1)
@@ -84,12 +85,12 @@ def look_for_user_key_and_create_if_cant_find(leap_session):
return wrapper
-def init_app(app):
- leap_session = init_leap_session(app)
+def init_app(app, leap_home):
+ leap_session = init_leap_session(app, leap_home)
soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad)
tag_service = TagService()
- search_engine = SearchEngine(soledad_querier)
+ search_engine = SearchEngine(soledad_querier, agent_home=leap_home)
pixelated_mail_sender = MailSender(leap_session.account_email())
pixelated_mailboxes = Mailboxes(leap_session.account, soledad_querier)
@@ -130,7 +131,7 @@ def create_app(app, args):
listen_with_ssl(app, args)
else:
listen_without_ssl(app, args)
- reactor.callWhenRunning(lambda: init_app(app))
+ reactor.callWhenRunning(lambda: init_app(app, args.home))
reactor.run()
diff --git a/service/pixelated/config/args.py b/service/pixelated/config/args.py
index d08df929..5bb01d90 100644
--- a/service/pixelated/config/args.py
+++ b/service/pixelated/config/args.py
@@ -15,6 +15,7 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import argparse
+from pixelated.bitmask_libraries.config import DEFAULT_LEAP_HOME
def parse():
@@ -24,6 +25,7 @@ def parse():
parser.add_argument('--dispatcher-stdin', help='run in organization mode, the credentials will be read from stdin', default=False, action='store_true', dest='dispatcher_stdin')
parser.add_argument('--host', default='127.0.0.1', help='the host to run the user agent on')
parser.add_argument('--port', type=int, default=3333, help='the port to run the user agent on')
+ parser.add_argument('--home', help='The folder where the user agent stores its data. Defaults to ~/.leap', default=DEFAULT_LEAP_HOME)
parser.add_argument('-c', '--config', metavar='<configfile>', default=None, help='use specified file for credentials (for test purposes only)')
parser.add_argument('-sk', '--sslkey', metavar='<server.key>', default=None, help='use specified file for SSL key')
parser.add_argument('-sc', '--sslcert', metavar='<server.pem>', default=None, help='use specified file for SSL certificate')
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index 893ec57f..eab001c6 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -46,7 +46,7 @@ class AppTestClient:
# setup app
PixelatedMail.from_email_address = self.mail_address
- SearchEngine.INDEX_FOLDER = soledad_test_folder + '/search_index'
+ SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder
self.app = pixelated.runserver.app
diff --git a/service/test_requirements.txt b/service/test_requirements.txt
index 4f8bc5e3..5fc2a997 100644
--- a/service/test_requirements.txt
+++ b/service/test_requirements.txt
@@ -8,4 +8,5 @@ mockito==0.5.2
funkload==1.16.1
tornado==4.0.2
pep8==1.5.7
+tempdir==0.6