Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Aug 3, 2018
1 parent 57e5d70 commit e6d5739
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .appveyor.yml
Expand Up @@ -15,6 +15,6 @@ init:
- cmd: set PATH=%PY_DIR%;%PY_DIR%\Scripts;%PATH%

install: pip install -e .[tests]

test_script: pytest -rsv

61 changes: 61 additions & 0 deletions meld_all.py
@@ -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()
3 changes: 3 additions & 0 deletions setup.cfg
Expand Up @@ -43,6 +43,8 @@ tests =
mypy
io =
pycurl
meld =
ghlinguist

[options.entry_points]
console_scripts =
Expand All @@ -54,6 +56,7 @@ console_scripts =
findvid = findvid:main
getIP = getIP:main
memfree = memfree:main
meld_all = meld_all:main
spellcheck = spellcheck:main
tarcp = tarcp:main

Expand Down

0 comments on commit e6d5739

Please sign in to comment.