#! /usr/bin/env python # vim: set fileencoding=utf-8 : import locale import os locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') author = 'Uwe Kleine-König' author_email = 'ukleinek@informatik.uni-freiburg.de' script_sort = r"""#! /usr/bin/env python import locale import re import sys import tempfile locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') re_start = re.compile('P:') re_topic = re.compile('[0-9a-zA-Z][^:]') # F is undefined but used re_field = re.compile('[PMLWTSF]:') re_empty = re.compile('\s*$') prologue = True current_topic = None topic = dict() fixed_maintainers = tempfile.TemporaryFile() for line in open('MAINTAINERS'): if prologue: print >> fixed_maintainers, line, mo = re_start.match(line) if mo: prologue = False continue mo = re_topic.match(line) if mo: current_topic = line if topic.has_key(current_topic): sys.exit(1) topic[current_topic] = list() continue elif current_topic is None: # rest of prologue print >> fixed_maintainers, line, continue assert not current_topic is None mo = re_field.match(line) if mo: topic[current_topic].append(line) else: mo = re_empty.match(line) if not mo: print >> sys.stderr, 'tralala', current_topic, repr(line) sys.exit(1) first = True the_rest = 'THE REST\n' have_the_rest = False # sort case insensitive for t, body in sorted(topic.iteritems(), key=lambda i: i[0].upper()): if t == the_rest: have_the_rest = True continue if first: first = False else: print >> fixed_maintainers print >> fixed_maintainers, t, for line in body: print >> fixed_maintainers, line, if have_the_rest: print >> fixed_maintainers print >> fixed_maintainers, the_rest, for line in topic[the_rest]: print >> fixed_maintainers, line, fixed_maintainers.seek(0) maintainers = open('MAINTAINERS', 'w') for line in fixed_maintainers: print >> maintainers, line, """ script_mergePM = r"""#! /usr/bin/env python import locale import re import sys import tempfile locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') re_person = re.compile('P:(\s*)(.*)') re_mail = re.compile('M:\s*(.*)') fixed_maintainers = tempfile.TemporaryFile() current_person = None current_person_used = False for lineno, line in enumerate(open('MAINTAINERS')): mo = re_person.match(line) if mo: if current_person and not current_person_used: print >> fixed_maintainers, 'P:%s%s' % (current_person_intend, current_person) current_person = mo.group(2) current_person_intend = mo.group(1) current_person_used = False continue mo = re_mail.match(line) if mo: if current_person is None: print 'mail without person at line %d' % (lineno + 1) sys.exit(1) mail = mo.group(1) if mail == 'Mail patches to': mail = 'p.e@rs.on' print >> fixed_maintainers, 'P:%s%s <%s>' % (current_person_intend, current_person, mail) current_person_used = True else: if current_person and not current_person_used: # either there is no mail address or the entry is already correct print >> fixed_maintainers, 'P:%s%s' % (current_person_intend, current_person) current_person = None print >> fixed_maintainers, line, fixed_maintainers.seek(0) maintainers = open('MAINTAINERS', 'w') for line in fixed_maintainers: print >> maintainers, line, """ def tabintend(s): lines = s.split('\n') indented_lines = ('\t%s' % l for l in lines) return '\n'.join(indented_lines) intended_script_sort = tabintend(script_sort) intended_script_mergePM = tabintend(script_mergePM) exec script_sort in dict(globals()) os.system('git commit --author="%(author)s <%(author_email)s>" -a -m "MAINTAINERS: fix alphabetic ordering\n\nThis change was done using the following Python script:\n\n%(intended_script_sort)s\n\nSigned-off-by: %(author)s <%(author_email)s>\n"' % locals()) exec script_mergePM in dict(globals()) os.system('git commit --author="%(author)s <%(author_email)s>" -a -m "MAINTAINERS: merge P and M fields to ease copy\'n\'paste\n\nThis was suggested by Sam Ravnborg and done using the following\nPython script:\n\n%(intended_script_mergePM)s\n\nSigned-off-by: %(author)s <%(author_email)s>\n"' % locals())