git-serve: Add support for adopting package bases

Add support for adopting packages from the SSH interface. The syntax is
`adopt <pkgbase>`.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2016-09-12 19:56:12 +02:00
parent e045069421
commit ce12e3b82d

View file

@ -3,12 +3,15 @@
import os
import re
import shlex
import subprocess
import sys
import time
import config
import db
notify_cmd = 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')
@ -73,6 +76,40 @@ def create_pkgbase(pkgbase, user):
conn.close()
def pkgbase_adopt(pkgbase):
pkgbase_id = pkgbase_from_name(pkgbase)
if not pkgbase_id:
die('{:s}: package base not found: {:s}'.format(action, pkgbase))
conn = db.Connection()
cur = conn.execute("SELECT ID FROM PackageBases WHERE ID = ? AND " +
"MaintainerUID IS NULL", [pkgbase_id])
if not privileged and not cur.fetchone():
die('{:s}: permission denied: {:s}'.format(action, user))
cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
userid = cur.fetchone()[0]
if userid == 0:
die('{:s}: unknown user: {:s}'.format(action, user))
cur = conn.execute("UPDATE PackageBases SET MaintainerUID = ? " +
"WHERE ID = ?", [userid, pkgbase_id])
cur = conn.execute("SELECT COUNT(*) FROM PackageNotifications WHERE " +
"PackageBaseID = ? AND UserID = ?",
[pkgbase_id, userid])
if cur.fetchone()[0] == 0:
cur = conn.execute("INSERT INTO PackageNotifications " +
"(PackageBaseID, UserID) VALUES (?, ?)",
[pkgbase_id, userid])
conn.commit()
subprocess.Popen((notify_cmd, 'adopt', str(pkgbase_id), str(userid)))
conn.close()
def pkgbase_set_keywords(pkgbase, keywords):
pkgbase_id = pkgbase_from_name(pkgbase)
if not pkgbase_id:
@ -194,8 +231,17 @@ elif action == 'restore':
os.environ["AUR_USER"] = user
os.environ["AUR_PKGBASE"] = pkgbase
os.execl(git_update_cmd, git_update_cmd, 'restore')
elif action == 'adopt':
if len(cmdargv) < 2:
die_with_help("{:s}: missing repository name".format(action))
if len(cmdargv) > 2:
die_with_help("{:s}: too many arguments".format(action))
pkgbase = cmdargv[1]
pkgbase_adopt(pkgbase)
elif action == 'help':
cmds = {
"adopt <name>": "Adopt a package base.",
"help": "Show this help message and exit.",
"list-repos": "List all your repositories.",
"restore <name>": "Restore a deleted package base.",