From a2b9214f492a6bff7241cc7ac24e3ec9ec41e4b1 Mon Sep 17 00:00:00 2001 From: Cristian Salamea Date: Fri, 5 Jan 2018 13:27:42 -0500 Subject: [PATCH] [IMP] config file management --- README.rst | 14 ++++++-------- runa/utils.py | 16 +++++++++++++++- setup.py | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index 5c00cbd..3afec6d 100644 --- a/README.rst +++ b/README.rst @@ -36,6 +36,8 @@ Installing Using ----- +This library will create a configuration file .runa.json in your HOMEPATH, update this to use it. + .. code-block:: python >>> import runa @@ -52,15 +54,11 @@ Using Features -------- -* Uso del WS Consultar_Ciudadano -* Validación de NUI (usa librería stdum) -* Uso del WS SRI - +* WS Consultar_Ciudadano +* WS SRI +* Config file needed Credits --------- -This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template. - -.. _Cookiecutter: https://github.com/audreyr/cookiecutter -.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage +Created by Cristian Salamea diff --git a/runa/utils.py b/runa/utils.py index 7c45754..f70f1a6 100644 --- a/runa/utils.py +++ b/runa/utils.py @@ -1,12 +1,26 @@ # -*- coding: utf-8 -*- import json +from pathlib import Path +import logging + +logger = logging.getLogger(__name__) + +CONFIG_FILE_NAME = '.runa.json' + +CONFIG_FILE = '{0}/{1}'.format(str(Path.home()), CONFIG_FILE_NAME) + +if not Path(CONFIG_FILE).is_file(): + mf = open(CONFIG_FILE, 'w') + json.dumps({}, mf) + mf.close() -CONFIG_FILE = '/var/tmp/config.json' # Read config with open(CONFIG_FILE) as env_file: VARS_ENV = json.load(env_file) + if not VARS_ENV: + logger.warning('No vars defined, please update your %s' % CONFIG_FILE) AUTHORIZED_NUI = VARS_ENV.get('AUTHORIZED_NUI', None) WS_CIUDADANO_PRODUCTION = VARS_ENV.get('WS_CIUDADANO_PRODUCTION', None) diff --git a/setup.py b/setup.py index 4534c22..0f9c4a6 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ setup( name='runa', - version='0.2.2', + version='0.2.3', description="Librería para uso de WS del Bus Gubernamental de Ecuador", long_description=readme + '\n\n' + history, author="Cristian Salamea",