summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgit-interface/git-serve.py46
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.",