mirror of https://github.com/zulip/zulip.git
provision: Refactor hashing of compilemessages into a function.
This allows it to be reused for other tools. Edited by tabbott to remove the use of "compilemessages" in variable names.
This commit is contained in:
parent
acd2528038
commit
7b8e79ae48
|
@ -15,7 +15,7 @@ import json
|
|||
import uuid
|
||||
|
||||
if False:
|
||||
from typing import Sequence, Set, Any, Dict
|
||||
from typing import Sequence, Set, Any, Dict, List
|
||||
|
||||
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
||||
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
|
||||
|
@ -312,3 +312,22 @@ def parse_lsb_release():
|
|||
for k, v in data:
|
||||
distro_info[k] = v
|
||||
return distro_info
|
||||
|
||||
def file_hash_updated(paths, hash_name, is_force):
|
||||
# type: (List[str], str, bool) -> bool
|
||||
sha1sum = hashlib.sha1()
|
||||
for path in paths:
|
||||
with open(path, 'rb') as file_to_hash:
|
||||
sha1sum.update(file_to_hash.read())
|
||||
|
||||
hash_path = os.path.join(get_dev_uuid_var_path(), hash_name)
|
||||
new_hash = sha1sum.hexdigest()
|
||||
run(['touch', hash_path])
|
||||
with open(hash_path, 'r') as hash_file:
|
||||
last_hash = hash_file.read()
|
||||
|
||||
if is_force or (new_hash != last_hash):
|
||||
with open(hash_path, 'w') as hash_file:
|
||||
hash_file.write(new_hash)
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -14,7 +14,7 @@ ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__f
|
|||
|
||||
sys.path.append(ZULIP_PATH)
|
||||
from scripts.lib.zulip_tools import run, subprocess_text_output, OKBLUE, ENDC, WARNING, \
|
||||
get_dev_uuid_var_path, FAIL, parse_lsb_release
|
||||
get_dev_uuid_var_path, FAIL, parse_lsb_release, file_hash_updated
|
||||
from scripts.lib.setup_venv import (
|
||||
setup_virtualenv, VENV_DEPENDENCIES, THUMBOR_VENV_DEPENDENCIES
|
||||
)
|
||||
|
@ -360,24 +360,11 @@ def main(options):
|
|||
|
||||
# Consider updating generated translations data: both `.mo`
|
||||
# files and `language-options.json`.
|
||||
sha1sum = hashlib.sha1()
|
||||
paths = ['zerver/management/commands/compilemessages.py']
|
||||
paths += glob.glob('static/locale/*/LC_MESSAGES/*.po')
|
||||
paths += glob.glob('static/locale/*/translations.json')
|
||||
|
||||
for path in paths:
|
||||
with open(path, 'rb') as file_to_hash:
|
||||
sha1sum.update(file_to_hash.read())
|
||||
|
||||
compilemessages_hash_path = os.path.join(UUID_VAR_PATH, "last_compilemessages_hash")
|
||||
new_compilemessages_hash = sha1sum.hexdigest()
|
||||
run(['touch', compilemessages_hash_path])
|
||||
with open(compilemessages_hash_path, 'r') as hash_file:
|
||||
last_compilemessages_hash = hash_file.read()
|
||||
|
||||
if options.is_force or (new_compilemessages_hash != last_compilemessages_hash):
|
||||
with open(compilemessages_hash_path, 'w') as hash_file:
|
||||
hash_file.write(new_compilemessages_hash)
|
||||
if file_hash_updated(paths, "last_compilemessages_hash", options.is_force):
|
||||
run(["./manage.py", "compilemessages"])
|
||||
else:
|
||||
print("No need to run `manage.py compilemessages`.")
|
||||
|
|
Loading…
Reference in New Issue