|
1 | 1 | """Tasks related to projects, including fetching repository code, cleaning
|
2 | 2 | ``conf.py`` files, and rebuilding documentation.
|
3 |
| -
|
4 | 3 | """
|
5 | 4 | import datetime
|
6 | 5 | import fnmatch
|
|
34 | 33 | make_api_version, make_api_project)
|
35 | 34 | from tastyapi import client as tastyapi_client
|
36 | 35 | from tastyapi import api, apiv2
|
37 |
| -from core.utils import copy_to_app_servers, run_on_app_servers |
| 36 | +from core.utils import (copy_to_app_servers, copy_file_to_app_servers, |
| 37 | + run_on_app_servers) |
38 | 38 |
|
39 | 39 | ghetto_hack = re.compile(
|
40 | 40 | r'(?P<key>.*)\s*=\s*u?\[?[\'\"](?P<value>.*)[\'\"]\]?')
|
@@ -771,6 +771,48 @@ def remove_symlink_single_version(version):
|
771 | 771 | symlink = version.project.single_version_symlink_path()
|
772 | 772 | run_on_app_servers('rm %s' % symlink)
|
773 | 773 |
|
| 774 | +def update_static_metadata(project_pk): |
| 775 | + """Update static metadata JSON file |
| 776 | +
|
| 777 | + Metadata settings include the following project settings: |
| 778 | +
|
| 779 | + version |
| 780 | + The default version for the project, default: `latest` |
| 781 | +
|
| 782 | + language |
| 783 | + The default language for the project, default: `en` |
| 784 | +
|
| 785 | + languages |
| 786 | + List of languages built by linked translation projects. |
| 787 | + """ |
| 788 | + project_base = apiv2.project(project_pk) |
| 789 | + project_data = project_base.get() |
| 790 | + project = make_api_project(project_data) |
| 791 | + translations = project_base.translations.get()['translations'] |
| 792 | + languages = set([ |
| 793 | + translation['language'] |
| 794 | + for translation in translations |
| 795 | + if 'language' in translation |
| 796 | + ]) |
| 797 | + # Convert to JSON safe types |
| 798 | + metadata = { |
| 799 | + 'version': project.default_version, |
| 800 | + 'language': project.language, |
| 801 | + 'languages': list(languages) |
| 802 | + } |
| 803 | + try: |
| 804 | + path = project.static_metadata_path() |
| 805 | + fh = open(path, 'w') |
| 806 | + json.dump(metadata, fh) |
| 807 | + fh.close() |
| 808 | + copy_file_to_app_servers(path, path) |
| 809 | + except IOError as e: |
| 810 | + log.debug(LOG_TEMPLATE.format( |
| 811 | + project=project.slug, |
| 812 | + version='', |
| 813 | + msg='Cannot write to metadata.json: {0}'.format(e) |
| 814 | + )) |
| 815 | + |
774 | 816 | def send_notifications(version, build):
|
775 | 817 | #zenircbot_notification(version.id)
|
776 | 818 | for hook in version.project.webhook_notifications.all():
|
|
0 commit comments