Project

General

Profile

Demande #552 » synthese.py

Script qui parse la configuration des listes de Sympa et en fait la synthèse en csv. - François Poulain, 06/07/2011 07:36 PM

 
import re, csv

dir_list = ['april.org/accessibilite', 'april.org/admins', 'april.org/admins-auto', 'april.org/ag2008', 'april.org/ag2009', 'april.org/ag2010', 'april.org/all-april', 'april.org/amellie', 'april.org/animation', 'april.org/april', 'april.org/april-actu', 'april.org/atelier', 'april.org/atf', 'april.org/bureau', 'april.org/ca', 'april.org/ca-interne', 'april.org/calendrier', 'april.org/campagne-adhesion', 'april.org/candidatsbe', 'april.org/candidatsbe-pacte', 'april.org/candidatsfr-actu', 'april.org/candidatsfr-locaux', 'april.org/comite-sgl', 'april.org/comm-externe', 'april.org/communique', 'april.org/comptabilite', 'april.org/contact', 'april.org/copinedegeek', 'april.org/copyleft_attitude', 'april.org/cstic', 'april.org/debats', 'april.org/diversite', 'april.org/educ', 'april.org/entreprises', 'april.org/fdi', 'april.org/freesw-eu', 'april.org/gdtc-devel', 'april.org/gte', 'april.org/informatique-deloyale', 'april.org/intervenants-sgl', 'april.org/juridique', 'april.org/libreassociation', 'april.org/liste-infos', 'april.org/liste-infos-moderateurs', 'april.org/mdl', 'april.org/orga', 'april.org/owf-ged', 'april.org/patrimoine-mondial', 'april.org/persmorales', 'april.org/prez', 'april.org/resp-tous', 'april.org/rp', 'april.org/rtfm', 'april.org/secretaire', 'april.org/sensibilisation', 'april.org/sgl', 'april.org/sir', 'april.org/siteweb', 'april.org/synceduc', 'april.org/syncrgi', 'april.org/technique', 'april.org/template', 'april.org/terminologie', 'april.org/trad-gnu', 'april.org/trad-gpl', 'april.org/traductions', 'april.org/transcriptions', 'april.org/tresorier', 'april.org/turing', 'april.org/webmasters', 'april.org/webmasters-auto', 'candidats.fr/candidatsfr', 'candidats.fr/signature-organisation', 'informatiquedeloyale.info/contact', 'libre-en-fete.net/contact-lef', 'libre-en-fete.net/lef']

keyword_list = r'(status|visibility|review|subscribe|add|send|digest|rfc2369_header_fields)'

keyword_detect_multilines = r'(available_user_options|web_archive|reply_to_header)'

keyword_list_multilines = r'(apply|value|other_email|reception|access)'

# Parsing

global configurations, keywords

configurations = {}
keywords = ['mailling_list']

def store(directory, line, master_key = ''):
if master_key == '':
key = line.split()[0]
else:
key = master_key + ':' + line.split()[0]
if key not in keywords: keywords.append(key)
content = line.split()[1:]
configurations[directory][key] = content[0]

for directory in dir_list:

configurations[directory] = {'mailling_list':directory}

config = open(directory + '/config', 'r')

old_line = '\n'
line = '\n'

while line != '':
line = config.readline()

if re.match(keyword_list, line) and old_line == '\n':
store(directory,line)

if re.match(keyword_detect_multilines, line) and old_line == '\n':
master = line.split()[0]
while line != '\n':
line = config.readline()
if re.match(keyword_list_multilines, line):
store(directory, line, master_key = master)

old_line = line

config.close()

# print configurations, keywords

# CSV export

############## DictWriter.writeheader() indisponible pour python < 2.7

out = open('config.csv', 'wb')
for key in keywords:
out.write(key + ',')
out.write('\n')
out.close()

##############

out = open('config.csv', 'a')

data = csv.DictWriter(out,keywords)

for mailling_list in configurations:
data.writerow(configurations[mailling_list])
(1-1/6)