diff options
author | Lukas Fleischer <lfleischer@archlinux.org> | 2016-09-12 19:56:12 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2016-09-17 20:17:39 +0200 |
commit | ce12e3b82d3089cf4ac5476c70e178f1fb1a0a7e (patch) | |
tree | bbb0c388f65b89aa5c86eafb6adfb66418a37246 | |
parent | e0450694216e5e88df6f48aaa9f7adc91e3f23f3 (diff) | |
download | aur-ce12e3b82d3089cf4ac5476c70e178f1fb1a0a7e.tar.gz aur-ce12e3b82d3089cf4ac5476c70e178f1fb1a0a7e.tar.xz |
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>
-rwxr-xr-x | git-interface/git-serve.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/git-interface/git-serve.py b/git-interface/git-serve.py index 0187de9a..353771c9 100755 --- a/git-interface/git-serve.py +++ b/git-interface/git-serve.py @@ -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.", |