Bc. Petr Pecha
8 years ago
13 changed files with 299 additions and 50 deletions
@ -0,0 +1,16 @@ |
|||
git hooks |
|||
========= |
|||
|
|||
Kontrola stylu pythoních zdrojáků pomocí flake8. Kontrolujeme jen změny, |
|||
abychom nenutili lidi dělat nesouvisející úpravy, které by rozbíjely historii |
|||
(git blame). |
|||
|
|||
pre-commit |
|||
---------- |
|||
* kontrola změn před commitnutím |
|||
* instalace: lokálně zkopírovat do .git/hooks (musí být spustitelný) |
|||
|
|||
update |
|||
------ |
|||
* kontrola změn přicházejících s pushem |
|||
* instalace: na atreyi zkopírovat do /akce/MaM/MaMweb/mamweb.git/hooks |
@ -0,0 +1,6 @@ |
|||
#!/bin/sh |
|||
# |
|||
# Git hook script to verify what is about to be committed. |
|||
# Checks that the changes don't introduce new flake8 errors. |
|||
|
|||
git diff --unified=1 --cached HEAD -- '*py' | flake8 --diff |
@ -0,0 +1,53 @@ |
|||
#!/bin/sh |
|||
|
|||
# git update hook to check that pushed changes don't introduce new flake8 |
|||
# errors |
|||
|
|||
# --- Command line |
|||
refname="$1" |
|||
oldrev="$2" |
|||
newrev="$3" |
|||
|
|||
# --- Safety check |
|||
if [ -z "$GIT_DIR" ]; then |
|||
echo "Don't run this script from the command line." >&2 |
|||
echo " (if you want, you could supply GIT_DIR then run" >&2 |
|||
echo " $0 <ref> <oldrev> <newrev>)" >&2 |
|||
exit 1 |
|||
fi |
|||
|
|||
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then |
|||
echo "usage: $0 <ref> <oldrev> <newrev>" >&2 |
|||
exit 1 |
|||
fi |
|||
|
|||
|
|||
TMPDIR=`mktemp -d` |
|||
TMPDIFF=`tempfile` |
|||
|
|||
[ $refname != "refs/heads/master" -a $refname != "refs/heads/stable" ] && exit 0 |
|||
|
|||
git diff --unified=1 $oldrev $newrev -- '*.py' >${TMPDIFF} |
|||
|
|||
# there is no working tree in bare git repository, so we recreate it for flake8 |
|||
git archive $newrev | tar -x -C ${TMPDIR} |
|||
|
|||
cd ${TMPDIR} |
|||
# report only errors on lines in diff |
|||
# (if threre was flake8 installed on atrey, we could just call flake8) |
|||
/akce/MaM/WWW/mamweb-test/bin/flake8 --diff <${TMPDIFF} |
|||
status=$? |
|||
if [ $status != 0 ] ; then |
|||
echo |
|||
echo -n "Změny, které se snažíte pushnout, obsahují kód v pythonu " |
|||
echo -n "nevyhovující flake8 (viz výše). Opravte je a zkuste to znovu. " |
|||
echo -n "Nezapomeňte, že můžete editovat historii (git commit --amend, " |
|||
echo -n "git rebase -i). Pokud byste chybu příště raději odhalili už při " |
|||
echo "commitu, zkopírujte si pre-commit hook z _git_hooks do .git/hooks." |
|||
echo |
|||
fi |
|||
|
|||
rm -rf ${TMPDIR} |
|||
rm -f ${TMPDIFF} |
|||
|
|||
exit $status |
@ -0,0 +1,25 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('seminar', '0041_konfery'), |
|||
('korektury', '0009_trizeni_korektur_v_seznamu'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='komentar', |
|||
name='autor_org', |
|||
field=models.ForeignKey(blank=True, to='seminar.Organizator', help_text='Autor koment\xe1\u0159e', null=True), |
|||
), |
|||
migrations.AddField( |
|||
model_name='oprava', |
|||
name='autor_org', |
|||
field=models.ForeignKey(blank=True, to='seminar.Organizator', help_text=b'Autor opravy', null=True), |
|||
), |
|||
] |
@ -0,0 +1,56 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
def transform_autor(apps, schema_editor): |
|||
print |
|||
Organizator = apps.get_model('seminar', 'Organizator') |
|||
|
|||
# preorgovani oprav |
|||
Oprava = apps.get_model('korektury', 'Oprava') |
|||
for oprava in Oprava.objects.all(): |
|||
jmeno = oprava.autor.split() |
|||
if len(jmeno) == 2: |
|||
try: |
|||
org = Organizator.objects.get(user__first_name=jmeno[0], |
|||
user__last_name=jmeno[1]) |
|||
oprava.autor_org = org |
|||
oprava.save() |
|||
except: |
|||
print "Org nenalezen -- mažu korekturu" |
|||
# oprava.delete() |
|||
else: |
|||
print "Org nenalezen -- mažu korekturu" |
|||
oprava.delete() |
|||
|
|||
# preorgovani komentaru |
|||
Komentar = apps.get_model('korektury', 'Komentar') |
|||
for komentar in Komentar.objects.all(): |
|||
jmeno = komentar.autor.split() |
|||
if len(jmeno) == 2: |
|||
try: |
|||
org = Organizator.objects.get(user__first_name=jmeno[0], |
|||
user__last_name=jmeno[1]) |
|||
komentar.autor_org = org |
|||
komentar.save() |
|||
except: |
|||
print "Org nenalezen -- mažu korekturu" |
|||
# oprava.delete() |
|||
else: |
|||
print "Org nenalezen -- mažu korekturu" |
|||
komentar.delete() |
|||
|
|||
def back(apps, schema_editor): |
|||
pass |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('korektury', '0010_Pridani_odkazu_na_organizatora'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RunPython(transform_autor, back), |
|||
] |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('korektury', '0011_prevod_autora_z_charField_na_Organizator'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RemoveField( |
|||
model_name='komentar', |
|||
name='autor', |
|||
), |
|||
migrations.RemoveField( |
|||
model_name='oprava', |
|||
name='autor', |
|||
), |
|||
] |
@ -0,0 +1,24 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('korektury', '0012_delete_autor'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RenameField( |
|||
model_name='komentar', |
|||
old_name='autor_org', |
|||
new_name='autor', |
|||
), |
|||
migrations.RenameField( |
|||
model_name='oprava', |
|||
old_name='autor_org', |
|||
new_name='autor', |
|||
), |
|||
] |
Loading…
Reference in new issue