Skip to content
Snippets Groups Projects
Commit be854eae authored by Guillaume Chanel's avatar Guillaume Chanel
Browse files

First version of repos file generator

parent c61faeeb
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
import argparse
import yaml
import re
import logging
email_regex = re.compile(r'^([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+$')
def is_valid_email(email: str) -> bool:
is_valid = re.fullmatch(email_regex, email) is not None
if not is_valid:
logging.warning(f'"{email.strip()}": is not a valid email -> not added in a group')
return is_valid
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Repos file generator - create the PWM repos file from a list of emails')
parser.add_argument('in_file', type=argparse.FileType('r'), default='-', help='name of the file containing a list of email adresses (- for stdin)')
parser.add_argument('repos_file', type=argparse.FileType('w'), default='repos_file.yml', help='name of the repos file')
# In the case we want to implement input file parsers:
# parser.add_argument('-f', '--field', help='name of the field containing emails if the input as several fields (e.g. CSV)')
args = parser.parse_args()
email_list = [line.strip() for line in args.in_file if is_valid_email(line.strip())] # I do not get why I need to strip for validating email -> the regexp should take care of line return with $
group_list = [{'emails': [email]} for email in email_list]
yaml.safe_dump(group_list, args.repos_file)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment