Skip to content

Commit

Permalink
Fix utf-8 encoding errors, exclude relevant folders from parser, add …
Browse files Browse the repository at this point in the history
….idea in .gitignore
  • Loading branch information
EugenioPetulla committed Aug 5, 2023
1 parent 60091b2 commit 6701590
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
43 changes: 24 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
import os
import pathlib
import fnmatch
import sys

"""
Run this script once after first creating the repository from the template.
This script is interactive and will prompt you for various inputs.
"""

import os
import pathlib
import fnmatch
from sys import argv


if __name__ == "__main__":
repo_name = input("What is the name of your plugin (full name with spaces) ? ")
repo_name = input("What is the name of your plugin (full name with spaces)? ")

snake_name = ("_").join(repo_name.lower().split(" "))
snake_name = "_".join(repo_name.lower().split(" "))

os.rename("my_plugin.py", f"{snake_name}.py")
for file in pathlib.Path(".").glob('**/*.*'):

for file in pathlib.Path(".").glob("**/*.*"):
filename = str(file)
if fnmatch.fnmatch(filename, ".git") or fnmatch.fnmatch(filename, ".git\*"):

if fnmatch.fnmatch(filename, ".git/*"): # Exclude .git directory
continue


if fnmatch.fnmatch(filename, "__pycache__/*"): # Exclude __pycache__ directory
continue

if fnmatch.fnmatch(filename, sys.argv[0]): # Exclude the script file itself
continue

if os.path.basename(file) == "setup.py":
continue

if file.is_dir():
continue
else:
with open(file, "r") as f:
with open(file, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()

replaced = content.replace("my_plugin", snake_name).replace("My plugin", repo_name.title())

with open(file, "w") as f:
with open(file, "w", encoding="utf-8", errors="ignore") as f:
f.write(replaced)
print(f"All the occurrencies were replaced successfully with `{repo_name}` !")
os.remove(argv[0])

print(f"All the occurrences were replaced successfully with `{repo_name}`!")
os.remove(sys.argv[0])

0 comments on commit 6701590

Please sign in to comment.