Browse Source

First init

pull/1/head
Boris Tassou 3 years ago
commit
44fd7d1a09
  1. BIN
      manage_sql/.DS_Store
  2. 25
      manage_sql/__init__.py
  3. BIN
      manage_sql/__init__.pyc
  4. BIN
      manage_sql/__pycache__/__init__.cpython-35.pyc
  5. BIN
      manage_sql/__pycache__/__init__.cpython-36.pyc
  6. BIN
      manage_sql/__pycache__/manage_psql.cpython-35.pyc
  7. BIN
      manage_sql/__pycache__/manage_sql.cpython-36.pyc
  8. 5
      manage_sql/conf.ini
  9. 70
      manage_sql/manage_sql.py
  10. BIN
      manage_sql/manage_sql.pyc
  11. 21
      manage_sql/test.py

BIN
manage_sql/.DS_Store vendored

Binary file not shown.

25
manage_sql/__init__.py

@ -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

Binary file not shown.

BIN
manage_sql/__pycache__/__init__.cpython-35.pyc

Binary file not shown.

BIN
manage_sql/__pycache__/__init__.cpython-36.pyc

Binary file not shown.

BIN
manage_sql/__pycache__/manage_psql.cpython-35.pyc

Binary file not shown.

BIN
manage_sql/__pycache__/manage_sql.cpython-36.pyc

Binary file not shown.

5
manage_sql/conf.ini

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

70
manage_sql/manage_sql.py

@ -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

Binary file not shown.

21
manage_sql/test.py

@ -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)
Loading…
Cancel
Save