-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from clarkperkins/feature/formula-cloning
Fix formula cloning
- Loading branch information
Showing
21 changed files
with
650 additions
and
596 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright 2016, Digital Reasoning | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
|
||
class FormulaTaskException(Exception): | ||
pass | ||
|
||
|
||
class InvalidFormula(Exception): | ||
pass | ||
|
||
|
||
class InvalidFormulaComponent(InvalidFormula): | ||
pass |
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
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,53 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.5 on 2016-04-08 18:19 | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
import shutil | ||
from django.conf import settings | ||
from django.db import migrations | ||
from stackdio.api.formulas.tasks import import_formula | ||
|
||
|
||
def fix_formulas_forwards(apps, schema_editor): | ||
Formula = apps.get_model('formulas', 'Formula') | ||
|
||
formula_dir = os.path.join(settings.FILE_STORAGE_DIRECTORY, 'formulas') | ||
|
||
for formula in Formula.objects.all(): | ||
# Delete the old dir | ||
repo_name = os.path.splitext(os.path.split(formula.uri)[-1])[0] | ||
dir_name = '{}-{}'.format(formula.id, repo_name) | ||
shutil.rmtree(os.path.join(formula_dir, dir_name), ignore_errors=True) | ||
|
||
# re-import | ||
import_formula.si(formula.id)() | ||
|
||
|
||
def fix_formulas_reverse(apps, schema_editor): | ||
Formula = apps.get_model('formulas', 'Formula') | ||
|
||
formula_dir = os.path.join(settings.FILE_STORAGE_DIRECTORY, 'formulas') | ||
|
||
for formula in Formula.objects.all(): | ||
repo_name = os.path.splitext(os.path.split(formula.uri)[-1])[0] | ||
dir_name = '{}-{}'.format(formula.id, repo_name) | ||
|
||
new_dir = os.path.join(formula_dir, dir_name) | ||
|
||
# Copy the HEAD over | ||
shutil.move(os.path.join(new_dir, 'checkouts', 'HEAD'), new_dir) | ||
|
||
# Blow away the old checkouts | ||
shutil.rmtree(os.path.join(new_dir, 'checkouts')) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('formulas', '0002_0_8_0_migrations'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(fix_formulas_forwards, fix_formulas_reverse), | ||
] |
Oops, something went wrong.