diff --git a/.env b/.env deleted file mode 100644 index d600cc3f8ee5af070b1d7b1fc2b633ae55a799c2..0000000000000000000000000000000000000000 --- a/.env +++ /dev/null @@ -1,16 +0,0 @@ -# DB settings -DB_HOST="217.182.138.216" -DB_PORT=5432 -DB_USER="romain" -DB_PWD="!P@4postss!" -DB_NAME="calque_planta_temp" -DB_SCHEMA="base" - -# Python settings -PYTHON_LAUNCH="python" - -# Others settings -TARGET_PROJ="EPSG:2154" -REMOVE_TEMP_FILE=False -SKIP_EXISTING_DATA=True -ENABLE_TRUNCATE=False \ No newline at end of file diff --git a/.gitignore b/.gitignore index 763624ebe547350200a2b9d538bdff0b90536f61..b661180625aaa7a9ac6a9cd96cfe6a0483f152b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -__pycache__/* \ No newline at end of file +__pycache__/* +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 625448a17cfd8d3256b973ec23ac2226bf325412..10f059c865def36bef4cd5569fb2be6e295934af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,10 @@ FROM python:3 WORKDIR /usr/src/app +RUN echo "-----------------------" +RUN echo " Python3 Image" +RUN echo "-----------------------" + COPY scripts/requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt diff --git a/logs/log_11-10-2022.log b/logs/log_11-10-2022.log new file mode 100644 index 0000000000000000000000000000000000000000..9cdbcc5243b2336f2a2bdac1dcc04748c5931994 --- /dev/null +++ b/logs/log_11-10-2022.log @@ -0,0 +1,3 @@ +11/10/2022 14:14:39 - [INFO] Logger is initialized +11/10/2022 14:14:40 - [INFO] Database connection successfully opened +11/10/2022 14:14:40 - [INFO] Database connection successfully closed diff --git a/main.py b/main.py index 976e51f57e10fe74e8bb0adac7d25ec631539889..b545f56d7cf357f10d26351b0901720f88cda4d5 100644 --- a/main.py +++ b/main.py @@ -62,6 +62,7 @@ def showDoc(): computeAll <gridSize: int, listInseeCode: int> Generate all the plantability layer (launch all previous steps). List of inseeCode must be separated with comma (,) and without space (e.g. python main.py 5 69266,69388,69256) but you can launch treatments for only one commune (e.g. python main.py 5 69266) + testDB Test the connexion with DB parameters in .env file help Show this documentation """ @@ -101,6 +102,19 @@ def test(communesArrayInput=None): return retcode +def testDBConnexion(): + # Init + retcode = None + + print(style.BLUE + "Try to connect to database : {} - {} \n".format(DB_params['host'], DB_params['database']), style.RESET) + + # Connect DB + conn, cur = connectDB(DB_params) + # Close DB + closeDB(conn, cur) + + return retcode + # ------------------------ # COMMUNES # ------------------------ @@ -1008,6 +1022,8 @@ def main(): elif firstArgv == 'test': secArgv = sys.argv[1:][1] test(secArgv) + elif firstArgv == 'testDB': + testDBConnexion() elif firstArgv == 'help': showDoc() else: diff --git a/utils.py b/utils.py index 16fa9c7723dfe8645bb3ef069a9db95f382abaaa..19f2f9a542dcbda4f061b347e31b951e28278cfc 100644 --- a/utils.py +++ b/utils.py @@ -206,7 +206,7 @@ def connectDB(params_DB, jsonEnable = False): cur = conn.cursor() # Log - debugLog(style.GREEN, "Database connection successfully opened", logging.INFO, True) + debugLog(style.GREEN, "Database connection successfully opened", logging.INFO) return conn, cur @@ -222,7 +222,7 @@ def closeDB(conn, cur): cur.close() # Log - debugLog(style.GREEN, "Database connection successfully closed", logging.INFO, True) + debugLog(style.GREEN, "Database connection successfully closed", logging.INFO) except (Exception, psycopg2.Error) as error : debugLog(style.RED, "Error while trying to connect in PostgreSQL database : {}".format(error), logging.ERROR)