Commit 64f85457 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

pre-merge clean-up

parent 97c62dab
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -12,20 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# ztp_server/service/rest_server/ztpServer_plugins/ztp_provisioning_api/Tools.py
import os, logging
log = logging.getLogger(__name__)

LOGGER = logging.getLogger(__name__)

def returnConfigFile(config_db: str):
    base = os.path.normpath(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     "..","..","..","..","data")
    )
    cfg = os.path.join(base, config_db)
    log.info("ZTP REST: trying config file: %s", cfg)
    file_path = os.path.normpath(os.path.join(
        os.path.dirname(os.path.abspath(__file__)),
        '..', '..', '..', '..', 'data', config_db
    ))
    MSG = 'ZTP REST: trying config file: {:s}'
    LOGGER.info(MSG.format(str(file_path)))
    try:
        with open(cfg, "r", encoding="utf-8") as f:
        with open(file_path, 'r', encoding='utf-8') as f:
            return f.read()
    except FileNotFoundError:
        log.warning("ZTP REST: config file not found: %s", cfg)
        MSG = 'ZTP REST: config file not found: {:s}'
        LOGGER.warning(MSG.format(str(file_path)))
        return None