Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support lists of categories #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions src/dbetto/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,38 @@
entries = {}
for props in PropsStream.get(file_name):
timestamp = props["valid_from"]
system = "all" if props.get("category") is None else props["category"]
system = props.get("category", "all")
if not isinstance(system, list):
system = [system]
file_key = props["apply"]
if system not in entries:
entries[system] = []
mode = "append" if props.get("mode") is None else props["mode"]
mode = "reset" if len(entries[system]) == 0 else mode
if mode == "reset":
new = file_key
elif mode == "append":
new = entries[system][-1].file.copy() + file_key
elif mode == "remove":
new = entries[system][-1].file.copy()
for file in file_key:
new.remove(file)
elif mode == "replace":
new = entries[system][-1].file.copy()
if len(file_key) != 2:
msg = f"Invalid number of elements in replace mode: {len(file_key)}"
for syst in system:
if syst not in entries:
entries[syst] = []
mode = props.get("mode", "append")
mode = "reset" if len(entries[syst]) == 0 else mode
if mode == "reset":
new = file_key
elif mode == "append":
new = entries[syst][-1].file.copy() + file_key
elif mode == "remove":
new = entries[syst][-1].file.copy()
for file in file_key:
new.remove(file)
elif mode == "replace":
new = entries[syst][-1].file.copy()
if len(file_key) != 2:
msg = f"Invalid number of elements in replace mode: {len(file_key)}"
raise ValueError(msg)

Check warning on line 100 in src/dbetto/catalog.py

View check run for this annotation

Codecov / codecov/patch

src/dbetto/catalog.py#L99-L100

Added lines #L99 - L100 were not covered by tests
new.remove(file_key[0])
new += [file_key[1]]
else:
msg = f"Unknown mode for {timestamp}"

Check warning on line 104 in src/dbetto/catalog.py

View check run for this annotation

Codecov / codecov/patch

src/dbetto/catalog.py#L104

Added line #L104 was not covered by tests
raise ValueError(msg)
new.remove(file_key[0])
new += [file_key[1]]

else:
msg = f"Unknown mode for {timestamp}"
raise ValueError(msg)

if timestamp in [entry.valid_from for entry in entries[system]]:
msg = f"Duplicate timestamp: {timestamp}, use reset mode instead with a single entry"
raise ValueError(msg)
entries[system].append(Catalog.Entry(time.unix_time(timestamp), new))
if timestamp in [entry.valid_from for entry in entries[syst]]:
msg = f"Duplicate timestamp: {timestamp}, use reset mode instead with a single entry"
raise ValueError(msg)

Check warning on line 109 in src/dbetto/catalog.py

View check run for this annotation

Codecov / codecov/patch

src/dbetto/catalog.py#L108-L109

Added lines #L108 - L109 were not covered by tests
entries[syst].append(Catalog.Entry(time.unix_time(timestamp), new))

for system, value in entries.items():
entries[system] = sorted(value, key=lambda entry: entry.valid_from)
Expand Down
Loading