mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 01:16:19 +00:00
scripts: Tool to find the diff to an original settings.py prod template.
This hits the unauthenticated Github API to get the list of tags, which is rate-limited to 60 requests per hour. This means that the tool can only be run 60 times per hour before it starts to exit with errors, but that seems like a reasonable limit for the moment.
This commit is contained in:
committed by
Tim Abbott
parent
a0e18cb06a
commit
4c88da8ed9
@@ -133,6 +133,14 @@ suggest using that updated template to update
|
|||||||
section in `/etc/zulip/settings-new.py` and copy the setting from
|
section in `/etc/zulip/settings-new.py` and copy the setting from
|
||||||
`settings.py` into there.
|
`settings.py` into there.
|
||||||
|
|
||||||
|
The following tool may help, by finding the most likely version of
|
||||||
|
the template that your `/etc/zulip/settings.py` was installed
|
||||||
|
using, and the differences that your file has from that:
|
||||||
|
|
||||||
|
```
|
||||||
|
/home/zulip/deployments/current/scripts/setup/compare-settings-to-template
|
||||||
|
```
|
||||||
|
|
||||||
If there are settings which you cannot find documented in
|
If there are settings which you cannot find documented in
|
||||||
`/etc/zulip/settings-new.py`, check the [changelog][changelog] to see
|
`/etc/zulip/settings-new.py`, check the [changelog][changelog] to see
|
||||||
if they have been removed.
|
if they have been removed.
|
||||||
|
|||||||
62
scripts/setup/compare-settings-to-template
Executable file
62
scripts/setup/compare-settings-to-template
Executable file
@@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import difflib
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
sys.path.append(BASE_DIR)
|
||||||
|
from scripts.lib.setup_path import setup_path
|
||||||
|
|
||||||
|
setup_path()
|
||||||
|
|
||||||
|
|
||||||
|
current_path = "/etc/zulip/settings.py"
|
||||||
|
if len(sys.argv) >= 2:
|
||||||
|
current_path = sys.argv[1]
|
||||||
|
|
||||||
|
print(f"Reading current configuration from {current_path}...")
|
||||||
|
with open(current_path, "r") as f:
|
||||||
|
current_contents = f.read()
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
print("Fetching old versions of setting templates from Github...")
|
||||||
|
templ = {}
|
||||||
|
resp = requests.get("https://api.github.com/repos/zulip/zulip/tags")
|
||||||
|
if resp.status_code != 200:
|
||||||
|
print(resp.content)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for tag in [t["name"] for t in resp.json()]:
|
||||||
|
if re.match(r"^\d+\.\d+(\.\d+)?$", tag):
|
||||||
|
print(f" - {tag}")
|
||||||
|
resp = requests.get(
|
||||||
|
f"https://raw.githubusercontent.com/zulip/zulip/{tag}/zproject/prod_settings_template.py",
|
||||||
|
)
|
||||||
|
if resp.status_code == 200:
|
||||||
|
templ[tag] = resp.content.decode("utf-8")
|
||||||
|
else:
|
||||||
|
print("Failure: ")
|
||||||
|
print(resp)
|
||||||
|
|
||||||
|
print("Computing minimal difference...")
|
||||||
|
sequence_matchers = {}
|
||||||
|
for version, contents in templ.items():
|
||||||
|
sm = difflib.SequenceMatcher(None, current_contents, contents)
|
||||||
|
sequence_matchers[version] = sm
|
||||||
|
|
||||||
|
likely = sorted(sequence_matchers.keys(), key=lambda v: sequence_matchers[v].ratio(), reverse=True)
|
||||||
|
print(f"Most likely version: {likely[0]}")
|
||||||
|
|
||||||
|
|
||||||
|
diff = difflib.unified_diff(
|
||||||
|
templ[likely[0]].splitlines(keepends=True),
|
||||||
|
current_contents.splitlines(keepends=True),
|
||||||
|
fromfile="zulip-server-{version}/zproject/prod_settings_template.py",
|
||||||
|
tofile=current_path,
|
||||||
|
)
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("".join(diff), end="")
|
||||||
Reference in New Issue
Block a user