Skip to content

Commit

Permalink
Disable parsing from lines for now if writing CSV/TSV
Browse files Browse the repository at this point in the history
The schema is entirely different, so we cannot put it in a uniform file.
  • Loading branch information
Natureshadow committed Apr 6, 2022
1 parent f9a6cfd commit e7e163c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion maillogger/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ def main() -> None:
loader = Loader(options.source_file)
contents = loader.handle()

parse_to = True
parse_from = True
if options.fmt in ("csv", "tsv"):
parse_from = False

parsed_contents = []
for c in contents:
result = parse(c)
result = parse(c, parse_to, parse_from)
if result:
parsed_contents.append(result)

Expand Down
6 changes: 3 additions & 3 deletions maillogger/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ParseResultType = Dict[str, str]


def parse(target: str) -> Optional[ParseResultType]:
def parse(target: str, parse_to: bool = True, parse_from: bool = True) -> Optional[ParseResultType]:
"""Parse postfix maillog including send status
Args:
Expand Down Expand Up @@ -61,10 +61,10 @@ def parse(target: str) -> Optional[ParseResultType]:
match_from = re.search(PATTERN_FROM, target)
match_to = re.search(PATTERN_TO, target)

if match_from:
if parse_from and match_from:
result = match_from.groupdict()
return ParseResultFrom(**result).to_dict()
if match_to:
if parse_to and match_to:
result = match_to.groupdict()
return ParseResultTo(**result).to_dict()

Expand Down

0 comments on commit e7e163c

Please sign in to comment.