|
1 | 1 | import logging |
2 | 2 | import os.path |
3 | | - |
| 3 | +from ruamel.yaml import YAML |
4 | 4 | import requests |
5 | 5 |
|
6 | 6 | from django.core.management.base import BaseCommand |
7 | 7 |
|
8 | 8 | from community.git import get_deploy_url, get_upstream_deploy_url |
| 9 | +from gci.students import cleanse_instances |
| 10 | +from gci.task import cleanse_tasks |
9 | 11 |
|
10 | 12 |
|
11 | 13 | class Command(BaseCommand): |
12 | 14 | help = 'Fetch old data' |
| 15 | + yaml = YAML() |
| 16 | + tasks = {} |
| 17 | + instances = {} |
13 | 18 |
|
14 | 19 | def add_arguments(self, parser): |
15 | 20 | parser.add_argument('output_dir', nargs='?', type=str) |
@@ -55,3 +60,26 @@ def handle(self, *args, **options): |
55 | 60 | filename = os.path.basename(filename) |
56 | 61 | with open(os.path.join(output_dir, filename), 'wb') as f: |
57 | 62 | f.write(r.content) |
| 63 | + |
| 64 | + tokens = { |
| 65 | + 'GH_TOKEN': os.environ.get('GH_TOKEN'), |
| 66 | + 'GL_TOKEN': os.environ.get('GL_TOKEN') |
| 67 | + } |
| 68 | + |
| 69 | + if filename == 'tasks.yaml': |
| 70 | + tasks = self.get_data(output_dir, filename) |
| 71 | + self.tasks = cleanse_tasks(tasks, tokens) |
| 72 | + self.put_data(output_dir, filename, self.tasks) |
| 73 | + |
| 74 | + if filename == 'instances.yaml': |
| 75 | + instances = self.get_data(output_dir, filename) |
| 76 | + self.instances = cleanse_instances(instances, self.tasks) |
| 77 | + self.put_data(output_dir, filename, self.instances) |
| 78 | + |
| 79 | + def get_data(self, output_dir, filename): |
| 80 | + with open(os.path.join(output_dir, filename), 'r') as f: |
| 81 | + return self.yaml.load(f) |
| 82 | + |
| 83 | + def put_data(self, output_dir, filename, data): |
| 84 | + with open(os.path.join(output_dir, filename), 'w') as f: |
| 85 | + self.yaml.dump(data, f) |
0 commit comments