First init

This commit is contained in:
Boris Tassou 2019-12-03 11:10:02 +01:00
commit 44fd7d1a09
11 changed files with 121 additions and 0 deletions

BIN
manage_sql/.DS_Store vendored Normal file

Binary file not shown.

25
manage_sql/__init__.py Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Sql connection module."""
# /*
# * ----------------------------------------------------------------------------
# * "THE BEER-WARE LICENSE" (Revision 42):
# * <boris.tassou@securmail.fr> wrote this file. As long as you retain this notice you
# * can do whatever you want with this stuff. If we meet some day, and you think
# * this stuff is worth it, you can buy me a beer in return Boris Tassou
# * ----------------------------------------------------------------------------
# */
import sys
# Global name
__version__ = '1.0'
__author__ = 'Boris Tassou <boris.tassou@securmail.fr>'
__license__ = 'Beerware'
try:
import MySQLdb
except ImportError:
print('MySQLdb library not found')
sys.exit(1)

BIN
manage_sql/__init__.pyc Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

5
manage_sql/conf.ini Executable file
View File

@ -0,0 +1,5 @@
[sql]
host=localhost
database=postfix
user=postfix
passwd=blabli

70
manage_sql/manage_sql.py Executable file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Module sql connection."""
# /*
# * ----------------------------------------------------------------------------
# * "THE BEER-WARE LICENSE" (Revision 42):
# * <boris.tassou@securmail.fr> wrote this file. As long as you retain this notice you
# * can do whatever you want with this stuff. If we meet some day, and you think
# * this stuff is worth it, you can buy me a beer in return Boris Tassou
# * ----------------------------------------------------------------------------
# */
from configparser import SafeConfigParser
import MySQLdb
class HandleSql:
"""Class to handle sql connection."""
def sql_conn(self):
"""Init sql connection."""
# Read conf.ini
ini_conf = "./config/conf.ini"
config = SafeConfigParser()
config.read(ini_conf)
# DB parameters
sql_host = config.get('sql', 'host')
sql_db = config.get('sql', 'database')
sql_user = config.get('sql', 'user')
sql_pwd = config.get('sql', 'passwd')
try:
global conn
conn = MySQLdb.connect(host=sql_host, db=sql_db, user=sql_user, passwd=sql_pwd)
cur = conn.cursor()
except (Exception, MySQLdb.DatabaseError) as error:
print(error)
def sql_select(self, sql_select):
"""Sql select request."""
# global cur
cur = conn.cursor()
sql_return = cur.execute(sql_select)
sql_return = cur.fetchall()
return sql_return
def sql_delete(self, sql_delete):
"""Sql delte request."""
# global cur
cur = conn.cursor()
cur.execute(sql_delete)
conn.commit()
def sql_insert(self, sql_insert):
"""Sql insert request."""
# global cur
cur = conn.cursor()
cur.execute(sql_insert)
conn.commit()
def sql_unconn(self):
"""Deconnection sql."""
cur = conn.cursor()
cur.close()
conn.close()
if __name__ == "__main__":
print("Module sql to handle the connection")

BIN
manage_sql/manage_sql.pyc Normal file

Binary file not shown.

21
manage_sql/test.py Normal file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from configparser import SafeConfigParser
import psycopg2
# Read conf.ini
ini_conf = "./conf.ini"
config = SafeConfigParser()
config.read(ini_conf)
# DB parameters
psql_host = config.get('psql', 'host')
psql_db = config.get('psql', 'database')
psql_user = config.get('psql', 'user')
psql_pwd = config.get('psql', 'passwd')
print(psql_host)
print(psql_db)
print(psql_user)
print(psql_pwd)