From 54e463be00de78a336f4e547634a77faf6a60b37 Mon Sep 17 00:00:00 2001 From: drebs Date: Fri, 3 May 2013 17:20:34 -0300 Subject: Use mkdir_p from leap.common. --- src/leap/soledad/__init__.py | 13 +++++-------- src/leap/soledad/tests/test_couch.py | 7 +++++-- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/leap') diff --git a/src/leap/soledad/__init__.py b/src/leap/soledad/__init__.py index 2138e14e..b87dbbb6 100644 --- a/src/leap/soledad/__init__.py +++ b/src/leap/soledad/__init__.py @@ -42,6 +42,7 @@ from hashlib import sha256 from leap.common import events from leap.common.check import leap_assert +from leap.common.files import mkdir_p from leap.soledad.backends import sqlcipher from leap.soledad.backends.leap_backend import ( LeapDocument, @@ -254,19 +255,15 @@ class Soledad(object): def _init_dirs(self): """ Create work directories. + + @raise OSError: in case file exists and is not a dir. """ paths = map( lambda x: os.path.dirname(x), [self.local_db_path, self.secret_path]) for path in paths: - if not os.path.isfile(path): - if not os.path.isdir(path): - logger.info('Creating directory: %s.' % path) - os.makedirs(path) - else: - logger.info('Using existent directory: %s.' % path) - else: - raise NotADirectory(path) + logger.info('Creating directory: %s.' % path) + mkdir_p(path) def _init_keys(self): """ diff --git a/src/leap/soledad/tests/test_couch.py b/src/leap/soledad/tests/test_couch.py index 9ac07f88..d6b9ad83 100644 --- a/src/leap/soledad/tests/test_couch.py +++ b/src/leap/soledad/tests/test_couch.py @@ -24,6 +24,9 @@ import re import copy import shutil from base64 import b64decode + +from leap.common.files import mkdir_p + from leap.soledad.backends import couch from leap.soledad.tests import u1db_tests as tests from leap.soledad.tests.u1db_tests import test_backends @@ -77,8 +80,8 @@ class CouchDBWrapper(object): handle.close() # create the dirs from the template - os.mkdir(os.path.join(self.tempdir, 'lib')) - os.mkdir(os.path.join(self.tempdir, 'log')) + mkdir_p(os.path.join(self.tempdir, 'lib')) + mkdir_p(os.path.join(self.tempdir, 'log')) args = ['couchdb', '-n', '-a', confPath] #null = open('/dev/null', 'w') self.process = subprocess.Popen( -- cgit v1.2.3