8000 [pull] master from nwithan8:master by pull[bot] · Pull Request #85 · Yoruio/tauticord · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[pull] master from nwithan8:master #85

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

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
49 changes: 26 additions & 23 deletions migrations/m003_add_recently_added_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def path_ends_in_empty(yaml_data, path: list[str]) -> bool:
if value_at_path is None:
return False

return value_at_path is [] or value_at_path == {}
return value_at_path == [] or value_at_path == {}


class ConfigWriter:
Expand Down Expand Up @@ -118,35 +118,39 @@ def recently_added_libraries_config_section_exists(self, file_path: str) -> bool
with open(file_path, 'r') as f:
data = yaml.safe_load(f)

path = ["Stats", "Libraries", "Libraries"]

# If the Libraries section doesn't exist, that's an error that should be raised
if not path_exists_in_yaml(yaml_data=data, path=path):
path_string = " -> ".join(path)
raise Exception(f"Missing {path_string} section in config file")

# If the Libraries section is empty, that's fine
paths = [
["Stats", "Libraries", "Libraries"],
]
if all([path_ends_in_empty(yaml_data=data, path=path) for path in paths]):
if path_ends_in_empty(yaml_data=data, path=path):
return True

# Otherwise, confirm that the RecentlyAdded section is already in the config
paths = [
["Stats", "Libraries", "Libraries", [], "RecentlyAdded", "Enable"],
]
return all([path_exists_in_yaml(yaml_data=data, path=path) for path in paths])
path = ["Stats", "Libraries", "Libraries", [], "RecentlyAdded", "Enable"]
return path_exists_in_yaml(yaml_data=data, path=path)

def recently_added_combined_libraries_config_section_exists(self, file_path: str) -> bool:
with open(file_path, 'r') as f:
data = yaml.safe_load(f)

path = ["Stats", "Libraries", "CombinedLibraries"]

# If the CombinedLibraries section doesn't exist, that's an error that should be raised
if not path_exists_in_yaml(yaml_data=data, path=path):
path_string = " -> ".join(path)
raise Exception(f"Missing {path_string} section in config file")

# If the CombinedLibraries section is empty, that's fine
paths = [
["Stats", "Libraries", "CombinedLibraries"],
]
if all([path_ends_in_empty(yaml_data=data, path=path) for path in paths]):
if path_ends_in_empty(yaml_data=data, path=path):
return True

# Otherwise, confirm that the RecentlyAdded section is already in the config
paths = [
["Stats", "Libraries", "CombinedLibraries", [], "RecentlyAdded", "Enable"],
]
return all([path_exists_in_yaml(yaml_data=data, path=path) for path in paths])
path = ["Stats", "Libraries", "CombinedLibraries", [], "RecentlyAdded", "Enable"]
return path_exists_in_yaml(yaml_data=data, path=path)

def pre_forward_check(self) -> bool:
# Check if the old config file exists
Expand Down Expand Up @@ -177,10 +181,8 @@ def forward(self):
path=["Stats", "Libraries",
"CombinedLibraries"])

# By this point, we know thanks to pre-checks that stat_libraries and stat_combined_libraries exist
# and have some or all elements that don't have the "RecentlyAdded" section

for i, _ in enumerate(stat_libraries):
# Need to add the RecentlyAdded section to each library in the Libraries section
for i, _ in enumerate(stat_libraries or []): # Will iterate 0 times if stat_libraries is None
new_config.add(value={
"CustomName": "",
"CustomEmoji": "",
Expand All @@ -189,8 +191,9 @@ def forward(self):
"Hours": 24,
},
key_path=["Stats", "Libraries", "Libraries", i, "RecentlyAdded"])

for i, _ in enumerate(stat_combined_libraries):
# Need to add the RecentlyAdded section to each library in the CombinedLibraries section
for i, _ in enumerate(
stat_combined_libraries or []): # Will iterate 0 times if stat_combined_libraries is None
new_config.add(value={
"CustomName": "",
"CustomEmoji": "",
Expand Down
Loading
0