Convert create_datadir to Pathlib

This commit is contained in:
Matthias
2019-07-17 20:53:29 +02:00
parent fbd229810f
commit 8b4827ad85
3 changed files with 12 additions and 10 deletions

View File

@@ -1,18 +1,20 @@
import logging
import os
from typing import Any, Dict, Optional
from pathlib import Path
logger = logging.getLogger(__name__)
def create_datadir(config: Dict[str, Any], datadir: Optional[str] = None) -> str:
folder = Path(datadir) if datadir else Path('user_data/data')
if not datadir:
# set datadir
exchange_name = config.get('exchange', {}).get('name').lower()
datadir = os.path.join('user_data', 'data', exchange_name)
folder = folder.joinpath(exchange_name)
if not os.path.isdir(datadir):
os.makedirs(datadir)
if not folder.is_dir():
folder.mkdir(parents=True)
logger.info(f'Created data directory: {datadir}')
return datadir
return str(folder)