mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
git-serve: Move entry point to a main() method
Move the main program logic of git-serve to a main() method such that it can be used as a module and easily be invoked by setuptools wrapper scripts. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
b8318d2587
commit
8468b6be4b
1 changed files with 102 additions and 96 deletions
|
@ -289,22 +289,23 @@ def usage(cmds):
|
|||
exit(0)
|
||||
|
||||
|
||||
user = os.environ.get('AUR_USER')
|
||||
privileged = (os.environ.get('AUR_PRIVILEGED', '0') == '1')
|
||||
ssh_cmd = os.environ.get('SSH_ORIGINAL_COMMAND')
|
||||
ssh_client = os.environ.get('SSH_CLIENT')
|
||||
def main():
|
||||
user = os.environ.get('AUR_USER')
|
||||
privileged = (os.environ.get('AUR_PRIVILEGED', '0') == '1')
|
||||
ssh_cmd = os.environ.get('SSH_ORIGINAL_COMMAND')
|
||||
ssh_client = os.environ.get('SSH_CLIENT')
|
||||
|
||||
if not ssh_cmd:
|
||||
if not ssh_cmd:
|
||||
die_with_help("Interactive shell is disabled.")
|
||||
cmdargv = shlex.split(ssh_cmd)
|
||||
action = cmdargv[0]
|
||||
remote_addr = ssh_client.split(' ')[0] if ssh_client else None
|
||||
cmdargv = shlex.split(ssh_cmd)
|
||||
action = cmdargv[0]
|
||||
remote_addr = ssh_client.split(' ')[0] if ssh_client else None
|
||||
|
||||
if enable_maintenance:
|
||||
if enable_maintenance:
|
||||
if remote_addr not in maintenance_exc:
|
||||
die("The AUR is down due to maintenance. We will be back soon.")
|
||||
|
||||
if action == 'git-upload-pack' or action == 'git-receive-pack':
|
||||
if action == 'git-upload-pack' or action == 'git-receive-pack':
|
||||
if len(cmdargv) < 2:
|
||||
die_with_help("{:s}: missing path".format(action))
|
||||
|
||||
|
@ -326,22 +327,23 @@ if action == 'git-upload-pack' or action == 'git-receive-pack':
|
|||
os.environ["GIT_NAMESPACE"] = pkgbase
|
||||
cmd = action + " '" + repo_path + "'"
|
||||
os.execl(git_shell_cmd, git_shell_cmd, '-c', cmd)
|
||||
elif action == 'set-keywords':
|
||||
elif action == 'set-keywords':
|
||||
if len(cmdargv) < 2:
|
||||
die_with_help("{:s}: missing repository name".format(action))
|
||||
pkgbase_set_keywords(cmdargv[1], cmdargv[2:])
|
||||
elif action == 'list-repos':
|
||||
elif action == 'list-repos':
|
||||
if len(cmdargv) > 1:
|
||||
die_with_help("{:s}: too many arguments".format(action))
|
||||
list_repos(user)
|
||||
elif action == 'setup-repo':
|
||||
elif action == 'setup-repo':
|
||||
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))
|
||||
warn('{:s} is deprecated. Use `git push` to create new repositories.'.format(action))
|
||||
warn('{:s} is deprecated. '
|
||||
'Use `git push` to create new repositories.'.format(action))
|
||||
create_pkgbase(cmdargv[1], user)
|
||||
elif action == 'restore':
|
||||
elif action == 'restore':
|
||||
if len(cmdargv) < 2:
|
||||
die_with_help("{:s}: missing repository name".format(action))
|
||||
if len(cmdargv) > 2:
|
||||
|
@ -358,7 +360,7 @@ 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':
|
||||
elif action == 'adopt':
|
||||
if len(cmdargv) < 2:
|
||||
die_with_help("{:s}: missing repository name".format(action))
|
||||
if len(cmdargv) > 2:
|
||||
|
@ -366,7 +368,7 @@ elif action == 'adopt':
|
|||
|
||||
pkgbase = cmdargv[1]
|
||||
pkgbase_adopt(pkgbase, user, privileged)
|
||||
elif action == 'disown':
|
||||
elif action == 'disown':
|
||||
if len(cmdargv) < 2:
|
||||
die_with_help("{:s}: missing repository name".format(action))
|
||||
if len(cmdargv) > 2:
|
||||
|
@ -374,14 +376,14 @@ elif action == 'disown':
|
|||
|
||||
pkgbase = cmdargv[1]
|
||||
pkgbase_disown(pkgbase, user, privileged)
|
||||
elif action == 'set-comaintainers':
|
||||
elif action == 'set-comaintainers':
|
||||
if len(cmdargv) < 2:
|
||||
die_with_help("{:s}: missing repository name".format(action))
|
||||
|
||||
pkgbase = cmdargv[1]
|
||||
userlist = cmdargv[2:]
|
||||
pkgbase_set_comaintainers(pkgbase, userlist, user, privileged)
|
||||
elif action == 'help':
|
||||
elif action == 'help':
|
||||
cmds = {
|
||||
"adopt <name>": "Adopt a package base.",
|
||||
"disown <name>": "Disown a package base.",
|
||||
|
@ -395,5 +397,9 @@ elif action == 'help':
|
|||
"git-upload-pack": "Internal command used with Git.",
|
||||
}
|
||||
usage(cmds)
|
||||
else:
|
||||
else:
|
||||
die_with_help("invalid command: {:s}".format(action))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Reference in a new issue