Last active
August 29, 2015 14:02
-
-
Save daboross/5335bae8db91a7aa57c1 to your computer and use it in GitHub Desktop.
<3 python
This file contains hidden or 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 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