LEFT | RIGHT |
1 import os | 1 import os |
2 | 2 |
3 from flask import Flask, send_from_directory, jsonify, request | 3 from flask import Flask, send_from_directory, jsonify, request |
4 | 4 |
5 app = Flask('mock_api') | 5 app = Flask('mock_api') |
6 | 6 |
7 | 7 |
8 def load(rootdir, zipdir): | 8 def load(rootdir, zipdir): |
9 app.request_log = [] | 9 app.request_log = [] |
10 app.config['zipdir'] = zipdir | 10 app.config['zipdir'] = zipdir |
11 app.config['info'] = {'files': [], 'languages': []} | 11 app.config['info'] = {'files': [], 'languages': []} |
12 app.config['supported_languages'] = [] | 12 app.config['supported_languages'] = [] |
13 | 13 |
14 for root, locales, files in os.walk(rootdir): | 14 for root, locales, files in os.walk(rootdir): |
15 for locale in locales: | 15 for locale in locales: |
16 files = [] | 16 files = [] |
17 app.config['supported_languages'].append({'crowdin_code': locale}) | 17 app.config['supported_languages'].append({'crowdin_code': locale}) |
18 app.config['info']['languages'].append( | 18 app.config['info']['languages'].append({ |
19 {'code': locale, | 19 'code': locale, |
20 'can_translate': 1, | 20 'can_translate': 1, |
21 'can_approve': 1 | 21 'can_approve': 1, |
22 }) | 22 }) |
23 | 23 |
24 for translations in os.listdir(os.path.join(root, locale)): | 24 for translations in os.listdir(os.path.join(root, locale)): |
25 files.append({'name': translations, 'node_type': 'file'}) | 25 files.append({'name': translations, 'node_type': 'file'}) |
26 | 26 |
27 app.config['info']['files'].append({'name': locale, | 27 app.config['info']['files'].append({ |
28 'files': files, | 28 'name': locale, |
29 'node_type': 'directory' | 29 'files': files, |
30 }) | 30 'node_type': 'directory', |
| 31 }) |
| 32 |
31 return app | 33 return app |
32 | 34 |
33 | 35 |
34 @app.before_request | 36 @app.before_request |
35 def log_request_info(): | 37 def log_request_info(): |
36 app.request_log.append((request.url, str(request.get_data()))) | 38 app.request_log.append((request.url, str(request.get_data()))) |
37 | 39 |
38 | 40 |
39 @app.route('/api/project/test/info', methods=['GET']) | 41 @app.route('/api/project/test/info', methods=['GET']) |
40 def info(): | 42 def info(): |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 75 |
74 | 76 |
75 @app.route('/api/project/test/export', methods=['GET']) | 77 @app.route('/api/project/test/export', methods=['GET']) |
76 def export(): | 78 def export(): |
77 return jsonify({'success': {'status': 'skipped'}}) | 79 return jsonify({'success': {'status': 'skipped'}}) |
78 | 80 |
79 | 81 |
80 @app.route('/api/project/test/download/all.zip', methods=['GET']) | 82 @app.route('/api/project/test/download/all.zip', methods=['GET']) |
81 def get_zip(): | 83 def get_zip(): |
82 return send_from_directory(app.config['zipdir'], 'all.zip') | 84 return send_from_directory(app.config['zipdir'], 'all.zip') |
LEFT | RIGHT |