summaryrefslogtreecommitdiff
path: root/git-interface/db.py
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2016-09-20 20:18:24 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2016-09-29 22:07:06 +0200
commitdc3fd60715a5b17b9542ec888c6eaeb14c284e2b (patch)
tree18d9f17b8d582409f0db55ee32fc5efa674aaa2e /git-interface/db.py
parent1946486a67d6085318e00c753d341ab05d12904c (diff)
Use setuptools to install Python modules
Instead of using relative imports, add support for installing the config and db Python modules to a proper location using setuptools. Change all git-interface scripts to access those modules from the search path. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'git-interface/db.py')
-rw-r--r--git-interface/db.py51
1 files changed, 0 insertions, 51 deletions
diff --git a/git-interface/db.py b/git-interface/db.py
deleted file mode 100644
index 75d2283..0000000
--- a/git-interface/db.py
+++ /dev/null
@@ -1,51 +0,0 @@
-import mysql.connector
-import sqlite3
-
-import config
-
-
-class Connection:
- _conn = None
- _paramstyle = None
-
- def __init__(self):
- aur_db_backend = config.get('database', 'backend')
-
- if aur_db_backend == 'mysql':
- aur_db_host = config.get('database', 'host')
- aur_db_name = config.get('database', 'name')
- aur_db_user = config.get('database', 'user')
- aur_db_pass = config.get('database', 'password')
- aur_db_socket = config.get('database', 'socket')
- self._conn = mysql.connector.connect(host=aur_db_host,
- user=aur_db_user,
- passwd=aur_db_pass,
- db=aur_db_name,
- unix_socket=aur_db_socket,
- buffered=True)
- self._paramstyle = mysql.connector.paramstyle
- elif aur_db_backend == 'sqlite':
- aur_db_name = config.get('database', 'name')
- self._conn = sqlite3.connect(aur_db_name)
- self._paramstyle = sqlite3.paramstyle
- else:
- raise ValueError('unsupported database backend')
-
- def execute(self, query, params=()):
- if self._paramstyle in ('format', 'pyformat'):
- query = query.replace('%', '%%').replace('?', '%s')
- elif self._paramstyle == 'qmark':
- pass
- else:
- raise ValueError('unsupported paramstyle')
-
- cur = self._conn.cursor()
- cur.execute(query, params)
-
- return cur
-
- def commit(self):
- self._conn.commit()
-
- def close(self):
- self._conn.close()