mirror of https://github.com/interlegis/sapl.git
Marcio Mazza
9 years ago
1 changed files with 86 additions and 0 deletions
@ -0,0 +1,86 @@ |
|||||
|
import os |
||||
|
import re |
||||
|
|
||||
|
from redbaron import RedBaron |
||||
|
|
||||
|
root = '/home/mazza/work/sapl' |
||||
|
|
||||
|
|
||||
|
def ignorado(path, name): |
||||
|
for pattern in [ |
||||
|
'legacy.*', |
||||
|
'relatorios/templates.*', |
||||
|
'.*/migrations', |
||||
|
]: |
||||
|
if re.match(os.path.join(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 name in files |
||||
|
if name.endswith('.py') and not ignorado(path, name)] |
||||
|
|
||||
|
|
||||
|
def build_reds(): |
||||
|
for filename in filenames: |
||||
|
with open(filename, "r") as source_code: |
||||
|
red = RedBaron(source_code.read()) |
||||
|
if red.data: |
||||
|
red.__filename__ = filename |
||||
|
yield red |
||||
|
|
||||
|
reds = list(build_reds()) |
||||
|
reds_without_tests = [r for r in reds |
||||
|
if not re.match('.*/test_.*\.py', r.__filename__)] |
||||
|
|
||||
|
|
||||
|
def write(node): |
||||
|
red = node.root |
||||
|
with open(red.__filename__, "w") as source_code: |
||||
|
source_code.write(red.dumps()) |
||||
|
|
||||
|
|
||||
|
############################################################################## |
||||
|
# verificacoes ad-hoc |
||||
|
|
||||
|
def flat(ll): |
||||
|
return [i for l in ll for i in l] |
||||
|
|
||||
|
|
||||
|
def inter(n): |
||||
|
'Se a string n está dentro de uma chamada de tradução' |
||||
|
try: |
||||
|
assert not n.next or n.next.type == 'string' |
||||
|
assert n.parent_find('call').parent.value[0].value == '_' |
||||
|
return True |
||||
|
except: |
||||
|
return False |
||||
|
|
||||
|
|
||||
|
def frase(n): |
||||
|
return ' ' in n.value |
||||
|
|
||||
|
|
||||
|
def get(r): |
||||
|
return [s for s in r('string') |
||||
|
if not inter(s) |
||||
|
# and frase(s) |
||||
|
and not s.value in ok] |
||||
|
|
||||
|
|
||||
|
def mark(n): |
||||
|
ok |= {n.value} |
||||
|
|
||||
|
|
||||
|
def fix(n): |
||||
|
n.value = '_(%s)' % n.value |
||||
|
write(n) |
||||
|
|
||||
|
|
||||
|
def local(node): |
||||
|
res = '%s:%s' % (node.root.__filename__, |
||||
|
node.absolute_bounding_box.top_left.line) |
||||
|
os.system("echo '%s' | xclip -selection c" % res) |
||||
|
return res |
Loading…
Reference in new issue