Projet

Général

Profil

Demande #4566 » remove_owners_and_editors.py

François Poulain, 17/08/2020 19:30

 
1
#!/usr/bin/env python3
2
import glob, re
3

    
4
section = re.compile(r'\s*\n+\s*\n+')
5
owner_editor_section = re.compile(r'^(owner|editor)(\n(visibility|reception|gecos|profile|email) [^\n]+)+$')
6

    
7
def clean_config(config):
8
    sections = section.split(config)
9
    cleaned_sections = [s for s in sections if not owner_editor_section.match(s)]
10
    return '\n\n'.join(cleaned_sections)
11

    
12

    
13
for config_filename in glob.glob('expl/*/*/config'):
14
    print(config_filename)
15
    with open(config_filename, 'r') as f:
16
        config = f.read()
17

    
18
    with open(config_filename, 'w') as f:
19
        f.write(clean_config(config))
(1-1/2)