File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,9 @@ dmypy.json
131131# Pycharm
132132.idea
133133
134+ # Vim
135+ . * .sw [op ]
136+
134137# VS Code
135138.vscode
136139
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ import sys
3+ import os
4+ import re
5+ import fnmatch
6+ import functools
7+ from pathlib import Path
8+
9+ PACKAGE_ROOT = Path (__file__ ).absolute ().parent .parent
10+
11+ @functools .lru_cache ()
12+ def load_gitignore (repo ):
13+ gitignore = repo / '.gitignore'
14+ ignore = [fnmatch .translate (".git/" ), fnmatch .translate (Path (__file__ ).name )]
15+ if gitignore .exists ():
16+ ignore .extend (
17+ fnmatch .translate (line .strip ())
18+ for line in gitignore .read_text ().splitlines ()
19+ if line .strip () and not line [0 ] == '#'
20+ )
21+ return re .compile ('|' .join (ignore ))
22+
23+ cmd , new_name , * _ = sys .argv
24+
25+ for root , dirs , files in os .walk (PACKAGE_ROOT ):
26+ ignore = load_gitignore (PACKAGE_ROOT ).search
27+ for d in [d for d in dirs if ignore (f"{ d } /" )]:
28+ dirs .remove (d )
29+ for f in [f for f in files if ignore (f )]:
30+ files .remove (f )
31+
32+ root = Path (root )
33+ for src in list (dirs ):
34+ if 'TODO' in src :
35+ dst = src .replace ("TODO" , new_name )
36+ print (f"Renaming: { root / src } -> { root / dst } " )
37+ os .rename (root / src , root / dst )
38+ dirs .remove (src )
39+ dirs .append (dst )
40+ for fname in files :
41+ f = root / fname
42+ text = Path .read_text (root / fname )
43+ if 'TODO' in text :
44+ print (f"Rewriting: { root / fname } " )
45+ Path .write_text (root / fname , text .replace ("TODO" , new_name ))
You can’t perform that action at this time.
0 commit comments