From a8084b72934e48cfb3068a7cac6b66a32cc6e9a1 Mon Sep 17 00:00:00 2001 From: Eliseu Egewarth Date: Mon, 14 May 2018 15:02:49 -0300 Subject: [PATCH] Move scripts para pasta scripts (#1933) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Aprimorando script check_migrations.sh para executa-lo de qualquer pasta do repositório Signed-off-by: Eliseu Egewarth * Movendo script check_migrations.sh para a pasta scripts Signed-off-by: Eliseu Egewarth * Atualizando caminho do arquivo check_migrations.sh em .travis.yml e hooks/pre-commit Signed-off-by: Eliseu Egewarth * Modificando script fix_qa.sh para executar sempre na raiz do repositório Signed-off-by: Eliseu Egewarth * Movendo script fix_qa.sh para a pasta scripts/django/ Signed-off-by: Eliseu Egewarth * Removendo caminho hard-coded do script redbaron Signed-off-by: Eliseu Egewarth * Adaptando script reset_all_migrations.sh. Sempre executará a partir da raiz do repositório Signed-off-by: Eliseu Egewarth * Adaptando script gerar_grafico_apps.sh Signed-off-by: Eliseu Egewarth * Alterando scripts de QA para executar sempre na raiz do projeto Signed-off-by: Eliseu Egewarth * Fix QA script auto reference Signed-off-by: Eliseu Egewarth --- .travis.yml | 6 +++--- .../django/check_migrations.sh | 10 ++++++---- check_qa.sh => scripts/django/check_qa.sh | 4 ++++ fix_qa.sh => scripts/django/fix_qa.sh | 2 ++ scripts/{ => django}/gerar_grafico_apps.sh | 3 +++ scripts/{ => django}/reset_all_migrations.sh | 5 +++++ .../django/test_and_check_qa.sh | 5 ++++- scripts/hooks/pre-commit | 2 +- scripts/redbaron.py | 14 +++++++++----- 9 files changed, 37 insertions(+), 14 deletions(-) rename check_migrations.sh => scripts/django/check_migrations.sh (61%) rename check_qa.sh => scripts/django/check_qa.sh (89%) rename fix_qa.sh => scripts/django/fix_qa.sh (88%) rename scripts/{ => django}/gerar_grafico_apps.sh (69%) rename scripts/{ => django}/reset_all_migrations.sh (57%) rename test_and_check_qa.sh => scripts/django/test_and_check_qa.sh (53%) diff --git a/.travis.yml b/.travis.yml index eb6abe0c3..f54ee6d20 100644 --- a/.travis.yml +++ b/.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: diff --git a/check_migrations.sh b/scripts/django/check_migrations.sh similarity index 61% rename from check_migrations.sh rename to scripts/django/check_migrations.sh index 9db8143b2..dc78641cd 100755 --- a/check_migrations.sh +++ b/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 ' ou semelhante.${NC}" echo exit 1 -fi \ No newline at end of file +fi diff --git a/check_qa.sh b/scripts/django/check_qa.sh similarity index 89% rename from check_qa.sh rename to scripts/django/check_qa.sh index 47f2b56d3..a145bee7a 100755 --- a/check_qa.sh +++ b/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" ] diff --git a/fix_qa.sh b/scripts/django/fix_qa.sh similarity index 88% rename from fix_qa.sh rename to scripts/django/fix_qa.sh index 264c01676..cb0f24001 100755 --- a/fix_qa.sh +++ b/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*' diff --git a/scripts/gerar_grafico_apps.sh b/scripts/django/gerar_grafico_apps.sh similarity index 69% rename from scripts/gerar_grafico_apps.sh rename to scripts/django/gerar_grafico_apps.sh index 312f04b0c..ab6bf9a84 100755 --- a/scripts/gerar_grafico_apps.sh +++ b/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 diff --git a/scripts/reset_all_migrations.sh b/scripts/django/reset_all_migrations.sh similarity index 57% rename from scripts/reset_all_migrations.sh rename to scripts/django/reset_all_migrations.sh index 53e274fe9..d3f2cfbe4 100755 --- a/scripts/reset_all_migrations.sh +++ b/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 diff --git a/test_and_check_qa.sh b/scripts/django/test_and_check_qa.sh similarity index 53% rename from test_and_check_qa.sh rename to scripts/django/test_and_check_qa.sh index 14231ce80..024139bba 100755 --- a/test_and_check_qa.sh +++ b/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 diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit index de82032c1..d8efe2cf5 100644 --- a/scripts/hooks/pre-commit +++ b/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 diff --git a/scripts/redbaron.py b/scripts/redbaron.py index 3229872bc..b02e4cdfa 100644 --- a/scripts/redbaron.py +++ b/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