mirror of
https://github.com/zen-browser/theme-store.git
synced 2025-07-08 01:10:01 +02:00
Merge 57cf2f9dde
into 856819918b
This commit is contained in:
commit
3dd2eb7d31
1 changed files with 22 additions and 22 deletions
|
@ -3,48 +3,48 @@ import time
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def panic(message: str):
|
def panic(message: str):
|
||||||
print(message, file=sys.stderr)
|
print(message, file=sys.stderr)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def update_theme_date(theme_path):
|
def update_theme_date(theme_path):
|
||||||
theme_file = os.path.join(theme_path, "theme.json")
|
theme_file = os.path.join(theme_path, "theme.json")
|
||||||
|
|
||||||
if not os.path.exists(theme_file):
|
if not os.path.exists(theme_file):
|
||||||
panic(f"{theme_file} not found.")
|
panic(f"{theme_file} not found.")
|
||||||
|
|
||||||
# Load the theme JSON data
|
# Load the theme JSON data with single file operation
|
||||||
with open(theme_file, "r") as f:
|
try:
|
||||||
try:
|
with open(theme_file, "r") as f:
|
||||||
theme_data = json.load(f)
|
theme_data = json.load(f)
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
panic("Error reading theme.json: " + str(e))
|
panic("Error reading theme.json: " + str(e))
|
||||||
|
|
||||||
# Get the current date
|
# Get the current date once and reuse
|
||||||
current_date = time.strftime("%Y-%m-%d")
|
current_date = time.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
# Set `createdAt` to the current date if it doesn't exist
|
# Combine checks and updates for efficiency
|
||||||
|
updates_made = False
|
||||||
if "createdAt" not in theme_data:
|
if "createdAt" not in theme_data:
|
||||||
theme_data["createdAt"] = current_date
|
theme_data["createdAt"] = current_date
|
||||||
print(f"Set `createdAt` for {theme_path} to {theme_data['createdAt']}")
|
print(f"Set `createdAt` for {theme_path} to {theme_data['createdAt']}")
|
||||||
|
updates_made = True
|
||||||
|
|
||||||
# Update the `updatedAt` field to the current date
|
if theme_data.get("updatedAt") != current_date:
|
||||||
theme_data["updatedAt"] = current_date
|
theme_data["updatedAt"] = current_date
|
||||||
print(f"Updated `updatedAt` for {theme_path} to {theme_data['updatedAt']}")
|
print(f"Updated `updatedAt` for {theme_path} to {theme_data['updatedAt']}")
|
||||||
|
updates_made = True
|
||||||
|
|
||||||
# Add `tags` as an empty list if it doesn't exist
|
|
||||||
if "tags" not in theme_data:
|
if "tags" not in theme_data:
|
||||||
theme_data["tags"] = []
|
theme_data["tags"] = []
|
||||||
print(f"Initialized `tags` for {theme_path} as an empty list")
|
print(f"Initialized `tags` for {theme_path} as an empty list")
|
||||||
|
updates_made = True
|
||||||
|
|
||||||
# Write the changes back to theme.json
|
# Write changes only if modifications were made
|
||||||
with open(theme_file, "w") as f:
|
if updates_made:
|
||||||
json.dump(theme_data, f, indent=4)
|
with open(theme_file, "w") as f:
|
||||||
|
json.dump(theme_data, f, indent=4)
|
||||||
print(f"Updated `updatedAt` for {theme_path} to {theme_data['updatedAt']}")
|
print(f"Updated `updatedAt` for {theme_path} to {theme_data['updatedAt']}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Make sure the script is run with the theme path as an argument
|
# Make sure the script is run with the theme path as an argument
|
||||||
|
@ -52,4 +52,4 @@ if __name__ == "__main__":
|
||||||
panic("Usage: update_theme_date.py <path_to_theme_directory>")
|
panic("Usage: update_theme_date.py <path_to_theme_directory>")
|
||||||
|
|
||||||
theme_path = sys.argv[1]
|
theme_path = sys.argv[1]
|
||||||
update_theme_date(theme_path)
|
update_theme_date(theme_path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue