forked from coala/community
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Django command to fetch GCI data
Separates the fetch operation from the load operation, allowing the build on forks to use a cached dataset. Related to coala#3
- Loading branch information
Showing
8 changed files
with
97 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,5 +100,6 @@ ENV/ | |
# mypy | ||
.mypy_cache/ | ||
|
||
/private/ | ||
_site/ | ||
/public/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from collections import OrderedDict | ||
import os.path | ||
|
||
from ruamel.yaml import YAML | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from gci.students import ( | ||
_get_instances, | ||
_get_tasks, | ||
) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Fetch GCI data' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('output_dir', nargs='?', type=str) | ||
|
||
def handle(self, *args, **options): | ||
output_dir = options.get('output_dir') | ||
|
||
tasks = {} | ||
for task in _get_tasks(): | ||
tasks[int(task['id'])] = task | ||
|
||
instances = {} | ||
for instance in _get_instances(): | ||
instances[int(instance['id'])] = instance | ||
|
||
tasks = OrderedDict(sorted(tasks.items(), key=lambda t: t[0])) | ||
instances = OrderedDict(sorted(instances.items(), key=lambda t: t[0])) | ||
|
||
yaml = YAML() | ||
|
||
with open(os.path.join(output_dir, 'tasks.yaml'), 'w') as f: | ||
yaml.dump(tasks, f) | ||
|
||
with open(os.path.join(output_dir, 'instances.yaml'), 'w') as f: | ||
yaml.dump(instances, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .config import load_cache | ||
|
||
_tasks = {} | ||
|
||
|
||
def get_tasks(): | ||
global _tasks | ||
if not _tasks: | ||
_tasks = load_cache('tasks.yaml') | ||
|
||
return _tasks | ||
|
||
|
||
def get_task(task_id): | ||
return get_tasks()[task_id] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ IGitt | |
requests | ||
python-dateutil | ||
pillow | ||
ruamel.yaml |