From a47c5df213ff1245110876da63d84de0d33292f0 Mon Sep 17 00:00:00 2001 From: cartoonnerie Date: Sun, 28 Nov 2021 03:07:41 +0100 Subject: [PATCH] refacto: db path in config files --- config.py | 5 ++++- scripts/ccInterface.py | 5 +++-- scripts/cineclubBlogSQ.py | 18 +++++++++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/config.py b/config.py index 6c8c8be..4f5cde6 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,7 @@ PRICE_ONE_COF = 4 PRICE_ONE_EXTE = 5 PRICE_CARD_COF = 30 -PRICE_CARD_EXTE = 35 \ No newline at end of file +PRICE_CARD_EXTE = 35 + +db_path = '../db/baseFilms.db' +dump_path = '../db/dumpFile' diff --git a/scripts/ccInterface.py b/scripts/ccInterface.py index 6b493d8..8a0fd40 100644 --- a/scripts/ccInterface.py +++ b/scripts/ccInterface.py @@ -12,6 +12,7 @@ Created on Sun Mar 25 18:20:49 2018 # * vérifier les eval et les types donnés from cineclubBlogSQ import filmSQ as f +from config import dump_path, db_path import sqlite3 DEBUG = True @@ -53,11 +54,11 @@ class FilmInterface(): print("\nLe film couramment chargé est", self.filmCharge.nom, "\n") def initBDD(self): - fichier = open("../db/dumpFile", "r") + fichier = open(dump_path, "r") instruction = fichier.read() fichier.close() - conn = sqlite3.connect('../db/baseFilms.db') + conn = sqlite3.connect(db_path) c = conn.cursor() c.executescript(instruction) conn.commit() diff --git a/scripts/cineclubBlogSQ.py b/scripts/cineclubBlogSQ.py index 9dd8cb3..7183d77 100644 --- a/scripts/cineclubBlogSQ.py +++ b/scripts/cineclubBlogSQ.py @@ -14,7 +14,7 @@ TODO : """ import sqlite3 -import config +from config import db_path from datetime import date import locale locale.setlocale(locale.LC_ALL, 'fr_FR.utf8') @@ -31,7 +31,7 @@ class filmSQ(): if type(dic) == type(""): self.idN = dic - conn = sqlite3.connect("../db/baseFilms.db") + conn = sqlite3.connect(db_path) conn.row_factory = sqlite3.Row c = conn.cursor() @@ -52,7 +52,7 @@ class filmSQ(): elif type(dic) == type(1): self.i = dic - conn = sqlite3.connect("../db/baseFilms.db") + conn = sqlite3.connect(db_path) conn.row_factory = sqlite3.Row c = conn.cursor() @@ -70,7 +70,7 @@ class filmSQ(): conn.close() else: - conn = sqlite3.connect("../db/baseFilms.db") + conn = sqlite3.connect(db_path) conn.row_factory = sqlite3.Row c = conn.cursor() @@ -95,7 +95,7 @@ class filmSQ(): object.__setattr__(self, 'idN', val_attr) else: try: - conn = sqlite3.connect("../db/baseFilms.db") + conn = sqlite3.connect(db_path) conn.row_factory = sqlite3.Row c = conn.cursor() @@ -113,7 +113,7 @@ class filmSQ(): conn.close() def __getattr__(self, nom): - conn = sqlite3.connect("../db/baseFilms.db", detect_types=sqlite3.PARSE_DECLTYPES) + conn = sqlite3.connect(db_path, detect_types=sqlite3.PARSE_DECLTYPES) conn.row_factory = sqlite3.Row c = conn.cursor() try: @@ -137,7 +137,7 @@ class filmSQ(): def __str__(self): try: - conn = sqlite3.connect("../db/baseFilms.db") + conn = sqlite3.connect(db_path) #conn.row_factory = sqlite3.Row c = conn.cursor() c.execute('SELECT idN, nom, date FROM films WHERE idN = ?', (self.idN)) @@ -296,7 +296,7 @@ class filmSQ(): def maxId(): try: - conn = sqlite3.connect("../db/baseFilms.db") + conn = sqlite3.connect(db_path) conn.row_factory = sqlite3.Row c = conn.cursor() @@ -312,7 +312,7 @@ class filmSQ(): def printAll(): try: - conn = sqlite3.connect("../db/baseFilms.db") + conn = sqlite3.connect(db_path) conn.row_factory = sqlite3.Row c = conn.cursor()