Last active
February 1, 2020 13:18
-
-
Save Nimrodda/e9d5e21557d7ca1a9e1e69b2b7bd25b2 to your computer and use it in GitHub Desktop.
Python script for verifying moved files in an Android projects with variants
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
""" | |
Helper script for verifying moved files match variant folders in an Android project. | |
Useful when modularizing. | |
Pipe the script to a Git diff command like so: | |
git --no-pager diff develop --name-status -R|python move-check.py | |
""" | |
import re | |
import sys | |
def check_moved_files(diff): | |
errors = 0 | |
match = re.search('^(R\\d{3})', diff) | |
if match is not None: | |
match = re.findall('/src/(\\w+?)/', diff) | |
if len(match) == 2 and match[0] != match[1]: | |
errors = errors + 1 | |
print('ERROR: Variant folder does not match. Should be %s but was %s in %s' % (match[0], match[1], diff)) | |
return errors | |
def read_stdin(): | |
if not sys.stdin.isatty(): | |
diff = sys.stdin.readlines() | |
errors = 0 | |
for line in diff: | |
errors = errors + check_moved_files(line) | |
return errors | |
print('Checking moved files...') | |
errors = read_stdin() | |
if errors > 0: | |
sys.exit('Found errors. See log above.') | |
else: | |
print('No errors found.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment