2021-01-10 11:43:17 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""Extract all string litterals from our code base.
|
|
|
|
|
|
|
|
Useful to check if an API function is used in a generated web page !
|
|
|
|
|
|
|
|
Usage:
|
2021-01-16 19:33:35 +01:00
|
|
|
extract_code_strings.py source.py ... > string-constants.txt
|
2021-01-10 11:43:17 +01:00
|
|
|
|
2021-04-26 08:53:12 +02:00
|
|
|
|
|
|
|
Résultat utilisé par check_zope_usage.py
|
2021-01-10 11:43:17 +01:00
|
|
|
|
|
|
|
E. Viennet 2021-01-09
|
|
|
|
"""
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import ast
|
2021-01-16 19:33:35 +01:00
|
|
|
import types
|
2021-01-10 11:43:17 +01:00
|
|
|
|
2021-04-26 08:53:12 +02:00
|
|
|
# L = []
|
2021-01-10 11:43:17 +01:00
|
|
|
for srcfilename in sys.argv[1:]:
|
2021-01-16 19:33:35 +01:00
|
|
|
# print("processing %s" % srcfilename, file=sys.stderr)
|
2021-01-10 11:43:17 +01:00
|
|
|
with open(srcfilename) as f:
|
|
|
|
p = ast.parse(f.read())
|
2021-01-16 19:33:35 +01:00
|
|
|
# L.extend(x.s.strip() for x in ast.walk(p) if x.__class__ == ast.Str)
|
|
|
|
for x in ast.walk(p):
|
|
|
|
if x.__class__ == ast.Str:
|
2021-07-11 18:18:44 +02:00
|
|
|
if isinstance(x.s, str):
|
2021-01-16 19:33:35 +01:00
|
|
|
s = x.s
|
|
|
|
else:
|
|
|
|
s = x.s.encode("UTF-8")
|
|
|
|
# remove tabs and cr
|
2021-07-12 10:51:45 +02:00
|
|
|
s = s.replace("\t", "").replace("\n", "")
|
2021-01-16 19:33:35 +01:00
|
|
|
if len(s):
|
|
|
|
print("%s\t%s" % (srcfilename, s))
|
2021-01-10 11:43:17 +01:00
|
|
|
|
2021-01-16 19:33:35 +01:00
|
|
|
# L = sorted(set(L)) # uniq | sort
|
|
|
|
# print("\n".join(L))
|