-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate update_assets and compile_locales to python scripts + add syn…
…c_host_files.py script to run tasks before starting containers
- Loading branch information
Showing
7 changed files
with
142 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import subprocess | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
|
||
def process_po_file(pofile, attempt=0): | ||
"""Process a single .po file, creating corresponding .mo file.""" | ||
print('processing', pofile) | ||
directory = os.path.dirname(pofile) | ||
stem = os.path.splitext(os.path.basename(pofile))[0] | ||
mo_path = os.path.join(directory, f'{stem}.mo') | ||
|
||
# Touch the .mo file | ||
open(mo_path, 'a').close() | ||
|
||
try: | ||
# Run dennis-cmd lint | ||
subprocess.run( | ||
['dennis-cmd', 'lint', '--errorsonly', pofile], | ||
capture_output=True, | ||
check=False, | ||
) | ||
# If lint passes, run msgfmt | ||
subprocess.run(['msgfmt', '-o', mo_path, pofile], check=True) | ||
return | ||
except subprocess.CalledProcessError as e: | ||
if attempt < 3: | ||
print(f'Failed attempt {attempt} for {pofile}, retrying...') | ||
return process_po_file(pofile, attempt=attempt + 1) | ||
raise e | ||
|
||
|
||
def main(): | ||
# Ensure 'dennis' is installed | ||
try: | ||
import dennis as _ | ||
except ImportError: | ||
print( | ||
'Error: dennis is not installed. Please install it with pip install dennis' | ||
) | ||
exit(1) | ||
|
||
locale_dir = os.path.abspath( | ||
os.path.join( | ||
os.path.dirname(__file__), | ||
'..', | ||
'locale', | ||
) | ||
) | ||
|
||
print(f'Compiling locales in {locale_dir}') | ||
|
||
# Collect all files first | ||
django_files = [] | ||
djangojs_files = [] | ||
for root, _, files in os.walk(locale_dir): | ||
for file in files: | ||
if file == 'django.po': | ||
django_files.append(os.path.join(root, file)) | ||
elif file == 'djangojs.po': | ||
djangojs_files.append(os.path.join(root, file)) | ||
|
||
# Process django.po files in parallel | ||
with ThreadPoolExecutor() as executor: | ||
executor.map(process_po_file, django_files + djangojs_files) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
import os | ||
import shutil | ||
import subprocess | ||
|
||
|
||
def main(): | ||
BUILD_INFO = os.environ.get('BUILD_INFO') | ||
|
||
subprocess.run(['make', 'update_deps'], check=True) | ||
|
||
HOME = os.environ.get('HOME') | ||
|
||
for dir in ['static-build', 'site-static']: | ||
path = os.path.join(HOME, dir) | ||
if os.path.exists(path): | ||
shutil.rmtree(path) | ||
os.makedirs(path, exist_ok=True) | ||
|
||
with open(BUILD_INFO, 'r') as f: | ||
build_info = json.load(f) | ||
|
||
if build_info.get('target') == 'production': | ||
subprocess.run(['make', 'compile_locales'], check=True) | ||
subprocess.run(['make', 'update_assets'], check=True) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import subprocess | ||
|
||
|
||
def main(): | ||
script_prefix = ['python3', 'manage.py'] | ||
|
||
environment = os.environ.copy() | ||
# Always run in production mode without any development settings | ||
environment['DJANGO_SETTINGS_MODULE'] = 'olympia.lib.settings_base' | ||
|
||
subprocess.run( | ||
script_prefix + ['compress_assets'], | ||
check=True, | ||
env=environment, | ||
) | ||
subprocess.run( | ||
script_prefix + ['generate_jsi18n_files'], | ||
check=True, | ||
env=environment, | ||
) | ||
subprocess.run( | ||
script_prefix + ['collectstatic', '--noinput'], | ||
check=True, | ||
env=environment, | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |