| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
import sys |
| 5 |
import os |
| 6 |
import subprocess |
| 7 |
import re |
| 8 |
|
| 9 |
try: |
| 10 |
import pystache |
| 11 |
except ImportError: |
| 12 |
print( |
| 13 |
''' |
| 14 |
Error: This project requires the pystache Python module in order to finish |
| 15 |
the maintainer setup. Please install it and re-run autocontrib. |
| 16 |
|
| 17 |
The pystache module can be installed using pip: |
| 18 |
|
| 19 |
pip install pystache |
| 20 |
''' |
| 21 |
) |
| 22 |
exit(1) |
| 23 |
|
| 24 |
|
| 25 |
class BlockTemplate(): |
| 26 |
|
| 27 |
def __init__(self): |
| 28 |
self.renderer = pystache.Renderer() |
| 29 |
self.contribs = [] |
| 30 |
self.shortlog = "" |
| 31 |
|
| 32 |
def raw_contributors(self): |
| 33 |
patt = re.compile(r'\d+\s+(.+)\s+<(.+)>') |
| 34 |
matches = patt.findall(self.shortlog) |
| 35 |
for item in matches: |
| 36 |
self.contribs.append({'name': item[0], 'email': item[1]}) |
| 37 |
|
| 38 |
def load_shortlog(self): |
| 39 |
self.shortlog = subprocess.check_output(['git', 'shortlog', '-es'], universal_newlines = True) |
| 40 |
|
| 41 |
def process_contribs(self, tpl_data): |
| 42 |
self.load_shortlog() |
| 43 |
self.raw_contributors() |
| 44 |
return self.renderer.render(tpl_data, { 'contributors' : self.contribs }) |
| 45 |
|
| 46 |
|
| 47 |
def main(): |
| 48 |
tpl_name = sys.argv[-1] |
| 49 |
with open(tpl_name, 'r') as tpl_file: |
| 50 |
tpl_contents = tpl_file.read() |
| 51 |
contribs_tpl = BlockTemplate() |
| 52 |
outfile_name = tpl_name.replace('.mustache','') |
| 53 |
with open(outfile_name, 'w') as outfile: |
| 54 |
outfile.write(contribs_tpl.process_contribs(tpl_contents)) |
| 55 |
|
| 56 |
|
| 57 |
if __name__ == '__main__': |
| 58 |
main() |