Browse Source

Move scripts para pasta scripts (#1933)

* Aprimorando script check_migrations.sh para executa-lo de qualquer pasta do repositório

Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>

* Movendo script check_migrations.sh para a pasta scripts

Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>

* Atualizando caminho do arquivo check_migrations.sh em .travis.yml e hooks/pre-commit

Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>

* Modificando script fix_qa.sh para executar sempre na raiz do repositório

Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>

* Movendo script fix_qa.sh para a pasta scripts/django/

Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>

* Removendo caminho hard-coded do script redbaron

Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>

* Adaptando script reset_all_migrations.sh. Sempre executará a partir da raiz do repositório

Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>

* Adaptando script gerar_grafico_apps.sh

Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>

* Alterando scripts de QA para executar sempre na raiz do projeto

Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>

* Fix QA script auto reference

Signed-off-by: Eliseu Egewarth <eliseuegewarth@gmail.com>
pull/1942/head
Eliseu Egewarth 7 years ago
committed by Edward
parent
commit
a8084b7293
  1. 6
      .travis.yml
  2. 8
      scripts/django/check_migrations.sh
  3. 4
      scripts/django/check_qa.sh
  4. 2
      scripts/django/fix_qa.sh
  5. 3
      scripts/django/gerar_grafico_apps.sh
  6. 5
      scripts/django/reset_all_migrations.sh
  7. 5
      scripts/django/test_and_check_qa.sh
  8. 2
      scripts/hooks/pre-commit
  9. 14
      scripts/redbaron.py

6
.travis.yml

@ -1,7 +1,7 @@
language: python
python:
- 3.4.3
- 3.5
services:
- postgresql
@ -14,13 +14,13 @@ before_script:
- cp sapl/.env_test sapl/.env
- psql -c "CREATE USER sapl WITH PASSWORD 'sapl'" -U postgres;
- psql -c "CREATE DATABASE sapl OWNER sapl;" -U postgres
- ./check_migrations.sh
- ./scripts/django/check_migrations.sh
script:
- ./manage.py migrate
- ./manage.py bower install
- py.test --create-db
# - ./test_and_check_qa.sh
# - ./scripts/django/test_and_check_qa.sh
addons:
hosts:

8
check_migrations.sh → scripts/django/check_migrations.sh

@ -11,13 +11,15 @@
# A chamada do django 1.10 INVERTE ISSO.
#
# https://docs.djangoproject.com/en/1.10/ref/django-admin/#cmdoption-makemigrations-check
if python manage.py makemigrations --dry-run --exit > /dev/null; then
git_project_root=$(git rev-parse --show-toplevel)
if python ${git_project_root}/manage.py makemigrations --dry-run --exit > /dev/null; then
NC='\033[0m'
RED='\033[0;31m'
echo
echo -e "${RED}ALGUMAS ALTERAÇÕES EXIGEM MIGRAÇÃO.${NC}"
echo -e "${RED}RODE 'python manage.py makemigrations' ANTES DE SUBMETER SEU CÓDIGO...${NC}"
echo -e "${RED}lembre de adicionar os arquivos criados ao git com 'git add .' ou semelhante.${NC}"
echo -e "${RED}Execute o comando 'python manage.py makemigrations' ANTES DE SUBMETER SEU CÓDIGO...${NC}"
echo -e "${RED}Lembre de adicionar os arquivos criados ao git com 'git add <arquivo>' ou semelhante.${NC}"
echo
exit 1
fi

4
check_qa.sh → scripts/django/check_qa.sh

@ -2,6 +2,10 @@
# Verifica se um breakpoint foi esquecido no código
me=`basename "$0"`
git_project_root=$(git rev-parse --show-toplevel)
cd ${git_project_root}
busca=`grep --color=auto --exclude=$me --exclude=ipython_log.py* -r -l "pdb.set_trace()" .`
if [ ! -z "$busca" ]

2
fix_qa.sh → scripts/django/fix_qa.sh

@ -8,5 +8,7 @@
# Uma forma simples de fazer isso é adicionando antes suas mudanças à
# "staging area" do git, com `git add .` e após usar o script `git diff`.
git_project_root=$(git rev-parse --show-toplevel)
cd ${git_project_root}
isort --recursive --skip='migrations' --skip='templates' --skip='ipython_log.py*' .
autopep8 --in-place --recursive . --exclude='migrations,ipython_log.py*'

3
scripts/gerar_grafico_apps.sh → scripts/django/gerar_grafico_apps.sh

@ -1,3 +1,6 @@
#!/bin/bash
git_project_root=$(git rev-parse --show-toplevel)
cd ${git_project_root}
python -c "from sapl.settings import SAPL_APPS; print(*[s.split('.')[-1] for s in SAPL_APPS])" | xargs -t ./manage.py graph_models -d -g -o zzz.png -l fdp

5
scripts/reset_all_migrations.sh → scripts/django/reset_all_migrations.sh

@ -3,6 +3,11 @@
# Sends all django migrations to the trash bin
# Requires trash-cli. To install:
# sudo apt-get install trash-cli
hash trash-put 2>/dev/null || { echo >&2 "I require trash-put but it's not installed. Aborting."; exit 1; }
git_project_root=$(git rev-parse --show-toplevel)
cd ${git_project_root}
find -name 00*.py | grep /migrations/ | xargs trash-put
# Make all migrations from scratch

5
test_and_check_qa.sh → scripts/django/test_and_check_qa.sh

@ -2,6 +2,9 @@
# QA checks: run this before every commit
git_project_root=$(git rev-parse --show-toplevel)
cd ${git_project_root}
py.test
py.test --ds=sapl.crud.tests.settings sapl/crud/tests
./check_qa.sh
./scripts/django/check_qa.sh

2
scripts/hooks/pre-commit

@ -4,5 +4,5 @@
if git diff --cached --name-status | grep -q '^M.*models\.py$'; then
# se a checagem de migrations falhar impedimos o commit
set -e
./check_migrations.sh
./scripts/django/check_migrations.sh
fi

14
scripts/redbaron.py

@ -1,10 +1,14 @@
import os
import re
import subprocess
from redbaron import RedBaron
from redbaron.nodes import EndlNode, ReturnNode, StringNode
root = '/home/mazza/work/sapl'
git_project_root = subprocess.Popen(
["git", "rev-parse", "--show-toplevel"],
stdout=subprocess.PIPE
).communicate()[0].decode('utf-8').replace('\n', '')
def ignorado(path, name):
@ -13,13 +17,13 @@ def ignorado(path, name):
'relatorios/templates.*',
'.*/migrations',
]:
if re.match(os.path.join(root, pattern), path):
if re.match(os.path.join(git_project_root, pattern), path):
return True
return name.startswith('ipython_log.py') or name == 'manage.py'
filenames = [os.path.join(path, name)
for path, subdirs, files in os.walk(root)
for path, subdirs, files in os.walk(git_project_root)
for name in files
if name.endswith('.py') and not ignorado(path, name)]
@ -37,7 +41,7 @@ def build_red(filename):
def write(node):
red = node.root
red = node.git_project_root
with open(red.__filename__, "w") as source_code:
source_code.write(red.dumps())
@ -82,7 +86,7 @@ def fix(n):
def local(node):
res = '%s:%s' % (node.root.__filename__,
res = '%s:%s' % (node.git_project_root.__filename__,
node.absolute_bounding_box.top_left.line)
os.system("echo '%s' | xclip -selection c" % res)
return res

Loading…
Cancel
Save