Skip to content

Instantly share code, notes, and snippets.

@daboross
Last active August 29, 2015 14:02
Show Gist options
  • Save daboross/5335bae8db91a7aa57c1 to your computer and use it in GitHub Desktop.
Save daboross/5335bae8db91a7aa57c1 to your computer and use it in GitHub Desktop.
<3 python
import codecs
import glob
import re
regex = re.compile(re.escape("@hook.command([") + "([^\]]*)" + re.escape("]") + "(:?, (.*))?" + re.escape(")"))
def main():
files = glob.iglob("plugins/*.py")
for path in files:
with codecs.open(path, encoding="utf-8") as read_file:
# io
old_code = read_file.read().split("\n")
new_code = []
# loop
for line in old_code:
match = regex.match(line)
if match:
if match.group(2) is not None:
new_code.append("@hook.command({}, {})".format(match.group(1), match.group(2)))
else:
new_code.append("@hook.command({})".format(match.group(1)))
else:
new_code.append(line)
with codecs.open(path, "w", encoding="utf-8") as write_file:
write_file.write("\n".join(new_code))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment