Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 62 lines (53 sloc) 1.989 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#!/usr/bin/env python
from ConfigParser import RawConfigParser
from collections import OrderedDict

GITHUBSECTION = 'repo:collective.github.com'
COMMENT = """\
#
# collective repositories \/
#
# -> below here add new repositories.
# -> place in ALPHABETICAL ORDER.
# -> existing repositories may not have the right owner. This happened at
# import time and set garbas as owner. If you are the owner of such a
# repository, just place your name there.

"""
FOOTER = """\
#
# DO NOT JUST APPEND NEW REPOSITORIES, PUT 'EM IN ALPHABETICAL ORDER
# thanks, this avoids merge conflicts and saves administration time.
#
"""

def write(self, fp):
    """Write an .ini-format representation of the configuration state."""
    # base code stolen from ConfigParser
    for section in self._sections:
        fp.write("[%s]\n" % section)
        for (key, value) in self._sections[section].items():
            if key == "__name__":
                continue
            if (value is not None) or (self._optcre == self.OPTCRE):
                key = " = ".join((key, str(value).replace('\n', '\n ')))
            key = key.replace('= \n', '=\n')
            fp.write("%s\n" % (key))
        fp.write("\n")
        if section == GITHUBSECTION:
           fp.write(COMMENT)


config = RawConfigParser()
config.read('permissions.cfg')
newconfig = RawConfigParser()

for key, value in config._sections.iteritems():
    if not key.startswith('team:'):
        continue
    members = value['members'].split('\n')
    value['members'] = '\n'.join(sorted(members, key=str.lower))
    newconfig._sections[key] = value

newconfig._sections[GITHUBSECTION] = config._sections[GITHUBSECTION]

for key, value in sorted(config._sections.iteritems(),
                         key=lambda x: x[0].lower()):
    if key.startswith('team:') or key == GITHUBSECTION:
        continue
    newconfig._sections[key] = value

with open('permissions.cfg', 'w') as pcfg:
    write(newconfig, pcfg)
    pcfg.write(FOOTER)
Something went wrong with that request. Please try again.