Skip to content

Commit

Permalink
ok, let's just duplicate the code then
Browse files Browse the repository at this point in the history
  • Loading branch information
baszoetekouw committed May 27, 2024
1 parent 7b6bb5a commit de5fbcc
Showing 1 changed file with 41 additions and 1 deletion.
1 change: 0 additions & 1 deletion dry_run/ldifparser.py

This file was deleted.

41 changes: 41 additions & 0 deletions dry_run/ldifparser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
import sys
import ldif
from collections import OrderedDict


def kcmp(item):
(key, v) = item
parts = key.split(',')[::-1]
new_key = ','.join(parts)
return (new_key, v)


def freeze(o):
if isinstance(o, dict):
return OrderedDict({k: freeze(v) for k, v in sorted(o.items(), key=kcmp)}.items())
if isinstance(o, list):
return sorted([freeze(v) for v in o])
return o.decode('utf-8')


def my_print(o, depth):
if isinstance(o, OrderedDict):
for k, v in o.items():
my_print(k, depth)
my_print(v, depth + 2)
elif isinstance(o, list):
for v in o:
my_print(v, depth)
else:
print(f"{' ' * depth}{o}")


ldifparser = ldif.LDIFRecordList(sys.stdin)
ldifparser.parse()

data = {k: v for k, v in ldifparser.all_records}
f = freeze(data)

# print(json.dumps(f, indent=2))
my_print(f, 0)

0 comments on commit de5fbcc

Please sign in to comment.