def export_notifications(**kwargs): """Export a mailer.py config file For each user/repository pair, a config group is created. Only if a user has read or read/write permission to one or multiple paths in that repository, _and_ if the user has notifications enabled for that repository, _and_ if the user has a non-empty email-address. Multiple paths are grouped together by a regexp group (multiple|paths)""" bindir = options.static_path("hooks") + 'svn' # get a list of all users from submin.models import user users = [user.User(name) for name in user.list(user.FakeAdminUser())] groups = [] for u in users: if not u.email: continue u_notif = u.notifications() for repos in u_notif: repos_path = str(options.env_path("svn_dir") + repos) if not u_notif[repos]["enabled"]: continue # strip leading / paths = [ x[1:] for x in permissions.list_readable_user_paths(repos, "svn", u) ] if len(paths) == 0: continue elif len(paths) == 1: for_paths = paths[0] elif len(paths) > 0: for_paths = "(" + "|".join(paths) + ")" # Only match complete path, not partial paths (ticket #257) repos_path_re = '^' + repos_path + '$' g = { "repos_name": repos, "for_repos": repos_path_re, "email": u.email, "for_paths": for_paths, "username": u.name } groups.append(g) email = options.value( 'commit_email_from', 'Please configure commit_email_from <*****@*****.**>') templatevariables = {"groups": groups, 'from_addr': email} from submin.template.shortcuts import evaluate content = evaluate("plugins/vcs/svn/mailer.conf", templatevariables) filename = str((options.env_path() + 'conf') + 'mailer.py.conf') file(filename, 'w').writelines(content.encode('utf-8'))
def run(username): if "SSH_ORIGINAL_COMMAND" not in os.environ: print ("No command provided. " \ + "Expected something like git-receive-pack", file=sys.stderr) sys.exit(1) orig_cmd = os.environ["SSH_ORIGINAL_COMMAND"] if not orig_cmd.startswith("git") or orig_cmd[3] not in (' ', '-'): print ("Not a git-command. Expected something like " \ + "git-receive-pack",file=sys.stderr) sys.exit(1) # command is something like `git-receive-pack repo.git' # or `git receive-pack repo.git' cmd, repo = orig_cmd.split(" ", 1) if repo[0] == repo[-1] == "'": repo = repo[1:-1] # git 1.5 adds a slash? if repo[0] == '/': repo = repo[1:] repo = repo[:-4] # remove '.git' sub_cmd = cmd[4:] u = user.User(username) readable_paths = permissions.list_readable_user_paths(repo, "git", u) if not readable_paths: print("Permission denied for %s to user %s" % (repo, u), file=sys.stderr) sys.exit(1) if sub_cmd not in WRITE_CMDS + READ_CMDS: print("Unrecognized command:", cmd, file=sys.stderr) sys.exit(1) elif sub_cmd in WRITE_CMDS: # check if we have write access writeable_paths = permissions.list_writeable_user_paths(repo, "git", u) if not writeable_paths: print ("Permission denied for writing, for %s to user %s" % \ (repo, u),file=sys.stderr) sys.exit(1) # To pass on to the git-hook os.environ["SUBMIN_USERNAME"] = username os.environ["SUBMIN_REPO"] = repo repo_path = repository.directory('git', repo) print("Original command: %s" % orig_cmd, file=sys.stderr) print("executing git-%s '%s'" % (sub_cmd, repo_path), file=sys.stderr) # XXX: retreive git-path from options. os.execvp('git', ['git', 'shell', '-c', "git-%s '%s'" % (sub_cmd, repo_path)])
def export_notifications(**kwargs): """Export a mailer.py config file For each user/repository pair, a config group is created. Only if a user has read or read/write permission to one or multiple paths in that repository, _and_ if the user has notifications enabled for that repository, _and_ if the user has a non-empty email-address. Multiple paths are grouped together by a regexp group (multiple|paths)""" bindir = options.static_path("hooks") + 'svn' # get a list of all users from submin.models import user users = [user.User(name) for name in user.list(user.FakeAdminUser())] groups = [] for u in users: if not u.email: continue u_notif = u.notifications() for repos in u_notif: repos_path = str(options.env_path("svn_dir") + repos) if not u_notif[repos]["enabled"]: continue # strip leading / paths = [x[1:] for x in permissions.list_readable_user_paths(repos, "svn", u)] if len(paths) == 0: continue elif len(paths) == 1: for_paths = paths[0] elif len(paths) > 0: for_paths = "(" + "|".join(paths) + ")" # Only match complete path, not partial paths (ticket #257) repos_path_re = '^' + repos_path + '$' g = {"repos_name": repos, "for_repos": repos_path_re, "email": u.email, "for_paths": for_paths, "username": u.name} groups.append(g) email = options.value('commit_email_from', 'Please configure commit_email_from <*****@*****.**>') templatevariables = {"groups": groups, 'from_addr': email} from submin.template.shortcuts import evaluate content = evaluate("plugins/vcs/svn/mailer.conf", templatevariables) filename = str((options.env_path() + 'conf') + 'mailer.py.conf') file(filename, 'w').writelines(content.encode('utf-8'))
def run(username): if "SSH_ORIGINAL_COMMAND" not in os.environ: print >>sys.stderr, "No command provided. " + "Expected something like git-receive-pack" sys.exit(1) orig_cmd = os.environ["SSH_ORIGINAL_COMMAND"] if not orig_cmd.startswith("git") or orig_cmd[3] not in (" ", "-"): print >>sys.stderr, "Not a git-command. Expected something like " + "git-receive-pack" sys.exit(1) # command is something like `git-receive-pack repo.git' # or `git receive-pack repo.git' cmd, repo = orig_cmd.split(" ", 1) if repo[0] == repo[-1] == "'": repo = repo[1:-1] # git 1.5 adds a slash? if repo[0] == "/": repo = repo[1:] repo = repo[:-4] # remove '.git' sub_cmd = cmd[4:] u = user.User(username) readable_paths = permissions.list_readable_user_paths(repo, "git", u) if not readable_paths: print >>sys.stderr, "Permission denied for %s to user %s" % (repo, u) sys.exit(1) if sub_cmd not in WRITE_CMDS + READ_CMDS: print >>sys.stderr, "Unrecognized command:", cmd sys.exit(1) elif sub_cmd in WRITE_CMDS: # check if we have write access writeable_paths = permissions.list_writeable_user_paths(repo, "git", u) if not writeable_paths: print >>sys.stderr, "Permission denied for writing, for %s to user %s" % (repo, u) sys.exit(1) # To pass on to the git-hook os.environ["SUBMIN_USERNAME"] = username os.environ["SUBMIN_REPO"] = repo repo_path = repository.directory("git", repo) print >>sys.stderr, "Original command: %s" % orig_cmd print >>sys.stderr, "executing git-%s '%s'" % (sub_cmd, repo_path) # XXX: retreive git-path from options. os.execvp("git", ["git", "shell", "-c", "git-%s '%s'" % (sub_cmd, repo_path)])