mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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>
This commit is contained in:
parent
1946486a67
commit
dc3fd60715
10 changed files with 66 additions and 42 deletions
0
aurweb/__init__.py
Normal file
0
aurweb/__init__.py
Normal file
|
@ -1,7 +1,7 @@
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
import config
|
import aurweb.config
|
||||||
|
|
||||||
|
|
||||||
class Connection:
|
class Connection:
|
||||||
|
@ -9,14 +9,14 @@ class Connection:
|
||||||
_paramstyle = None
|
_paramstyle = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
aur_db_backend = config.get('database', 'backend')
|
aur_db_backend = aurweb.config.get('database', 'backend')
|
||||||
|
|
||||||
if aur_db_backend == 'mysql':
|
if aur_db_backend == 'mysql':
|
||||||
aur_db_host = config.get('database', 'host')
|
aur_db_host = aurweb.config.get('database', 'host')
|
||||||
aur_db_name = config.get('database', 'name')
|
aur_db_name = aurweb.config.get('database', 'name')
|
||||||
aur_db_user = config.get('database', 'user')
|
aur_db_user = aurweb.config.get('database', 'user')
|
||||||
aur_db_pass = config.get('database', 'password')
|
aur_db_pass = aurweb.config.get('database', 'password')
|
||||||
aur_db_socket = config.get('database', 'socket')
|
aur_db_socket = aurweb.config.get('database', 'socket')
|
||||||
self._conn = mysql.connector.connect(host=aur_db_host,
|
self._conn = mysql.connector.connect(host=aur_db_host,
|
||||||
user=aur_db_user,
|
user=aur_db_user,
|
||||||
passwd=aur_db_pass,
|
passwd=aur_db_pass,
|
||||||
|
@ -25,7 +25,7 @@ class Connection:
|
||||||
buffered=True)
|
buffered=True)
|
||||||
self._paramstyle = mysql.connector.paramstyle
|
self._paramstyle = mysql.connector.paramstyle
|
||||||
elif aur_db_backend == 'sqlite':
|
elif aur_db_backend == 'sqlite':
|
||||||
aur_db_name = config.get('database', 'name')
|
aur_db_name = aurweb.config.get('database', 'name')
|
||||||
self._conn = sqlite3.connect(aur_db_name)
|
self._conn = sqlite3.connect(aur_db_name)
|
||||||
self._paramstyle = sqlite3.paramstyle
|
self._paramstyle = sqlite3.paramstyle
|
||||||
else:
|
else:
|
0
git-interface/__init__.py
Normal file
0
git-interface/__init__.py
Normal file
|
@ -4,8 +4,8 @@ import shlex
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import config
|
import aurweb.config
|
||||||
import db
|
import aurweb.db
|
||||||
|
|
||||||
|
|
||||||
def format_command(env_vars, command, ssh_opts, ssh_key):
|
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():
|
def main():
|
||||||
valid_keytypes = config.get('auth', 'valid-keytypes').split()
|
valid_keytypes = aurweb.config.get('auth', 'valid-keytypes').split()
|
||||||
username_regex = config.get('auth', 'username-regex')
|
username_regex = aurweb.config.get('auth', 'username-regex')
|
||||||
git_serve_cmd = config.get('auth', 'git-serve-cmd')
|
git_serve_cmd = aurweb.config.get('auth', 'git-serve-cmd')
|
||||||
ssh_opts = config.get('auth', 'ssh-options')
|
ssh_opts = aurweb.config.get('auth', 'ssh-options')
|
||||||
|
|
||||||
keytype = sys.argv[1]
|
keytype = sys.argv[1]
|
||||||
keytext = sys.argv[2]
|
keytext = sys.argv[2]
|
||||||
if keytype not in valid_keytypes:
|
if keytype not in valid_keytypes:
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
conn = db.Connection()
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
cur = conn.execute("SELECT Users.Username, Users.AccountTypeID FROM Users "
|
cur = conn.execute("SELECT Users.Username, Users.AccountTypeID FROM Users "
|
||||||
"INNER JOIN SSHPubKeys ON SSHPubKeys.UserID = Users.ID "
|
"INNER JOIN SSHPubKeys ON SSHPubKeys.UserID = Users.ID "
|
||||||
|
|
|
@ -7,23 +7,23 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import config
|
import aurweb.config
|
||||||
import db
|
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_path = aurweb.config.get('serve', 'repo-path')
|
||||||
repo_regex = config.get('serve', 'repo-regex')
|
repo_regex = aurweb.config.get('serve', 'repo-regex')
|
||||||
git_shell_cmd = config.get('serve', 'git-shell-cmd')
|
git_shell_cmd = aurweb.config.get('serve', 'git-shell-cmd')
|
||||||
git_update_cmd = config.get('serve', 'git-update-cmd')
|
git_update_cmd = aurweb.config.get('serve', 'git-update-cmd')
|
||||||
ssh_cmdline = config.get('serve', 'ssh-cmdline')
|
ssh_cmdline = aurweb.config.get('serve', 'ssh-cmdline')
|
||||||
|
|
||||||
enable_maintenance = config.getboolean('options', 'enable-maintenance')
|
enable_maintenance = aurweb.config.getboolean('options', 'enable-maintenance')
|
||||||
maintenance_exc = config.get('options', 'maintenance-exceptions').split()
|
maintenance_exc = aurweb.config.get('options', 'maintenance-exceptions').split()
|
||||||
|
|
||||||
|
|
||||||
def pkgbase_from_name(pkgbase):
|
def pkgbase_from_name(pkgbase):
|
||||||
conn = db.Connection()
|
conn = aurweb.db.Connection()
|
||||||
cur = conn.execute("SELECT ID FROM PackageBases WHERE Name = ?", [pkgbase])
|
cur = conn.execute("SELECT ID FROM PackageBases WHERE Name = ?", [pkgbase])
|
||||||
|
|
||||||
row = cur.fetchone()
|
row = cur.fetchone()
|
||||||
|
@ -35,7 +35,7 @@ def pkgbase_exists(pkgbase):
|
||||||
|
|
||||||
|
|
||||||
def list_repos(user):
|
def list_repos(user):
|
||||||
conn = db.Connection()
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
|
cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
|
||||||
userid = cur.fetchone()[0]
|
userid = cur.fetchone()[0]
|
||||||
|
@ -55,7 +55,7 @@ def create_pkgbase(pkgbase, user):
|
||||||
if pkgbase_exists(pkgbase):
|
if pkgbase_exists(pkgbase):
|
||||||
die('{:s}: package base already exists: {:s}'.format(action, 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])
|
cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
|
||||||
userid = cur.fetchone()[0]
|
userid = cur.fetchone()[0]
|
||||||
|
@ -81,7 +81,7 @@ def pkgbase_adopt(pkgbase, user, privileged):
|
||||||
if not pkgbase_id:
|
if not pkgbase_id:
|
||||||
die('{:s}: package base not found: {:s}'.format(action, pkgbase))
|
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 " +
|
cur = conn.execute("SELECT ID FROM PackageBases WHERE ID = ? AND " +
|
||||||
"MaintainerUID IS NULL", [pkgbase_id])
|
"MaintainerUID IS NULL", [pkgbase_id])
|
||||||
|
@ -111,7 +111,7 @@ def pkgbase_adopt(pkgbase, user, privileged):
|
||||||
|
|
||||||
|
|
||||||
def pkgbase_get_comaintainers(pkgbase):
|
def pkgbase_get_comaintainers(pkgbase):
|
||||||
conn = db.Connection()
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
cur = conn.execute("SELECT UserName FROM PackageComaintainers " +
|
cur = conn.execute("SELECT UserName FROM PackageComaintainers " +
|
||||||
"INNER JOIN Users " +
|
"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):
|
if not privileged and not pkgbase_has_full_access(pkgbase, user):
|
||||||
die('{:s}: permission denied: {:s}'.format(action, user))
|
die('{:s}: permission denied: {:s}'.format(action, user))
|
||||||
|
|
||||||
conn = db.Connection()
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
userlist_old = set(pkgbase_get_comaintainers(pkgbase))
|
userlist_old = set(pkgbase_get_comaintainers(pkgbase))
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ def pkgbase_disown(pkgbase, user, privileged):
|
||||||
comaintainers = []
|
comaintainers = []
|
||||||
new_maintainer_userid = None
|
new_maintainer_userid = None
|
||||||
|
|
||||||
conn = db.Connection()
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
# Make the first co-maintainer the new maintainer, unless the action was
|
# Make the first co-maintainer the new maintainer, unless the action was
|
||||||
# enforced by a Trusted User.
|
# enforced by a Trusted User.
|
||||||
|
@ -232,7 +232,7 @@ def pkgbase_set_keywords(pkgbase, keywords):
|
||||||
if not pkgbase_id:
|
if not pkgbase_id:
|
||||||
die('{:s}: package base not found: {:s}'.format(action, pkgbase))
|
die('{:s}: package base not found: {:s}'.format(action, pkgbase))
|
||||||
|
|
||||||
conn = db.Connection()
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
conn.execute("DELETE FROM PackageKeywords WHERE PackageBaseID = ?",
|
conn.execute("DELETE FROM PackageKeywords WHERE PackageBaseID = ?",
|
||||||
[pkgbase_id])
|
[pkgbase_id])
|
||||||
|
@ -245,7 +245,7 @@ def pkgbase_set_keywords(pkgbase, keywords):
|
||||||
|
|
||||||
|
|
||||||
def pkgbase_has_write_access(pkgbase, user):
|
def pkgbase_has_write_access(pkgbase, user):
|
||||||
conn = db.Connection()
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
cur = conn.execute("SELECT COUNT(*) FROM PackageBases " +
|
cur = conn.execute("SELECT COUNT(*) FROM PackageBases " +
|
||||||
"LEFT JOIN PackageComaintainers " +
|
"LEFT JOIN PackageComaintainers " +
|
||||||
|
@ -259,7 +259,7 @@ def pkgbase_has_write_access(pkgbase, user):
|
||||||
|
|
||||||
|
|
||||||
def pkgbase_has_full_access(pkgbase, user):
|
def pkgbase_has_full_access(pkgbase, user):
|
||||||
conn = db.Connection()
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
cur = conn.execute("SELECT COUNT(*) FROM PackageBases " +
|
cur = conn.execute("SELECT COUNT(*) FROM PackageBases " +
|
||||||
"INNER JOIN Users " +
|
"INNER JOIN Users " +
|
||||||
|
|
|
@ -10,15 +10,15 @@ import time
|
||||||
import srcinfo.parse
|
import srcinfo.parse
|
||||||
import srcinfo.utils
|
import srcinfo.utils
|
||||||
|
|
||||||
import config
|
import aurweb.config
|
||||||
import db
|
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_path = aurweb.config.get('serve', 'repo-path')
|
||||||
repo_regex = config.get('serve', 'repo-regex')
|
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):
|
def size_humanize(num):
|
||||||
|
@ -256,7 +256,7 @@ def main():
|
||||||
if refname != "refs/heads/master":
|
if refname != "refs/heads/master":
|
||||||
die("pushing to a branch other than master is restricted")
|
die("pushing to a branch other than master is restricted")
|
||||||
|
|
||||||
conn = db.Connection()
|
conn = aurweb.db.Connection()
|
||||||
|
|
||||||
# Detect and deny non-fast-forwards.
|
# Detect and deny non-fast-forwards.
|
||||||
if sha1_old != "0" * 40 and not privileged:
|
if sha1_old != "0" * 40 and not privileged:
|
||||||
|
|
|
@ -2,6 +2,10 @@ TEST_DIRECTORY="$(pwd)"
|
||||||
|
|
||||||
. ./sharness.sh
|
. ./sharness.sh
|
||||||
|
|
||||||
|
# Configure python search path.
|
||||||
|
PYTHONPATH="$TEST_DIRECTORY/../../"
|
||||||
|
export PYTHONPATH
|
||||||
|
|
||||||
# Configure paths to the Git interface scripts.
|
# Configure paths to the Git interface scripts.
|
||||||
GIT_AUTH="$TEST_DIRECTORY/../git-auth.py"
|
GIT_AUTH="$TEST_DIRECTORY/../git-auth.py"
|
||||||
GIT_SERVE="$TEST_DIRECTORY/../git-serve.py"
|
GIT_SERVE="$TEST_DIRECTORY/../git-serve.py"
|
||||||
|
|
0
scripts/__init__.py
Normal file
0
scripts/__init__.py
Normal file
20
setup.py
Normal file
20
setup.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import re
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
import sys
|
||||||
|
|
||||||
|
version = None
|
||||||
|
with open('web/lib/version.inc.php', 'r') as f:
|
||||||
|
for line in f.readlines():
|
||||||
|
match = re.match(r'^define\("AURWEB_VERSION", "v([0-9.]+)"\);$', line)
|
||||||
|
if match:
|
||||||
|
version = match.group(1)
|
||||||
|
|
||||||
|
if not version:
|
||||||
|
sys.stderr.write('error: Failed to parse version file!')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name="aurweb",
|
||||||
|
version=version,
|
||||||
|
packages=find_packages(),
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue