diff options
-rw-r--r-- | scripts/build_web_resources.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/scripts/build_web_resources.py b/scripts/build_web_resources.py index 604d9d9..9a4ccec 100644 --- a/scripts/build_web_resources.py +++ b/scripts/build_web_resources.py @@ -17,6 +17,7 @@ import os import traceback import sys import json +import shutil # insert the parent directory, so the problem scripts find their modules sys.path.insert(0, os.sep.join(os.path.dirname(__file__).split(os.sep)[:-1])) @@ -118,6 +119,25 @@ def process_hint_type(hint_type): result[identifier] = hint.hint_type return result +resource_tree = {} # a directory tree where branches are paths and leaves are filenames, it is rooted at the web data directory +def copy_web_resources(package, dst_dir_fragments): + src_path = os.path.join(problems_path, os.sep.join(package.split('.'))) + dst_path = output_path + node = resource_tree + for fragment in dst_dir_fragments: + dst_path = os.path.join(dst_path, fragment) + subnode = node.get(fragment) + if subnode is None: + subnode = {} + node[fragment] = subnode + node = subnode + for filename in os.listdir(src_path): + if not filename.startswith('.') and not filename.endswith('.py'): + full_filename = os.path.join(src_path, filename) + if os.path.isfile(full_filename): + shutil.copy(full_filename, dst_path) + node[filename] = True + cur.execute('select id, name, identifier from language') row = cur.fetchone() while row: @@ -172,6 +192,7 @@ while row: lang_index['groups'] = problem_groups_list lang_index['translations'] = load_translation_data(lang_identifier, language_props) previous_group_id = None + copy_web_resources(lang_identifier, [lang_identifier]) # process problem group data, it all goes into the language directory language.json group_id = row[2] @@ -194,6 +215,7 @@ while row: group_data['problems'] = problems_list group_data['translations'] = load_translation_data(group_package, group_props) problem_groups_list.append(group_data) + copy_web_resources(group_package, [lang_identifier, group_identifier]) # process problem data, from common.py goes into the language directory language.json, others go into problem subdirectory's problem.json problem_id = row[0] @@ -226,7 +248,11 @@ while row: os.mkdir(problem_output_path) with open(os.path.join(problem_output_path, 'problem.json'), 'w') as f: json.dump(problem_data, f, indent=2) + copy_web_resources(problem_package, [lang_identifier, group_identifier, problem_identifier]) finally: row = cur.fetchone() dump_language_defs() # dump the last language index +# dump the tree of resources +with open(os.path.join(output_path, 'resources.json'), 'w') as f: + json.dump(resource_tree, f, indent=2) |