diff --git a/Makefile b/Makefile index c07be6e..63b0e15 100644 --- a/Makefile +++ b/Makefile @@ -38,4 +38,4 @@ pull_translations: $(DOCKER_RUN) python xblocks/xblocks_i18n.py make chown find edx-platform/xblocks/repos/ -maxdepth 1 -mindepth 1 -type d \ - -exec bash -c 'cd {} && git push --set-upstream local $(shell rev-parse --abbrev-ref HEAD)' \; + -exec bash -c 'cd {} && git push --set-upstream local $(shell git rev-parse --abbrev-ref HEAD)' \; diff --git a/edx-platform/xblocks/config.json b/edx-platform/xblocks/config.json new file mode 100644 index 0000000..80fc8a5 --- /dev/null +++ b/edx-platform/xblocks/config.json @@ -0,0 +1,84 @@ +{ + "xblocks": [ + { + "name": "poll", + "upstream_repo": "https://github.com/open-craft/xblock-poll.git", + "local_repo": "git@github.com:appsembler/xblock-poll.git", + "requirements_script": "make requirements", + "push_script": "make push_translations", + "pull_script": "make pull_translations" + }, + { + "name": "drag-and-drop-v2", + "upstream_repo": "https://github.com/edx-solutions/xblock-drag-and-drop-v2.git", + "local_repo": "git@github.com:appsembler/xblock-drag-and-drop-v2.git", + "requirements_script": "pip install -r requirements.txt", + "push_script": "make extract_translations && make push_translations", + "pull_script": "make pull_translations && make compile_translations" + }, + { + "name": "free-text-response", + "upstream_repo": "https://github.com/Stanford-Online/xblock-free-text-response.git", + "local_repo": "git@github.com:OmarIthawi/xblock-free-text-response.git", + "requirements_script": "make requirements", + "push_script": "make push_translations", + "pull_script": "make pull_translations" + }, + { + "name": "done", + "upstream_repo": "https://github.com/pmitros/DoneXBlock.git", + "local_repo": "git@github.com:pmitros/DoneXBlock.git", + "requirements_script": "make requirements", + "push_script": "make push_translations", + "pull_script": "make pull_translations" + }, + { + "name": "lti-consumer", + "upstream_repo": "https://github.com/edx/xblock-lti-consumer.git", + "local_repo": "git@github.com:appsembler/xblock-lti-consumer.git", + "requirements_script": "make install", + "push_script": "echo 'Not supported' && false", + "pull_script": "tx pull -f --mode=reviewed -l en,ar,es_419,fr,fr_CA,he,hi,ko_KR,pt_BR,ru,zh_CN,ja_JP" + }, + { + "name": "google-drive", + "upstream_repo": "https://github.com/edx-solutions/xblock-google-drive.git", + "local_repo": "git@github.com:appsembler/xblock-google-drive.git", + "requirements_script": "make requirements", + "push_script": "make push_translations", + "pull_script": "make pull_translations" + }, + { + "name": "pdf", + "upstream_repo": "https://github.com/appsembler/pdfXBlock.git", + "local_repo": "git@github.com:appsembler/pdfXBlock.git", + "requirements_script": "make requirements", + "push_script": "make push_translations", + "pull_script": "make pull_translations" + }, + { + "name": "ubcpi", + "upstream_repo": "https://github.com/ubc/ubcpi.git", + "local_repo": "git@github.com:appsembler/ubcpi.git", + "requirements_script": "make deps", + "push_script": "make extract && tx push -s", + "pull_script": "tx pull -f --mode=reviewed -l en,ar,es_419,fr,fr_CA,he,hi,ko_KR,pt_BR,ru,zh_CN,ja_JP && make compile" + }, + { + "name": "problem-builder", + "upstream_repo": "https://github.com/open-craft/problem-builder.git", + "local_repo": "git@github.com:appsembler/problem-builder.git", + "requirements_script": "pip install -r requirements.txt && pip install -r requirements-dev.txt", + "push_script": "make extract_translations && make push_translations", + "pull_script": "make pull_translations && make compile_translations" + }, + { + "name": "ora2", + "upstream_repo": "https://github.com/edx/edx-ora2.git", + "local_repo": "git@github.com:appsembler/edx-ora2.git", + "requirements_script": "make install", + "push_script": "make extract_translations && make push_translations", + "pull_script": "tx pull -f --mode=reviewed -l en,ar,es_419,fr,fr_CA,he,hi,ko_KR,pt_BR,ru,zh_CN,ja_JP --minimum-perc=1 && make compile_translations" + } + ] +} \ No newline at end of file diff --git a/edx-platform/xblocks/config.yaml b/edx-platform/xblocks/config.yaml deleted file mode 100644 index 99bc061..0000000 --- a/edx-platform/xblocks/config.yaml +++ /dev/null @@ -1,21 +0,0 @@ -xblocks: - - name: xblock-poll - upstream_repo: https://github.com/open-craft/xblock-poll.git - local_repo: git@github.com:appsembler/xblock-poll.git - requirements_script: | - make requirements - push_script: | - make push_translations - pull_script: | - make pull_translations - - - name: xblock-drag-and-drop-v2 - upstream_repo: https://github.com/edx-solutions/xblock-drag-and-drop-v2.git - local_repo: git@github.com:appsembler/xblock-drag-and-drop-v2.git - requirements_script: | - pip install -r requirements.txt - push_script: | - make extract_translations - make push_translations - pull_script: | - make pull_translations diff --git a/edx-platform/xblocks/xblocks_i18n.py b/edx-platform/xblocks/xblocks_i18n.py index 89592db..2ed1376 100644 --- a/edx-platform/xblocks/xblocks_i18n.py +++ b/edx-platform/xblocks/xblocks_i18n.py @@ -1,18 +1,34 @@ """ Push and pull the latest sources of XBlocks to Transifex in batch. """ -from __future__ import print_function, unicode_literals +from __future__ import print_function -from yaml import safe_load -from subprocess import check_call -from os import path +from json import load +from subprocess import CalledProcessError, STDOUT, check_call +from os import getenv, path, walk +from os.path import join, relpath import time XBLOCKS_DIR = path.dirname(__file__) + +def print_prob_files(root): + for parent, dirs, files in walk(root): + for f in files: + if f.endswith('.prob'): + file_path = relpath(join(parent, f), root) + with open(file_path) as file_obj: + print('=====', file_path, '=====') + print(file_obj.read()) + + +def execute(cmd, **kwargs): + check_call(cmd, stderr=STDOUT, **kwargs) + + def xblock_configs(): - with open(path.join(XBLOCKS_DIR, 'config.yaml'), 'r') as config_file: - config = safe_load(config_file) + with open(path.join(XBLOCKS_DIR, 'config.json'), 'r') as config_file: + config = load(config_file) for xblock in config['xblocks']: yield xblock @@ -20,23 +36,32 @@ def xblock_configs(): def pull_translations(): for config in xblock_configs(): + only = getenv('XBLOCK_NAME') + if only and only != config['name']: + continue + repos_dir = path.join(XBLOCKS_DIR, 'repos') repo_dir = path.join(repos_dir, config['name']) branch = 'i18n-bot/{time}'.format(time=time.strftime('%Y-%m-%d-%H%M%S')) + execute(['git', 'clone', config['upstream_repo'], config['name']], cwd=repos_dir) + # execute(['git', 'clone', config['upstream_repo'], config['name']], cwd=repos_dir) + execute(['git', 'remote', 'add', 'local', config['local_repo']], cwd=repo_dir) + execute(['git', 'checkout', '-b', branch, 'master'], cwd=repo_dir) + execute(config['requirements_script'], shell=True, cwd=repo_dir) - check_call(['git', 'clone', config['upstream_repo'], config['name']], cwd=repos_dir) - check_call(['git', 'remote', 'add', 'local', config['local_repo']], cwd=repo_dir) - check_call(['git', 'checkout', '-b', branch, 'master'], cwd=repo_dir) - - check_call(config['requirements_script'], shell=True, cwd=repo_dir) - check_call(config['pull_script'], shell=True, cwd=repo_dir) - - check_call(['git', 'config', 'user.name', 'Open edX i18n Bot'], cwd=repo_dir) - check_call(['git', 'config', 'user.email', 'bot-i18n@openedx.org'], cwd=repo_dir) + try: + execute(config['pull_script'], shell=True, cwd=repo_dir) + except CalledProcessError as e: + print('Errors in pulling "{xblock}" resources from Transifex'.format(xblock=config['name'])) + print_prob_files(repo_dir) + raise - check_call(['git', 'add', '--all'], cwd=repo_dir) - check_call(['git', 'commit', '-m', 'Update translations (autogenerated message)'], cwd=repo_dir) + execute(['git', 'config', 'user.name', 'Omar Al-Ithawi'], cwd=repo_dir) + execute(['git', 'config', 'user.email', 'i@omardo.com'], cwd=repo_dir) + execute("git add $(git status --porcelain --untracked-files=all | " + "grep -e '\\.po' -e '\\.mo$' -e '\\.js$' | cut -c4-)", shell=True, cwd=repo_dir) + execute(['git', 'commit', '-m', 'Update translations (autogenerated message)'], cwd=repo_dir) if __name__ == '__main__':