Last active
July 12, 2016 20:25
-
-
Save adoussot/3e27a032d7b40c09510af52523386d7e to your computer and use it in GitHub Desktop.
debug script - log functions name in order to better understand the data-flow (it's not a subtle solution but I find it handy in some cases)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
import fileinput | |
import time | |
import pprint | |
import collections | |
def main(): | |
""" | |
""" | |
with open('file.js', 'r') as f: | |
content = f.readlines() | |
temp = {} | |
lineno = 0 | |
regex = re.compile('^((?!//).)*function.*{$') | |
for l in content: | |
lineno += 1 | |
for m in [regex.search(l)]: | |
if m: | |
temp[lineno] = m.group(0) | |
for i in collections.OrderedDict(sorted(temp.items(), reverse=True)): | |
log = 'console.log("!!! {} !!!")\n'.format(pretty_print(content[i-1])) | |
content.insert(i, log) | |
with open("foo.js", "w") as f: | |
f.write(' '.join(content)) | |
def pretty_print(log): | |
""" | |
:param arg1: the string to clean | |
:type arg1: str | |
""" | |
a = log.replace('\n', ' ').replace("\"", "'") | |
str_clean = a.translate ({ord(c): " " for c in "!@#$%^&*()[]{};:,./<>?\|`~-=_+"}) | |
return str_clean | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment