Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python | ||
""" | ||
useful for updating templates. | ||
e.g. | ||
meld_all .appveyor.yml | ||
meld_all .appveyor.yml -l Fortran | ||
""" | ||
from pathlib import Path | ||
from argparse import ArgumentParser | ||
import filecmp | ||
import subprocess | ||
try: | ||
import ghlinguist as ghl | ||
LANG = ghl.linguist(Path(__file__).parent, rtype=True) | ||
except ImportError: | ||
ghl = None | ||
|
||
EXE = 'meld' | ||
|
||
|
||
def meldloop(root: Path, filename: Path, language: str=LANG, exe: str=EXE): | ||
flist = list(root.rglob(filename.name)) | ||
|
||
print(f'comparing {len(flist)} files vs {filename}') | ||
|
||
# Not using check_call due to spurious errors | ||
for f in flist: | ||
if filecmp.cmp(f, filename, shallow=False): | ||
continue | ||
|
||
if ghl is not None: | ||
if ghl.linguist(f.parent, rtype=True) != language: | ||
continue | ||
|
||
subprocess.run([exe, str(filename), str(f)]) | ||
|
||
|
||
def main(): | ||
p = ArgumentParser() | ||
p.add_argument('filename', help='filename to compare against') | ||
p.add_argument('root', help='top-level directory to search under', nargs='?') | ||
p.add_argument('-l', '--language', help='language to template', default=LANG) | ||
p.add_argument('-exe', help='program to compare with', default=EXE) | ||
p = p.parse_args() | ||
|
||
fn = Path(p.filename).expanduser() | ||
if not fn.is_file(): | ||
raise FileNotFoundError(f'{fn} is not a file') | ||
|
||
root = fn.resolve().parents[1] if not p.root else Path(p.root).expanduser() | ||
if not root.is_dir(): | ||
raise FileNotFoundError(f'{root} is not a directory') | ||
|
||
meldloop(root, fn, p.language, p.exe) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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