|
Pierre-Yves Chibon |
a27356 |
#-*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
"""
|
|
Pierre-Yves Chibon |
a27356 |
(c) 2015 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
Authors:
|
|
Pierre-Yves Chibon |
a27356 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
"""
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
import datetime
|
|
Pierre-Yves Chibon |
a27356 |
import json
|
|
Pierre-Yves Chibon |
a27356 |
import os
|
|
Pierre-Yves Chibon |
a27356 |
import random
|
|
Pierre-Yves Chibon |
a27356 |
import shutil
|
|
Pierre-Yves Chibon |
a27356 |
import string
|
|
Pierre-Yves Chibon |
a27356 |
import tempfile
|
|
Pierre-Yves Chibon |
a27356 |
import uuid
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
import pygit2
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
import progit.exceptions
|
|
Pierre-Yves Chibon |
a27356 |
import progit.notify
|
|
Pierre-Yves Chibon |
a27356 |
from progit.lib import model
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
def commit_to_patch(repo_obj, commits):
|
|
Pierre-Yves Chibon |
a27356 |
''' For a given commit (PyGit2 commit object) of a specified git repo,
|
|
Pierre-Yves Chibon |
a27356 |
returns a string representation of the changes the commit did in a
|
|
Pierre-Yves Chibon |
a27356 |
format that allows it to be used as patch.
|
|
Pierre-Yves Chibon |
a27356 |
'''
|
|
Pierre-Yves Chibon |
a27356 |
if not isinstance(commits, list):
|
|
Pierre-Yves Chibon |
a27356 |
commits = [commits]
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
patch = ""
|
|
Pierre-Yves Chibon |
a27356 |
for cnt, commit in enumerate(commits):
|
|
Pierre-Yves Chibon |
a27356 |
if commit.parents:
|
|
Pierre-Yves Chibon |
a27356 |
diff = commit.tree.diff_to_tree()
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
parent = repo_obj.revparse_single('%s^' % commit.oid.hex)
|
|
Pierre-Yves Chibon |
a27356 |
diff = repo_obj.diff(parent, commit)
|
|
Pierre-Yves Chibon |
a27356 |
else:
|
|
Pierre-Yves Chibon |
a27356 |
# First commit in the repo
|
|
Pierre-Yves Chibon |
a27356 |
diff = commit.tree.diff_to_tree(swap=True)
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
subject = message = ''
|
|
Pierre-Yves Chibon |
a27356 |
if '\n' in commit.message:
|
|
Pierre-Yves Chibon |
a27356 |
subject, message = commit.message.split('\n', 1)
|
|
Pierre-Yves Chibon |
a27356 |
else:
|
|
Pierre-Yves Chibon |
a27356 |
subject = commit.message
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
if len(commits) > 1:
|
|
Pierre-Yves Chibon |
a27356 |
subject = '[PATCH %s/%s] %s' % (cnt + 1, len(commits), subject)
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
patch += """From %(commit)s Mon Sep 17 00:00:00 2001
|
|
Pierre-Yves Chibon |
a27356 |
From: %(author_name)s <%(author_email)s>
|
|
Pierre-Yves Chibon |
a27356 |
Date: %(date)s
|
|
Pierre-Yves Chibon |
a27356 |
Subject: %(subject)s
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
%(msg)s
|
|
Pierre-Yves Chibon |
a27356 |
---
|
|
Pierre-Yves Chibon |
a27356 |
|
|
Pierre-Yves Chibon |
a27356 |
%(patch)s
|
|
Pierre-Yves Chibon |
a27356 |
""" % (
|
|
Pierre-Yves Chibon |
a27356 |
{
|
|
Pierre-Yves Chibon |
a27356 |
'commit': commit.oid.hex,
|
|
Pierre-Yves Chibon |
a27356 |
'author_name': commit.author.name,
|
|
Pierre-Yves Chibon |
a27356 |
'author_email': commit.author.email,
|
|
Pierre-Yves Chibon |
a27356 |
'date': datetime.datetime.utcfromtimestamp(
|
|
Pierre-Yves Chibon |
a27356 |
commit.commit_time).strftime('%b %d %Y %H:%M:%S +0000'),
|
|
Pierre-Yves Chibon |
a27356 |
'subject': subject,
|
|
Pierre-Yves Chibon |
a27356 |
'msg': message,
|
|
Pierre-Yves Chibon |
a27356 |
'patch': diff.patch,
|
|
Pierre-Yves Chibon |
a27356 |
}
|
|
Pierre-Yves Chibon |
a27356 |
)
|
|
Pierre-Yves Chibon |
a27356 |
return patch
|
|
Pierre-Yves Chibon |
459834 |
|
|
Pierre-Yves Chibon |
459834 |
|
|
Pierre-Yves Chibon |
40699d |
def write_gitolite_acls(session, configfile):
|
|
Pierre-Yves Chibon |
459834 |
''' Generate the configuration file for gitolite for all projects
|
|
Pierre-Yves Chibon |
459834 |
on the forge.
|
|
Pierre-Yves Chibon |
459834 |
'''
|
|
Pierre-Yves Chibon |
459834 |
config = []
|
|
Pierre-Yves Chibon |
459834 |
for project in session.query(model.Project).all():
|
|
Pierre-Yves Chibon |
459834 |
if project.parent_id:
|
|
Pierre-Yves Chibon |
459834 |
config.append('repo forks/%s' % project.fullname)
|
|
Pierre-Yves Chibon |
459834 |
else:
|
|
Pierre-Yves Chibon |
459834 |
config.append('repo %s' % project.fullname)
|
|
Pierre-Yves Chibon |
459834 |
config.append(' R = @all')
|
|
Pierre-Yves Chibon |
459834 |
config.append(' RW+ = %s' % project.user.user)
|
|
Pierre-Yves Chibon |
459834 |
for user in project.users:
|
|
Pierre-Yves Chibon |
459834 |
if user != project.user:
|
|
Pierre-Yves Chibon |
459834 |
config.append(' RW+ = %s' % user.user.user)
|
|
Pierre-Yves Chibon |
459834 |
config.append('')
|
|
Pierre-Yves Chibon |
459834 |
|
|
Pierre-Yves Chibon |
459834 |
config.append('repo docs/%s' % project.fullname)
|
|
Pierre-Yves Chibon |
459834 |
config.append(' R = @all')
|
|
Pierre-Yves Chibon |
459834 |
config.append(' RW+ = %s' % project.user.user)
|
|
Pierre-Yves Chibon |
459834 |
for user in project.users:
|
|
Pierre-Yves Chibon |
459834 |
if user != project.user:
|
|
Pierre-Yves Chibon |
459834 |
config.append(' RW+ = %s' % user.user.user)
|
|
Pierre-Yves Chibon |
459834 |
config.append('')
|
|
Pierre-Yves Chibon |
459834 |
|
|
Pierre-Yves Chibon |
459834 |
config.append('repo tickets/%s' % project.fullname)
|
|
Pierre-Yves Chibon |
459834 |
config.append(' R = @all')
|
|
Pierre-Yves Chibon |
459834 |
config.append(' RW+ = %s' % project.user.user)
|
|
Pierre-Yves Chibon |
459834 |
for user in project.users:
|
|
Pierre-Yves Chibon |
459834 |
if user != project.user:
|
|
Pierre-Yves Chibon |
459834 |
config.append(' RW+ = %s' % user.user.user)
|
|
Pierre-Yves Chibon |
459834 |
config.append('')
|
|
Pierre-Yves Chibon |
459834 |
|
|
Pierre-Yves Chibon |
459834 |
with open(configfile, 'w') as stream:
|
|
Pierre-Yves Chibon |
459834 |
for row in config:
|
|
Pierre-Yves Chibon |
459834 |
stream.write(row + '\n')
|