Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

(WIP) Add more XBlocks #6

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)' \;
84 changes: 84 additions & 0 deletions edx-platform/xblocks/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
21 changes: 0 additions & 21 deletions edx-platform/xblocks/config.yaml

This file was deleted.

59 changes: 42 additions & 17 deletions edx-platform/xblocks/xblocks_i18n.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,67 @@
"""
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


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__':
Expand Down