Initial import

This commit is contained in:
3wc 2024-02-15 19:53:09 -03:00
commit f7a88cd6cb

47
mailmansettings.py Normal file
View File

@ -0,0 +1,47 @@
import argparse
import json
import sys
from bs4 import BeautifulSoup
from mailman.utilities.importer import NAME_MAPPINGS
parser = argparse.ArgumentParser(
prog=sys.argv[0], description="Munge Mailman config data"
)
parser.add_argument("file", type=argparse.FileType('r', encoding='utf-8'))
args = parser.parse_args()
data_clean = {}
soup = BeautifulSoup(args.file.read(), 'html.parser')
for field in soup.find_all('textarea'):
name = NAME_MAPPINGS.get(field['name'], field['name'])
if 'msg' in name:
continue
data_clean[name] = [l for l in field.get_text().split('\n') if l != ""]
for field in soup.find_all('input'):
if field['type'] == 'hidden':
continue
if field['type'] == 'RADIO':
if 'checked' not in field.attrs:
continue
name = NAME_MAPPINGS.get(field['name'], field['name'])
if 'msg' in name:
continue
try:
data_clean[name] = field['value']
except KeyError:
data_clean[name] = ""
print(json.dumps(data_clean))