Skip to content

Commit

Permalink
provision: Avoid spending ~1s on compilemessages in no-op provisions
Browse files Browse the repository at this point in the history
Fixes #5185
  • Loading branch information
sinwar committed Jun 20, 2017
1 parent 0e8f1f4 commit e146915
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tools/lib/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import argparse
import platform
import subprocess
import glob
import hashlib

os.environ["PYTHONUNBUFFERED"] = "y"

Expand Down Expand Up @@ -262,7 +264,27 @@ def main(options):
else:
print("No need to regenerate the test DB.")

run(["./manage.py", "compilemessages"])
# Check if translation files have been modified or not
sha1sum = hashlib.sha1()
paths = glob.glob('static/locale/*/LC_MESSAGES/*.po')
paths += glob.glob('static/locale/*/translations.json')

from django.utils.encoding import force_bytes

for path in paths:
sha1sum.update(force_bytes(open(path, 'r').read()))
sha1sum.update(force_bytes(open('zerver/management/commands/compilemessages.py', 'r').read()))

new_compilemessages_hash = sha1sum.hexdigest()
run(['touch', 'var/last_compilemessages_hash'])
hash_file = open('var/last_compilemessages_hash', 'r+')
last_compilemessages_hash = hash_file.read()

if (new_compilemessages_hash != last_compilemessages_hash):
hash_file.write(new_compilemessages_hash)
run(["./manage.py", "compilemessages"])
else:
print("No need to run compilemessage.")

# Here we install nvm, node, and npm.
run(["sudo", "scripts/lib/install-node"])
Expand Down

0 comments on commit e146915

Please sign in to comment.