From 1683d8785837c7413631e273743b506f2bf74e11 Mon Sep 17 00:00:00 2001 From: Eliseu Egewarth Date: Mon, 14 May 2018 11:14:12 -0300 Subject: [PATCH] Removendo caminho hard-coded do script redbaron Signed-off-by: Eliseu Egewarth --- scripts/redbaron.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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