summaryrefslogtreecommitdiffstats
path: root/git-interface
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
parent1946486a67d6085318e00c753d341ab05d12904c (diff)
downloadaur-dc3fd60715a5b17b9542ec888c6eaeb14c284e2b.tar.gz
aur-dc3fd60715a5b17b9542ec888c6eaeb14c284e2b.tar.xz
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')
-rw-r--r--git-interface/__init__.py0
-rw-r--r--git-interface/config.py31
-rw-r--r--git-interface/db.py51
-rwxr-xr-xgit-interface/git-auth.py14
-rwxr-xr-xgit-interface/git-serve.py40
-rwxr-xr-xgit-interface/git-update.py14
-rw-r--r--git-interface/test/setup.sh4
7 files changed, 38 insertions, 116 deletions
diff --git a/git-interface/__init__.py b/git-interface/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/git-interface/__init__.py
diff --git a/git-interface/config.py b/git-interface/config.py
deleted file mode 100644
index aac188b1..00000000
--- a/git-interface/config.py
+++ /dev/null
@@ -1,31 +0,0 @@
-import configparser
-import os
-
-_parser = None
-
-
-def _get_parser():
- global _parser
-
- if not _parser:
- _parser = configparser.RawConfigParser()
- if 'AUR_CONFIG' in os.environ:
- path = os.environ.get('AUR_CONFIG')
- else:
- relpath = "/../conf/config"
- path = os.path.dirname(os.path.realpath(__file__)) + relpath
- _parser.read(path)
-
- return _parser
-
-
-def get(section, option):
- return _get_parser().get(section, option)
-
-
-def getboolean(section, option):
- return _get_parser().getboolean(section, option)
-
-
-def getint(section, option):
- return _get_parser().getint(section, option)
diff --git a/git-interface/db.py b/git-interface/db.py
deleted file mode 100644
index 75d2283d..00000000
--- 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()
diff --git a/git-interface/git-auth.py b/git-interface/git-auth.py
index d3b0188b..022b0fff 100755
--- a/git-interface/git-auth.py
+++ b/git-interface/git-auth.py
@@ -4,8 +4,8 @@ import shlex
import re
import sys
-import config
-import db
+import aurweb.config
+import aurweb.db
def format_command(env_vars, command, ssh_opts, ssh_key):
@@ -24,17 +24,17 @@ def format_command(env_vars, command, ssh_opts, ssh_key):
def main():
- valid_keytypes = config.get('auth', 'valid-keytypes').split()
- username_regex = config.get('auth', 'username-regex')
- git_serve_cmd = config.get('auth', 'git-serve-cmd')
- ssh_opts = config.get('auth', 'ssh-options')
+ valid_keytypes = aurweb.config.get('auth', 'valid-keytypes').split()
+ username_regex = aurweb.config.get('auth', 'username-regex')
+ git_serve_cmd = aurweb.config.get('auth', 'git-serve-cmd')
+ ssh_opts = aurweb.config.get('auth', 'ssh-options')
keytype = sys.argv[1]
keytext = sys.argv[2]
if keytype not in valid_keytypes:
exit(1)
- conn = db.Connection()
+ conn = aurweb.db.Connection()
cur = conn.execute("SELECT Users.Username, Users.AccountTypeID FROM Users "
"INNER JOIN SSHPubKeys ON SSHPubKeys.UserID = Users.ID "
diff --git a/git-interface/git-serve.py b/git-interface/git-serve.py
index 8bcecd27..5f3b26dd 100755
--- a/git-interface/git-serve.py
+++ b/git-interface/git-serve.py
@@ -7,23 +7,23 @@ import subprocess
import sys
import time
-import config
-import db
+import aurweb.config
+import aurweb.db
-notify_cmd = config.get('notifications', 'notify-cmd')
+notify_cmd = aurweb.config.get('notifications', 'notify-cmd')
-repo_path = config.get('serve', 'repo-path')
-repo_regex = config.get('serve', 'repo-regex')
-git_shell_cmd = config.get('serve', 'git-shell-cmd')
-git_update_cmd = config.get('serve', 'git-update-cmd')
-ssh_cmdline = config.get('serve', 'ssh-cmdline')
+repo_path = aurweb.config.get('serve', 'repo-path')
+repo_regex = aurweb.config.get('serve', 'repo-regex')
+git_shell_cmd = aurweb.config.get('serve', 'git-shell-cmd')
+git_update_cmd = aurweb.config.get('serve', 'git-update-cmd')
+ssh_cmdline = aurweb.config.get('serve', 'ssh-cmdline')
-enable_maintenance = config.getboolean('options', 'enable-maintenance')
-maintenance_exc = config.get('options', 'maintenance-exceptions').split()
+enable_maintenance = aurweb.config.getboolean('options', 'enable-maintenance')
+maintenance_exc = aurweb.config.get('options', 'maintenance-exceptions').split()
def pkgbase_from_name(pkgbase):
- conn = db.Connection()
+ conn = aurweb.db.Connection()
cur = conn.execute("SELECT ID FROM PackageBases WHERE Name = ?", [pkgbase])
row = cur.fetchone()
@@ -35,7 +35,7 @@ def pkgbase_exists(pkgbase):
def list_repos(user):
- conn = db.Connection()
+ conn = aurweb.db.Connection()
cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
userid = cur.fetchone()[0]
@@ -55,7 +55,7 @@ def create_pkgbase(pkgbase, user):
if pkgbase_exists(pkgbase):
die('{:s}: package base already exists: {:s}'.format(action, pkgbase))
- conn = db.Connection()
+ conn = aurweb.db.Connection()
cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
userid = cur.fetchone()[0]
@@ -81,7 +81,7 @@ def pkgbase_adopt(pkgbase, user, privileged):
if not pkgbase_id:
die('{:s}: package base not found: {:s}'.format(action, pkgbase))
- conn = db.Connection()
+ conn = aurweb.db.Connection()
cur = conn.execute("SELECT ID FROM PackageBases WHERE ID = ? AND " +
"MaintainerUID IS NULL", [pkgbase_id])
@@ -111,7 +111,7 @@ def pkgbase_adopt(pkgbase, user, privileged):
def pkgbase_get_comaintainers(pkgbase):
- conn = db.Connection()
+ conn = aurweb.db.Connection()
cur = conn.execute("SELECT UserName FROM PackageComaintainers " +
"INNER JOIN Users " +
@@ -132,7 +132,7 @@ def pkgbase_set_comaintainers(pkgbase, userlist, user, privileged):
if not privileged and not pkgbase_has_full_access(pkgbase, user):
die('{:s}: permission denied: {:s}'.format(action, user))
- conn = db.Connection()
+ conn = aurweb.db.Connection()
userlist_old = set(pkgbase_get_comaintainers(pkgbase))
@@ -198,7 +198,7 @@ def pkgbase_disown(pkgbase, user, privileged):
comaintainers = []
new_maintainer_userid = None
- conn = db.Connection()
+ conn = aurweb.db.Connection()
# Make the first co-maintainer the new maintainer, unless the action was
# enforced by a Trusted User.
@@ -232,7 +232,7 @@ def pkgbase_set_keywords(pkgbase, keywords):
if not pkgbase_id:
die('{:s}: package base not found: {:s}'.format(action, pkgbase))
- conn = db.Connection()
+ conn = aurweb.db.Connection()
conn.execute("DELETE FROM PackageKeywords WHERE PackageBaseID = ?",
[pkgbase_id])
@@ -245,7 +245,7 @@ def pkgbase_set_keywords(pkgbase, keywords):
def pkgbase_has_write_access(pkgbase, user):
- conn = db.Connection()
+ conn = aurweb.db.Connection()
cur = conn.execute("SELECT COUNT(*) FROM PackageBases " +
"LEFT JOIN PackageComaintainers " +
@@ -259,7 +259,7 @@ def pkgbase_has_write_access(pkgbase, user):
def pkgbase_has_full_access(pkgbase, user):
- conn = db.Connection()
+ conn = aurweb.db.Connection()
cur = conn.execute("SELECT COUNT(*) FROM PackageBases " +
"INNER JOIN Users " +
diff --git a/git-interface/git-update.py b/git-interface/git-update.py
index 36c38ae8..73373410 100755
--- a/git-interface/git-update.py
+++ b/git-interface/git-update.py
@@ -10,15 +10,15 @@ import time
import srcinfo.parse
import srcinfo.utils
-import config
-import db
+import aurweb.config
+import aurweb.db
-notify_cmd = config.get('notifications', 'notify-cmd')
+notify_cmd = aurweb.config.get('notifications', 'notify-cmd')
-repo_path = config.get('serve', 'repo-path')
-repo_regex = config.get('serve', 'repo-regex')
+repo_path = aurweb.config.get('serve', 'repo-path')
+repo_regex = aurweb.config.get('serve', 'repo-regex')
-max_blob_size = config.getint('update', 'max-blob-size')
+max_blob_size = aurweb.config.getint('update', 'max-blob-size')
def size_humanize(num):
@@ -256,7 +256,7 @@ def main():
if refname != "refs/heads/master":
die("pushing to a branch other than master is restricted")
- conn = db.Connection()
+ conn = aurweb.db.Connection()
# Detect and deny non-fast-forwards.
if sha1_old != "0" * 40 and not privileged:
diff --git a/git-interface/test/setup.sh b/git-interface/test/setup.sh
index f9c16166..d269af66 100644
--- a/git-interface/test/setup.sh
+++ b/git-interface/test/setup.sh
@@ -2,6 +2,10 @@ TEST_DIRECTORY="$(pwd)"
. ./sharness.sh
+# Configure python search path.
+PYTHONPATH="$TEST_DIRECTORY/../../"
+export PYTHONPATH
+
# Configure paths to the Git interface scripts.
GIT_AUTH="$TEST_DIRECTORY/../git-auth.py"
GIT_SERVE="$TEST_DIRECTORY/../git-serve.py"